Skip to content

Commit edbd6c1

Browse files
committed
chore: improve "dirty" test
1 parent 9849c7b commit edbd6c1

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/__tests__/NotebookPicker.spec.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ describe('NotebookPicker', () => {
1313
let deepnoteMetadata: PartialJSONObject;
1414
let consoleErrorSpy: jest.SpyInstance | null = null;
1515

16-
const createMockPanel = (metadata: PartialJSONObject): NotebookPanel => {
16+
const createMockPanel = (
17+
metadata: PartialJSONObject,
18+
dirty = false
19+
): NotebookPanel => {
1720
deepnoteMetadata = metadata;
1821

1922
mockNotebookModel = {
2023
fromJSON: jest.fn(),
21-
dirty: false,
24+
dirty: dirty,
2225
getMetadata: jest.fn((key: string) => {
2326
if (key === 'deepnote') {
2427
return deepnoteMetadata;
@@ -159,6 +162,26 @@ describe('NotebookPicker', () => {
159162
});
160163

161164
it('should set model.dirty to false after switching notebooks', async () => {
165+
widget.dispose();
166+
167+
const metadata = {
168+
notebooks: {
169+
'Notebook 1': {
170+
id: 'nb1',
171+
name: 'Notebook 1',
172+
cells: [{ cell_type: 'code', source: 'print(1)' }]
173+
},
174+
'Notebook 2': {
175+
id: 'nb2',
176+
name: 'Notebook 2',
177+
cells: [{ cell_type: 'code', source: 'print(2)' }]
178+
}
179+
}
180+
};
181+
182+
const dirtyPanel = createMockPanel(metadata, true);
183+
await attachWidget(dirtyPanel);
184+
162185
const select = widget.node.querySelector('select') as HTMLSelectElement;
163186
select.value = 'Notebook 2';
164187
select.dispatchEvent(new Event('change', { bubbles: true }));

0 commit comments

Comments
 (0)