Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration tests #13

Merged
merged 5 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,64 @@ jobs:
path: packages/jupyterlab-${{ matrix.extension }}-chat/dist/jupyterlab_${{ matrix.extension }}_chat*
if-no-files-found: error

integration-tests:
name: ${{ matrix.extension }} integration tests
needs: build_extensions
runs-on: ubuntu-latest
strategy:
matrix:
extension: [collaborative, ws]

env:
PLAYWRIGHT_BROWSERS_PATH: ${{ github.workspace }}/pw-browsers

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Base Setup
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1

- name: Download extension package
uses: actions/download-artifact@v3
with:
name: jupyterlab_${{ matrix.extension }}_chat-artifacts

- name: Install the extension
run: |
set -eux
python -m pip install "jupyterlab>=4.0.0,<5" jupyterlab_${{ matrix.extension }}_chat*.whl
- name: Install dependencies
working-directory: packages/jupyterlab-${{ matrix.extension }}-chat/ui-tests
env:
YARN_ENABLE_IMMUTABLE_INSTALLS: 0
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
run: jlpm install

- name: Set up browser cache
uses: actions/cache@v3
with:
path: |
${{ github.workspace }}/pw-browsers
key: ${{ runner.os }}-${{ hashFiles('ui-tests/yarn.lock') }}

- name: Install browser
run: jlpm playwright install chromium
working-directory: packages/jupyterlab-${{ matrix.extension }}-chat/ui-tests

- name: Execute integration tests
working-directory: packages/jupyterlab-${{ matrix.extension }}-chat/ui-tests
run: |
jlpm playwright test
- name: Upload Playwright Test report
if: always()
uses: actions/upload-artifact@v3
with:
name: jupyterlab_${{ matrix.extension }}_chat-playwright-tests
path: |
packages/jupyterlab-${{ matrix.extension }}-chat/ui-tests/test-results
packages/jupyterlab-${{ matrix.extension }}-chat/ui-tests/playwright-report

check_links:
name: Check Links
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ node_modules/
.ipynb_checkpoints
*.tsbuildinfo
jupyter_chat/labextension
.jupyter_ystore.db
# Version file is handled by hatchling
jupyter_chat/_version.py

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"items": [
{
"command": "collaborative-chat:create",
"rank": 10
"rank": 50
}
]
}
Expand Down
14 changes: 9 additions & 5 deletions packages/jupyterlab-collaborative-chat/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export const chatCreation: JupyterFrontEndPlugin<void> = {
await InputDialog.getText({
label: 'Name',
placeholder: 'untitled',
title: 'Name of the chat'
title: 'Create a new chat'
})
).value;
}
Expand All @@ -170,9 +170,13 @@ export const chatCreation: JupyterFrontEndPlugin<void> = {
}

let fileExist = true;
await drive.get(filepath, { content: false }).catch(() => {
if (filepath) {
await drive.get(filepath, { content: false }).catch(() => {
fileExist = false;
});
} else {
fileExist = false;
});
}

// Create a new file if it does not exists
if (!fileExist) {
Expand All @@ -193,9 +197,9 @@ export const chatCreation: JupyterFrontEndPlugin<void> = {
);
return '';
}

filepath = model.path;
}

