Skip to content

Commit

Permalink
Replace app if current dashboard's name is updated
Browse files Browse the repository at this point in the history
  • Loading branch information
caleb531 committed Sep 9, 2023
1 parent 393e9b3 commit f3c8fc3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
28 changes: 28 additions & 0 deletions __tests__/DashboardManager.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,34 @@ describe('Dashboard Manager', () => {
});
});

it('should update state of current dashboard if its own name is edited', async () => {
const localDashboard = secondDashboardJson;
const availableDashboards = [
firstDashboardJson,
secondDashboardJson,
thirdDashboardJson
];
await openDashboardManager({
localDashboard,
availableDashboards
});
const newDashboardName = 'Spiritual Warfare Dashboard';
mockPromptOnce(() => newDashboardName);
mockSupabaseUpsert('dashboards');
mockSupabaseUpsert('widgets');
await userEvent.click(
screen.getByRole('button', {
name: `Edit Name for Dashboard "${localDashboard.name}"`
})
);
await waitFor(() => {
expect(screen.getByText(newDashboardName)).toBeInTheDocument();
expect(supabaseFromMocks.dashboards.upsert).toHaveBeenCalledTimes(1);
expect(supabaseFromMocks.widgets.upsert).toHaveBeenCalledTimes(0);
expect(getAppData().name).toEqual(newDashboardName);
});
});

it('should handle errors while editing dashboard name', async () => {
const error = new Error('Could not edit dashboard name');
const availableDashboards = [
Expand Down
7 changes: 7 additions & 0 deletions components/app/DashboardManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ const DashboardManager = ({ onClose }: Props) => {
return;
}
setDashboards(updateDashboardInList(dashboards, dashboard));
// Update persisted app state if the current dashboard's own name is edited
if (dashboard.id === app.id) {
dispatchToApp({
type: 'replaceApp',
payload: dashboard
});
}
}

async function deleteDashboard(dashboard: SyncedAppState) {
Expand Down

0 comments on commit f3c8fc3

Please sign in to comment.