Skip to content

Commit

Permalink
Add test for importing dashboard from Dashboard Manager
Browse files Browse the repository at this point in the history
  • Loading branch information
caleb531 committed Sep 14, 2023
1 parent 25eff58 commit 3b40839
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion __tests__/DashboardManager.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import Home from '@app/page';
import '@testing-library/jest-dom';
import { screen, waitFor } from '@testing-library/react';
import { act, fireEvent, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import firstDashboardJson from '@tests/__json__/dashboardManager/firstDashboard.json';
import secondDashboardJson from '@tests/__json__/dashboardManager/secondDashboard.json';
import thirdDashboardJson from '@tests/__json__/dashboardManager/thirdDashboard.json';
import exportedDashboard from '@tests/__json__/exportedDashboard.json';
import { renderServerComponent } from '@tests/__utils__/renderServerComponent';
import {
ErrorConfig,
Expand All @@ -25,6 +26,7 @@ import {
mockPromptOnce,
setAppData
} from '@tests/__utils__/testUtils';
import FileReaderMock from './__mocks__/FileReaderMock';

function mockDashboardsFetch(
dashboards: JsonAppState[],
Expand Down Expand Up @@ -275,6 +277,40 @@ describe('Dashboard Manager', () => {
});
});

it('should import dashboard from file', async () => {
const localDashboard = secondDashboardJson;
const availableDashboards = [
firstDashboardJson,
secondDashboardJson,
thirdDashboardJson
];
await openDashboardManager({
localDashboard,
availableDashboards
});
const newDashboardName = 'Prayer Dashboard';
mockPromptOnce(() => newDashboardName);
await userEvent.click(
screen.getByRole('button', { name: 'Import Dashboard' })
);
const fileContents = JSON.stringify(exportedDashboard);
FileReaderMock._fileData = fileContents;
await act(async () => {
fireEvent.change(screen.getByLabelText('Import Dashboard'), {
target: { files: [new File([fileContents], 'exportedDashboard.json')] }
});
});
await waitFor(() => {
expect(screen.getByText('Evening')).toBeInTheDocument();
expect(
screen.queryByRole('heading', { name: 'My Dashboards' })
).not.toBeInTheDocument();
expect(
screen.queryByRole('button', { name: 'Skip Tutorial' })
).not.toBeInTheDocument();
});
});

it('should successfully edit dashboard name', async () => {
const localDashboard = secondDashboardJson;
const availableDashboards = [
Expand Down

0 comments on commit 3b40839

Please sign in to comment.