|
| 1 | +import { expect, test, galata } from '@jupyterlab/galata'; |
| 2 | +import path from 'path'; |
| 3 | + |
| 4 | +const BACKEND = process.env.BACKEND ?? 'rtc'; |
| 5 | +test.use({ autoGoto: false }); |
| 6 | + |
| 7 | +test.describe('UI Test', () => { |
| 8 | + test.describe('Extension activation test', () => { |
| 9 | + test('should emit an activation console message', async ({ |
| 10 | + page, |
| 11 | + request |
| 12 | + }) => { |
| 13 | + const logs: string[] = []; |
| 14 | + |
| 15 | + page.on('console', message => { |
| 16 | + logs.push(message.text()); |
| 17 | + }); |
| 18 | + |
| 19 | + await page.goto(); |
| 20 | + const expectedExtension = BACKEND === 'rtc' ? 7 : 6; |
| 21 | + expect(logs.filter(s => s.includes('@jupyter/suggestions'))).toHaveLength( |
| 22 | + expectedExtension |
| 23 | + ); |
| 24 | + await page.getByTitle('Jupyter Suggestions'); |
| 25 | + expect(await page.screenshot()).toMatchSnapshot({ |
| 26 | + name: `${BACKEND}-main-page.png` |
| 27 | + }); |
| 28 | + }); |
| 29 | + }); |
| 30 | + test.describe('Panel activation test', () => { |
| 31 | + test('should add the suggestion panel to the right', async ({ |
| 32 | + page, |
| 33 | + request |
| 34 | + }) => { |
| 35 | + await page.goto(); |
| 36 | + |
| 37 | + await page.sidebar.open('right'); |
| 38 | + await page.getByTitle('Jupyter Suggestions').click(); |
| 39 | + await page.getByTitle('All Suggestions'); |
| 40 | + expect(await page.screenshot()).toMatchSnapshot({ |
| 41 | + name: `${BACKEND}-side-panel.png` |
| 42 | + }); |
| 43 | + }); |
| 44 | + }); |
| 45 | +}); |
| 46 | + |
| 47 | +test.describe('Notebook Test', () => { |
| 48 | + test.beforeEach(async ({ page, tmpPath }) => { |
| 49 | + await page.contents.uploadDirectory( |
| 50 | + path.resolve(__dirname, './notebooks'), |
| 51 | + tmpPath |
| 52 | + ); |
| 53 | + await page.filebrowser.openDirectory(tmpPath); |
| 54 | + }); |
| 55 | + |
| 56 | + test('Should add suggestion widget', async ({ page, tmpPath }) => { |
| 57 | + await page.goto(); |
| 58 | + const notebook = 'test.ipynb'; |
| 59 | + await page.sidebar.open('right'); |
| 60 | + await page.getByTitle('Jupyter Suggestions').click(); |
| 61 | + await page.getByTitle('All Suggestions'); |
| 62 | + |
| 63 | + await page.notebook.openByPath(`${tmpPath}/${notebook}`); |
| 64 | + await page.notebook.activate(notebook); |
| 65 | + |
| 66 | + await page.notebook.selectCells(0); |
| 67 | + await page.getByRole('button', { name: 'Suggestion menu' }).click(); |
| 68 | + await page.getByText('Suggest change').click(); |
| 69 | + await page.waitForTimeout(500); |
| 70 | + await page.notebook.selectCells(1); |
| 71 | + await page.getByRole('button', { name: 'Suggestion menu' }).click(); |
| 72 | + await page.getByText('Suggest delete').click(); |
| 73 | + await page.waitForTimeout(500); |
| 74 | + expect(await page.screenshot()).toMatchSnapshot({ |
| 75 | + name: `${BACKEND}-add-suggestion.png` |
| 76 | + }); |
| 77 | + await page |
| 78 | + .getByLabel('All Suggestions (2)', { exact: true }) |
| 79 | + .getByText('def foo(): print(123) return') |
| 80 | + .fill('def foobar():\n print(123)\n return 123'); |
| 81 | + await page.waitForTimeout(500); |
| 82 | + expect( |
| 83 | + await page.getByLabel('All Suggestions (2)', { exact: true }).screenshot() |
| 84 | + ).toMatchSnapshot({ |
| 85 | + name: `${BACKEND}-change-cell-content.png` |
| 86 | + }); |
| 87 | + await page.getByLabel('Accept suggestion').nth(2).click(); |
| 88 | + await page.waitForTimeout(500); |
| 89 | + expect(await page.screenshot()).toMatchSnapshot({ |
| 90 | + name: `${BACKEND}-accept-change-suggestion.png` |
| 91 | + }); |
| 92 | + await page.getByLabel('Accept suggestion').nth(1).click(); |
| 93 | + await page.waitForTimeout(500); |
| 94 | + expect(await page.screenshot()).toMatchSnapshot({ |
| 95 | + name: `${BACKEND}-accept-delete-suggestion.png` |
| 96 | + }); |
| 97 | + }); |
| 98 | +}); |
0 commit comments