forked from jupyterlab/jupyterlab
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix search coming back in notebook and editor (jupyterlab#15443)
* a test case to illustrate issue jupyterlab#14871 * cleanup unused code * rename outline into highlight as it sounds more proper * fix typo in variable name _unrenderedByHighligh → _unrenderedByHighlight * Fix search coming back in notebook and editor * Add missing return * Rename snapshots and limit screenshot to notebook area Remove no-op await locator line * Update Playwright Snapshots * Improve async test implementation to avoid early closing * Update Playwright Snapshots * Remove visual snapshots, use locator counts instead and revert spurious snapshot updates --------- Co-authored-by: Thierry Parmentelat <[email protected]> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
9844a6f
commit 746ce2d
Showing
9 changed files
with
222 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright (c) Jupyter Development Team. | ||
// Distributed under the terms of the Modified BSD License. | ||
import { expect, galata, test } from '@jupyterlab/galata'; | ||
import * as path from 'path'; | ||
|
||
const TEST_FILENAME = 'search_highlight_notebook.ipynb'; | ||
const TEST_NEEDLE = 'come'; | ||
|
||
test.use({ tmpPath: 'test-search' }); | ||
|
||
test.beforeAll(async ({ request, tmpPath }) => { | ||
const contents = galata.newContentsHelper(request); | ||
await contents.uploadFile( | ||
path.resolve(__dirname, `./notebooks/${TEST_FILENAME}`), | ||
`${tmpPath}/${TEST_FILENAME}` | ||
); | ||
}); | ||
|
||
test.beforeEach(async ({ page, tmpPath }) => { | ||
await page.notebook.openByPath(`${tmpPath}/${TEST_FILENAME}`); | ||
await page.notebook.activate(TEST_FILENAME); | ||
}); | ||
|
||
const HIGHLIGHTS_LOCATOR = '.cm-searching'; | ||
|
||
test('Open and close Search dialog, then add new code cell', async ({ | ||
page | ||
}) => { | ||
// search for our needle | ||
await page.evaluate(async searchText => { | ||
await window.jupyterapp.commands.execute('documentsearch:start', { | ||
searchText | ||
}); | ||
}, TEST_NEEDLE); | ||
|
||
// wait for the search to complete | ||
await page.waitForSelector('text=1/21'); | ||
expect(await page.locator(HIGHLIGHTS_LOCATOR).count()).toBeGreaterThanOrEqual( | ||
4 | ||
); | ||
|
||
// cancel search | ||
await page.keyboard.press('Escape'); | ||
|
||
// expect the highlights to have gone | ||
expect(await page.locator(HIGHLIGHTS_LOCATOR).count()).toEqual(0); | ||
|
||
// insert a new code cell | ||
await page.evaluate(async () => | ||
window.jupyterapp.commands.execute('notebook:insert-cell-below') | ||
); | ||
|
||
// wait an arbitrary amount of extra time | ||
// and expect the highlights to be still gone | ||
// regression-testing against #14871 | ||
await new Promise(resolve => setTimeout(resolve, 1000)); | ||
expect(await page.locator(HIGHLIGHTS_LOCATOR).count()).toEqual(0); | ||
}); |
110 changes: 110 additions & 0 deletions
110
galata/test/jupyterlab/notebooks/search_highlight_notebook.ipynb
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,110 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "e86bd77e-7e48-4941-8cb9-72410d8256aa", | ||
"metadata": {}, | ||
"source": [ | ||
"# regular notebook (not myst)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "d06cb0c2-483b-4781-b283-8212ea667823", | ||
"metadata": {}, | ||
"source": [ | ||
"## a subtitle\n", | ||
"\n", | ||
"Where does it come from?\n", | ||
"Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of \"de Finibus Bonorum et Malorum\" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, \"Lorem ipsum dolor sit amet..\", comes from a line in section 1.10.32.\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "8541f40d-4f71-48fc-92d4-708063b476ec", | ||
"metadata": {}, | ||
"source": [ | ||
"## another one\n", | ||
"\n", | ||
"Where does it come from?\n", | ||
"Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of \"de Finibus Bonorum et Malorum\" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, \"Lorem ipsum dolor sit amet..\", comes from a line in section 1.10.32.\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "d896a643-8998-48cf-8a4f-ec2965656e73", | ||
"metadata": {}, | ||
"source": [ | ||
"## yet another\n", | ||
"\n", | ||
"Where does it come from?\n", | ||
"Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of \"de Finibus Bonorum et Malorum\" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, \"Lorem ipsum dolor sit amet..\", comes from a line in section 1.10.32.\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "a089ea8f-02b8-4b09-af17-aca38782b3c7", | ||
"metadata": {}, | ||
"source": [ | ||
"## let's change\n", | ||
"\n", | ||
"Where does it come from?\n", | ||
"Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of \"de Finibus Bonorum et Malorum\" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, \"Lorem ipsum dolor sit amet..\", comes from a line in section 1.10.32.\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "6f9ad439-3dc0-410c-9d98-2a9356f839a3", | ||
"metadata": {}, | ||
"source": [ | ||
"## to a less predictible\n", | ||
"\n", | ||
"Where does it come from?\n", | ||
"Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of \"de Finibus Bonorum et Malorum\" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, \"Lorem ipsum dolor sit amet..\", comes from a line in section 1.10.32.\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "a783fb23-b79c-40c7-b8fe-be597130a3ae", | ||
"metadata": {}, | ||
"source": [ | ||
"## pattern in picking names\n", | ||
"\n", | ||
"Where does it come from?\n", | ||
"Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of \"de Finibus Bonorum et Malorum\" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, \"Lorem ipsum dolor sit amet..\", comes from a line in section 1.10.32.\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "4e2ae1be-078e-4bf6-974b-6ea6750a74a9", | ||
"metadata": {}, | ||
"source": [ | ||
"## the last one\n", | ||
"\n", | ||
"Where does it come from?\n", | ||
"Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of \"de Finibus Bonorum et Malorum\" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, \"Lorem ipsum dolor sit amet..\", comes from a line in section 1.10.32.\n" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.5" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
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
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
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
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