return commands.execute(CommandIDs.openChat, { filepath });
}
});
Expand All @@ -210,7 +214,7 @@ export const chatCreation: JupyterFrontEndPlugin<void> = {
label: 'Open a chat',
execute: async args => {
let filepath: string | null = (args.filepath as string) ?? null;
if (!filepath) {
if (filepath === null) {
filepath = (
await InputDialog.getText({
label: 'File path',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@

configure_jupyter_server(c)

c.FileContentsManager.delete_to_trash = False

# Uncomment to set server log level to debug level
# c.ServerApp.log_level = "DEBUG"
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,129 @@
* Distributed under the terms of the Modified BSD License.
*/

import { expect, test } from '@jupyterlab/galata';
import { IJupyterLabPageFixture, expect, test } from '@jupyterlab/galata';

/**
* Don't load JupyterLab webpage before running the tests.
* This is required to ensure we capture all log messages.
*/
test.use({ autoGoto: false });
async function fillModal(
page: IJupyterLabPageFixture,
text = '',
button: 'Ok' | 'Cancel' = 'Ok'
) {
const dialog = page.getByRole('dialog');
await dialog.getByRole('textbox').pressSequentially(text);
await dialog.getByRole('button').filter({ hasText: button }).click();
}

test.describe('#commandPalette', () => {
const name = 'my-chat';

test.beforeEach(async ({ page }) => {
await page.keyboard.press('Control+Shift+c');
});

test.afterEach(async ({ page }) => {
for (let filename of ['untitled.chat', `${name}.chat`]) {
if (await page.filebrowser.contents.fileExists(filename)) {
await page.filebrowser.contents.deleteFile(filename);
}
}
});

test('should emit an activation console message', async ({ page }) => {
const logs: string[] = [];
test('should have 2 commands in palette', async ({ page }) => {
await expect(
page.locator(
'#modal-command-palette li[data-command^="collaborative-chat"]'
)
).toHaveCount(2);
});

test('should create a chat with name from command palette', async ({
page
}) => {
await page
.locator(
'#modal-command-palette li[data-command="collaborative-chat:create"]'
)
.click();
await fillModal(page, name);
await page.waitForCondition(
async () => await page.filebrowser.contents.fileExists(`${name}.chat`)
);
await expect(page.activity.getTabLocator(`${name}.chat`)).toBeVisible();
});

page.on('console', message => {
logs.push(message.text());
test('should create an untitled chat from command palette', async ({
page
}) => {
await page
.locator(
'#modal-command-palette li[data-command="collaborative-chat:create"]'
)
.click();
await fillModal(page);
await page.waitForCondition(
async () => await page.filebrowser.contents.fileExists('untitled.chat')
);
await expect(page.activity.getTabLocator('untitled.chat')).toBeVisible();
});

await page.goto();
test('should not create a chat if modal is cancelled', async ({ page }) => {
await page
.locator(
'#modal-command-palette li[data-command="collaborative-chat:create"]'
)
.click();
await fillModal(page, '', 'Cancel');
const tab = page.getByRole('main').getByRole('tab');
await expect(tab).toHaveCount(1);
});

test('should open an existing chat', async ({ page }) => {
// Create a chat file
await page.filebrowser.contents.uploadContent('{}', 'text', `${name}.chat`);

expect(
logs.filter(
s =>
s === 'JupyterLab extension jupyterlab-collaborative-chat is activated!'
)
).toHaveLength(1);
// open it from command palette
await page
.locator(
'#modal-command-palette li[data-command="collaborative-chat:open"]'
)
.click();
await fillModal(page, `${name}.chat`);
await expect(page.activity.getTabLocator(`${name}.chat`)).toBeVisible();
});
});

test.describe('#menuNew', () => {
test('should have an entry in main menu -> new', async ({ page }) => {
const menu = await page.menu.open('File>New');
expect(await menu?.screenshot()).toMatchSnapshot('menu-new.png');
});

test('should open modal create from the menu', async ({ page }) => {
await page.menu.clickMenuItem('File>New>Chat');
await expect(page.locator('dialog .jp-Dialog-header')).toHaveText(
'Create a new chat'
);
});
});

test.describe('#launcher', () => {
test('should have a launcher item in section', async ({ page }) => {
// Chat section
await expect(
page.locator('.jp-Launcher-sectionTitle:text("Chat")')
).toHaveCount(1);

// Chat tile
const tile = page
.locator('.jp-LauncherCard[data-category="Chat"]')
.getByTitle('Create a chat');
expect(await tile.screenshot()).toMatchSnapshot('launcher-tile.png');
});

test('should open modal create from the launcher', async ({ page }) => {
await page.locator('.jp-LauncherCard').getByTitle('Create a chat').click();
await expect(page.locator('dialog .jp-Dialog-header')).toHaveText(
'Create a new chat'
);
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading