diff --git a/e2e/config.test.ts b/e2e/config.test.ts index 6399aef7b5..75ba27a077 100644 --- a/e2e/config.test.ts +++ b/e2e/config.test.ts @@ -1,10 +1,39 @@ -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'); +test.describe('config.toml', () => { + test('block list', async ({ page, request }) => { + // modify config.toml to blocklist some menu items + const 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/); + }); + + test('showNonInstalledImages', 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); diff --git a/e2e/test-util.ts b/e2e/test-util.ts index 81bd9f1c80..9f644530d7 100644 --- a/e2e/test-util.ts +++ b/e2e/test-util.ts @@ -1,4 +1,12 @@ -import { Locator, Page, expect } from '@playwright/test'; +import TOML from '@iarna/toml'; +import { + APIRequestContext, + Locator, + Page, + Request, + expect, + request, +} from '@playwright/test'; import fs from 'fs/promises'; import path from 'path'; @@ -232,7 +240,7 @@ export async function deleteSession(page: Page, sessionName: string) { export async function mockConfigToml(page: Page, rawPath) { const filePath = path.resolve(__dirname, rawPath); const mockData = await fs.readFile(filePath, 'utf-8'); - await page.route('http://127.0.0.1:9081/config.toml', async (route) => { + await page.route(`${webuiEndpoint}/config.toml`, async (route) => { await route.fulfill({ status: 200, contentType: 'text/plain', @@ -240,3 +248,33 @@ export async function mockConfigToml(page: Page, rawPath) { }); }); } + +/** + * Modify specific columns in the webui config.toml file + * + * @param page + * @param request + * @param configColumn + * The object to modify the config.toml file + * + * e.g. { "environments": { "showNonInstalledImages": "true" } } + */ +export async function modifyConfigToml( + page: Page, + request: APIRequestContext, + configColumn: Record>, +) { + const configToml = await ( + await request.get(`${webuiEndpoint}/config.toml`) + ).text(); + const config = TOML.parse(configToml); + Object.assign(config, configColumn); + + await page.route(`${webuiEndpoint}/config.toml`, async (route) => { + await route.fulfill({ + status: 200, + contentType: 'text/plain', + body: TOML.stringify(config), + }); + }); +} diff --git a/package.json b/package.json index 5ddd4b265b..4793134268 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "theme-schema:update": "pnpm dlx typescript-json-schema \"./react/node_modules/antd/es/config-provider/context.d.ts\" ThemeConfig -o ./resources/antdThemeConfig.schema.json --esModuleInterop" }, "dependencies": { + "@iarna/toml": "^2.2.5", "@lit/reactive-element": "^2.0.4", "@material/mwc-button": "^0.27.0", "@material/mwc-checkbox": "^0.27.0", @@ -188,7 +189,7 @@ ], "src/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [ "prettier --write" - ], + ], "e2e/**/*.{js,ts}": [ "prettier --write" ] diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 12b6d04aab..48f0dc13bc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,6 +8,9 @@ importers: .: dependencies: + '@iarna/toml': + specifier: ^2.2.5 + version: 2.2.5 '@lit/reactive-element': specifier: ^2.0.4 version: 2.0.4 @@ -1328,6 +1331,9 @@ packages: resolution: {integrity: sha512-93zYdMES/c1D69yZiKDBj0V24vqNzB/koF26KPaagAfd3P/4gUlh3Dys5ogAK+Exi9QyzlD8x/08Zt7wIKcDcA==} deprecated: Use @eslint/object-schema instead + '@iarna/toml@2.2.5': + resolution: {integrity: sha512-trnsAYxU3xnS1gPHPyU961coFyLkh4gAD/0zQ5mymY4yOZ+CYvsPqUbOFSw0aDM4y0tV7tiFxL/1XfXPNC6IPg==} + '@isaacs/cliui@8.0.2': resolution: {integrity: sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==} engines: {node: '>=12'} @@ -8562,6 +8568,8 @@ snapshots: '@humanwhocodes/object-schema@2.0.3': {} + '@iarna/toml@2.2.5': {} + '@isaacs/cliui@8.0.2': dependencies: string-width: 5.1.2