Skip to content

Commit

Permalink
Clean up based on review
Browse files Browse the repository at this point in the history
- Add key to all dashboards
- Clean up tests a bit
  • Loading branch information
mofojed committed Mar 13, 2024
1 parent 6f7eb9c commit 3a22d39
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
17 changes: 14 additions & 3 deletions packages/code-studio/src/main/AppMainContainer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,18 @@ jest.mock('@deephaven/dashboard', () => ({
...jest.requireActual('@deephaven/dashboard'),
__esModule: true,
LazyDashboard: jest.fn(({ hydrate }) => {
const { useMemo } = jest.requireActual('react');
// We use the `key` to determine how many times this LazyDashboard component was re-rendered with a new key
// When rendered with a new key, the `useMemo` will be useless and will return a new key
const key = useMemo(() => {
const newKey = `${mockIteration}`;
mockIteration += 1;
return newKey;
}, []);
const result = hydrate(mockProp, mockId);
if (result.fetch != null) {
result.fetch();
}
const key = `${mockIteration}`;
mockIteration += 1;
return (
<>
<p>{JSON.stringify(result)}</p>
Expand All @@ -153,6 +159,7 @@ beforeEach(() => {
return 0;
});
mockProp = {};
mockIteration = 0;
});

afterEach(() => {
Expand Down Expand Up @@ -268,14 +275,18 @@ describe('imports layout correctly', () => {
const oldKey = screen.getByTestId('dashboard-key').textContent ?? '';
expect(oldKey.length).not.toBe(0);

const importInput = screen.getByTestId('btn-import-layout');
await act(async () => {
const text = JSON.stringify(EMPTY_LAYOUT);
const file = TestUtils.createMockProxy<File>({
text: () => Promise.resolve(text),
name: 'layout.json',
type: 'application/json',
});

// Technically, the "Import Layout" button in the panels list is what the user clicks on to show the file picker
// However, the testing library uses the `.upload` command on the `input` element directly, which we don't display
// So just fetch it by testid and use the `.upload` command: https://testing-library.com/docs/user-event/utility/#upload
const importInput = screen.getByTestId('btn-import-layout');
await userEvent.upload(importInput, file);
});

Expand Down
1 change: 1 addition & 0 deletions packages/code-studio/src/main/AppMainContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,7 @@ export class AppMainContainer extends Component<
id: tab.key,
layoutConfig: (allDashboardData[tab.key]?.layoutConfig ??
EMPTY_ARRAY) as ItemConfigType[],
key: `${tab.key}-${layoutIteration}`,
})),
];
}
Expand Down

0 comments on commit 3a22d39

Please sign in to comment.