forked from jupyterlab/jupyterlab
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Align notebook trust behaviour with trust in classic Notebook (jupyte…
…rlab#14345) * Trust cells created automatically or by user * Trust code cell after clearing outputs * Clear `trusted` metadata when changing cell type to markdown/raw * Only count code cells in trust indicator. This is because in the current Jupyter trust model only cells with outputs can be marked as (un)trusted. Further, since nbformat does not like `trusted` metadata on non-code cells we have to remove it, and on our side `.trusted` is always undefined for non-code cells. * Add tests for trust on actions, correct implementation for trust change when clearing outputs * Remove unused trust indicator code, avoid DOM modification noise * Add galata test for trust * Add another galata test, document trust mechanism * Update Playwright Snapshots * Use reload with `waitForIsReady: false` see jupyterlab#14349 * Fix typos (suggestions from code review) Co-authored-by: Frédéric Collonval <[email protected]> --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Frédéric Collonval <[email protected]>
- Loading branch information
1 parent
9c9bc56
commit ed7c879
Showing
11 changed files
with
319 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+245 Bytes
...entation/general.test.ts-snapshots/notebook-not-trusted-documentation-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+257 Bytes
...ocumentation/general.test.ts-snapshots/notebook-trusted-documentation-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright (c) Jupyter Development Team. | ||
// Distributed under the terms of the Modified BSD License. | ||
|
||
import { expect, test } from '@jupyterlab/galata'; | ||
|
||
const fileName = 'trust.ipynb'; | ||
const TRUSTED_SELECTOR = 'svg[data-icon="ui-components:trusted"]'; | ||
const NOT_TRUSTED_SELECTOR = 'svg[data-icon="ui-components:not-trusted"]'; | ||
|
||
test.describe('Notebook Trust', () => { | ||
test.beforeEach(async ({ page }) => { | ||
await page.notebook.createNew(fileName); | ||
}); | ||
|
||
test('Blank Markdown cell does not break trust', async ({ page }) => { | ||
// See https://github.com/jupyterlab/jupyterlab/issues/9765 | ||
|
||
// Add an empty Markdown cell | ||
await page.notebook.addCell('markdown', ''); | ||
// The notebook should be trusted | ||
await expect(page.locator(TRUSTED_SELECTOR)).toHaveCount(1); | ||
await page.notebook.save(); | ||
// Reload page | ||
await page.reload({ waitForIsReady: false }); | ||
// Should still be trusted | ||
await expect(page.locator(TRUSTED_SELECTOR)).toHaveCount(1); | ||
}); | ||
|
||
test('Trust is lost after manually editing notebook', async ({ page }) => { | ||
const browserContext = page.context(); | ||
await browserContext.grantPermissions(['clipboard-read']); | ||
// Add text to first cell | ||
await page.notebook.setCell(0, 'code', 'TEST_TEXT'); | ||
await page.notebook.save(); | ||
// The notebook should be trusted | ||
await expect(page.locator(TRUSTED_SELECTOR)).toHaveCount(1); | ||
await expect(page.locator(NOT_TRUSTED_SELECTOR)).toHaveCount(0); | ||
|
||
// Open notebook in text editor using context menu | ||
await page.click(`.jp-DirListing-item span:has-text("${fileName}")`, { | ||
button: 'right' | ||
}); | ||
await page.hover('text=Open With'); | ||
await page.click('.lm-Menu li[role="menuitem"]:has-text("Editor")'); | ||
const editorContent = await page.waitForSelector( | ||
'.jp-FileEditor .cm-content' | ||
); | ||
await editorContent.waitForSelector('text=TEST_TEXT'); | ||
const originalContent = await page.evaluate(async () => { | ||
await window.jupyterapp.commands.execute('fileeditor:select-all'); | ||
await window.jupyterapp.commands.execute('fileeditor:cut'); | ||
return navigator.clipboard.readText(); | ||
}); | ||
const newContent = originalContent.replace('TEST_TEXT', 'SUBSTITUTED_TEXT'); | ||
await page.evaluate( | ||
async ([newContent]) => { | ||
await window.jupyterapp.commands.execute( | ||
'fileeditor:replace-selection', | ||
{ text: newContent } | ||
); | ||
// Save file after changes | ||
await window.jupyterapp.commands.execute('docmanager:save'); | ||
// Close the file editor view of the notebook | ||
await window.jupyterapp.commands.execute('application:close'); | ||
}, | ||
[newContent] | ||
); | ||
|
||
// Reload page | ||
await page.reload({ waitForIsReady: false }); | ||
|
||
// It should no longer be trusted | ||
await expect(page.locator(TRUSTED_SELECTOR)).toHaveCount(0); | ||
await expect(page.locator(NOT_TRUSTED_SELECTOR)).toHaveCount(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.