-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: e2e test for parsing config.toml and modifying (#2705)
### TL;DR Updated e2e tests for config.toml and added TOML parsing functionality. ### What changed? - Removed `config-test.toml` file - Updated `config.test.ts` to include new tests for blocklist and showNonInstalledImages - Modified `test-util.ts` to include a new `modifyConfigToml` function - Added `@iarna/toml` dependency to `package.json` and `pnpm-lock.yaml` The toml parser currently used by webui has a lot of [issues](#2382), so I used a different library, [`@iarna/toml`](https://github.com/iarna/iarna-toml). ### How to test? 1. Run the e2e tests for the config.toml file: - Test the blocklist functionality by checking if specified menu items are hidden and their pages are inaccessible - Test the showNonInstalledImages setting by verifying the visibility of non-installed images 2. Verify that the `modifyConfigToml` function works correctly by running the tests and checking if the config.toml file is modified as expected ### Why make this change? This change improves the e2e testing capabilities for the config.toml file, allowing for more dynamic and comprehensive testing of configuration options. The addition of TOML parsing functionality enables easier manipulation of the config file during tests, providing a more flexible and maintainable testing approach. --- <!-- Please precisely, concisely, and concretely describe what this PR changes, the rationale behind codes, and how it affects the users and other developers. --> **Checklist:** (if applicable) - [ ] Mention to the original issue - [ ] Documentation - [ ] Minium required manager version - [ ] Specific setting for review (eg., KB link, endpoint or how to setup) - [ ] Minimum requirements to check during review - [ ] Test case(s) to demonstrate the difference of before/after
- Loading branch information
1 parent
be6db95
commit 406b5ac
Showing
5 changed files
with
213 additions
and
170 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,87 +1,174 @@ | ||
import { loginAsAdmin, mockConfigToml, webuiEndpoint } from './test-util'; | ||
import { loginAsAdmin, modifyConfigToml, webuiEndpoint } from './test-util'; | ||
import { test, expect } from '@playwright/test'; | ||
|
||
test.describe('config read and test', () => { | ||
test('showNonInstalledImages', async ({ page, context }) => { | ||
// manipulate config file from mocked one | ||
await mockConfigToml(page, './config-test.toml'); | ||
|
||
await loginAsAdmin(page); | ||
|
||
await page.getByRole('group').getByText('Environments').click(); | ||
await page | ||
.getByRole('columnheader', { name: 'Status' }) | ||
.locator('div') | ||
.click(); | ||
await page | ||
.getByRole('columnheader', { name: 'Status' }) | ||
.locator('div') | ||
.click(); | ||
|
||
const registryCell = await page | ||
.locator('.ant-table-row > td:nth-child(3)') | ||
.first(); | ||
const registry = await registryCell.textContent(); | ||
|
||
const architectureCell = await page | ||
.locator('.ant-table-row > td:nth-child(4)') | ||
.first(); | ||
const architecture = await architectureCell.textContent(); | ||
|
||
const namespaceCell = await page | ||
.getByRole('cell', { name: 'community' }) | ||
.first(); | ||
const namespace = await namespaceCell.textContent(); | ||
|
||
const languageCell = await page.getByRole('cell', { name: 'afni' }).first(); | ||
const language = await languageCell.textContent(); | ||
|
||
const versionCell = await page | ||
.getByRole('cell', { name: 'ubuntu18.04' }) | ||
.first(); | ||
const version = await versionCell.textContent(); | ||
|
||
const uninstalledImageString = `${registry}/${namespace}/${language}:${version}@${architecture}`; | ||
|
||
await page.goto(webuiEndpoint); | ||
await page.getByLabel('power_settings_new').click(); | ||
await page | ||
.getByRole('button', { name: '2 Environments & Resource' }) | ||
.click(); | ||
await page | ||
.locator( | ||
'.ant-form-item-control-input-content > .ant-select > .ant-select-selector', | ||
) | ||
.first() | ||
.click(); | ||
await page.getByLabel('Environments / Version').fill('AF'); | ||
await page | ||
.locator('.rc-virtual-list-holder-inner > div:nth-child(2)') | ||
.click(); | ||
|
||
await page | ||
.locator('span') | ||
.filter({ hasText: 'ubuntu18.04x86_64' }) | ||
.locator('div') | ||
.first() | ||
.click(); | ||
await page | ||
.locator( | ||
'div:nth-child(4) > .rc-virtual-list-holder > div > .rc-virtual-list-holder-inner > .ant-select-item > .ant-select-item-option-content > div', | ||
) | ||
.click(); | ||
await page | ||
.getByRole('button', { name: 'Skip to review double-right' }) | ||
.click(); | ||
await page.getByRole('button', { name: 'Copy' }).click(); | ||
|
||
await context.grantPermissions(['clipboard-read', 'clipboard-write']); | ||
|
||
const handle = await page.evaluateHandle(() => | ||
navigator.clipboard.readText(), | ||
); | ||
const clipboardContent = await handle.jsonValue(); | ||
|
||
expect(clipboardContent).toEqual(uninstalledImageString); | ||
}); | ||
test.describe.parallel('config.toml', () => { | ||
test( | ||
'enableLLMPlayground', | ||
{ tag: ['@serving'] }, | ||
async ({ page, request }) => { | ||
// modify config.toml to enable LLM playground | ||
let requestConfig = { | ||
general: { | ||
enableLLMPlayground: true, | ||
}, | ||
}; | ||
await modifyConfigToml(page, request, requestConfig); | ||
await loginAsAdmin(page); | ||
await page.getByRole('menuitem', { name: 'Serving' }).click(); | ||
await expect( | ||
page.getByRole('tab', { name: 'LLM Playground' }), | ||
).toBeVisible(); | ||
|
||
requestConfig.general.enableLLMPlayground = false; | ||
await modifyConfigToml(page, request, requestConfig); | ||
await page.reload(); | ||
await page.getByRole('menuitem', { name: 'Serving' }).click(); | ||
await expect( | ||
page.getByRole('tab', { name: 'LLM Playground' }), | ||
).toBeHidden(); | ||
}, | ||
); | ||
|
||
test( | ||
'block list', | ||
{ tag: ['@session', '@summary', '@serving'] }, | ||
async ({ page, request }) => { | ||
// modify config.toml to blocklist some menu items | ||
let requestConfig = { | ||
menu: { | ||
blocklist: 'summary, serving, job', | ||
}, | ||
}; | ||
await modifyConfigToml(page, request, requestConfig); | ||
await loginAsAdmin(page); | ||
|
||
// check if the menu items are hidden | ||
await expect( | ||
page.getByRole('menuitem', { name: 'Summary' }), | ||
).toBeHidden(); | ||
await expect( | ||
page.getByRole('menuitem', { name: 'Sessions' }), | ||
).toBeHidden(); | ||
await expect( | ||
page.getByRole('menuitem', { name: 'Serving' }), | ||
).toBeHidden(); | ||
|
||
// check if the pages are not accessible | ||
await page.goto(`${webuiEndpoint}/summary`); | ||
await expect(page).toHaveURL(/.*error/); | ||
await page.goto(`${webuiEndpoint}/serving`); | ||
await expect(page).toHaveURL(/.*error/); | ||
await page.goto(`${webuiEndpoint}/job`); | ||
await expect(page).toHaveURL(/.*error/); | ||
|
||
requestConfig.menu.blocklist = ''; | ||
await modifyConfigToml(page, request, requestConfig); | ||
await page.reload(); | ||
|
||
// check if the menu items are visible | ||
await expect( | ||
page.getByRole('menuitem', { name: 'Summary' }), | ||
).toBeVisible(); | ||
await expect( | ||
page.getByRole('menuitem', { name: 'Sessions' }), | ||
).toBeVisible(); | ||
await expect( | ||
page.getByRole('menuitem', { name: 'Serving' }), | ||
).toBeVisible(); | ||
}, | ||
); | ||
|
||
test( | ||
'showNonInstalledImages', | ||
{ tag: ['@session'] }, | ||
async ({ page, context, request }) => { | ||
// modify config.toml to show non-installed images | ||
const requestConfig = { | ||
environments: { | ||
showNonInstalledImages: true, | ||
}, | ||
}; | ||
await modifyConfigToml(page, request, requestConfig); | ||
|
||
await loginAsAdmin(page); | ||
|
||
await page.getByRole('group').getByText('Environments').click(); | ||
await page | ||
.getByRole('columnheader', { name: 'Status' }) | ||
.locator('div') | ||
.click(); | ||
await page | ||
.getByRole('columnheader', { name: 'Status' }) | ||
.locator('div') | ||
.click(); | ||
|
||
const registryCell = await page | ||
.locator('.ant-table-row > td:nth-child(3)') | ||
.first(); | ||
const registry = await registryCell.textContent(); | ||
|
||
const architectureCell = await page | ||
.locator('.ant-table-row > td:nth-child(4)') | ||
.first(); | ||
const architecture = await architectureCell.textContent(); | ||
|
||
const namespaceCell = await page | ||
.getByRole('cell', { name: 'community' }) | ||
.first(); | ||
const namespace = await namespaceCell.textContent(); | ||
|
||
const languageCell = await page | ||
.getByRole('cell', { name: 'afni' }) | ||
.first(); | ||
const language = await languageCell.textContent(); | ||
|
||
const versionCell = await page | ||
.getByRole('cell', { name: 'ubuntu18.04' }) | ||
.first(); | ||
const version = await versionCell.textContent(); | ||
|
||
const uninstalledImageString = `${registry}/${namespace}/${language}:${version}@${architecture}`; | ||
|
||
await page.goto(webuiEndpoint); | ||
await page.getByLabel('power_settings_new').click(); | ||
await page | ||
.getByRole('button', { name: '2 Environments & Resource' }) | ||
.click(); | ||
await page | ||
.locator( | ||
'.ant-form-item-control-input-content > .ant-select > .ant-select-selector', | ||
) | ||
.first() | ||
.click(); | ||
await page.getByLabel('Environments / Version').fill('AF'); | ||
await page | ||
.locator('.rc-virtual-list-holder-inner > div:nth-child(2)') | ||
.click(); | ||
|
||
await page | ||
.locator('span') | ||
.filter({ hasText: 'ubuntu18.04x86_64' }) | ||
.locator('div') | ||
.first() | ||
.click(); | ||
await page | ||
.locator( | ||
'div:nth-child(4) > .rc-virtual-list-holder > div > .rc-virtual-list-holder-inner > .ant-select-item > .ant-select-item-option-content > div', | ||
) | ||
.click(); | ||
await page | ||
.getByRole('button', { name: 'Skip to review double-right' }) | ||
.click(); | ||
await page.getByRole('button', { name: 'Copy' }).click(); | ||
|
||
await context.grantPermissions(['clipboard-read', 'clipboard-write']); | ||
|
||
const handle = await page.evaluateHandle(() => | ||
navigator.clipboard.readText(), | ||
); | ||
const clipboardContent = await handle.jsonValue(); | ||
|
||
expect(clipboardContent).toEqual(uninstalledImageString); | ||
}, | ||
); | ||
}); |
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.