2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-12 07:54:14 +00:00

UI plugins custom features (#8137)

* initial implementation to let plugins provide custom ui features

* provide exportable types

* refactor ref into renderContext to make it more generic and support template preview area ui plugins

* rename 'renderContext' -> 'featureContext' as not all features may render something

* allow to specify the function name via the source file string divided by a colon

* Bump api version

* add tests

* add docs

* add docs

* debug: workflow

* debug: workflow

* fix tests

* fix tests hopefully

* apply suggestions from codereview

* trigger: ci

* Prove that coverage does not work

* Revert "Prove that coverage does not work"

This reverts commit 920c58ea6f.

* potentially fix test???
This commit is contained in:
Lukas
2024-09-26 11:59:37 +02:00
committed by GitHub
parent 4d48a10bdd
commit 35362347a7
24 changed files with 974 additions and 265 deletions

View File

@ -1,6 +1,7 @@
import { test } from './baseFixtures.js';
import { expect, test } from './baseFixtures.js';
import { baseUrl } from './defaults.js';
import { doQuickLogin } from './login.js';
import { setPluginState } from './settings.js';
/*
* Test for label printing.
@ -81,8 +82,16 @@ test('PUI - Report Printing', async ({ page }) => {
await page.context().close();
});
test('PUI - Report Editing', async ({ page }) => {
await doQuickLogin(page, 'admin', 'inventree');
test('PUI - Report Editing', async ({ page, request }) => {
const [username, password] = ['admin', 'inventree'];
await doQuickLogin(page, username, password);
// activate the sample plugin for this test
await setPluginState({
request,
plugin: 'sampleui',
state: true
});
// Navigate to the admin center
await page.getByRole('button', { name: 'admin' }).click();
@ -104,5 +113,38 @@ test('PUI - Report Editing', async ({ page }) => {
await page.getByText('The preview has been updated').waitFor();
await page.context().close();
// Test plugin provided editors
await page.getByRole('tab', { name: 'Sample Template Editor' }).click();
const textarea = page.locator('#sample-template-editor-textarea');
const textareaValue = await textarea.inputValue();
expect(textareaValue).toContain(
`<img class='qr' alt="{% trans 'QR Code' %}" src='{% qrcode qr_data %}'>`
);
textarea.fill(textareaValue + '\nHello world');
// Switch back and forth to see if the changed contents get correctly passed between the hooks
await page.getByRole('tab', { name: 'Code', exact: true }).click();
await page.getByRole('tab', { name: 'Sample Template Editor' }).click();
const newTextareaValue = await page
.locator('#sample-template-editor-textarea')
.inputValue();
expect(newTextareaValue).toMatch(/\nHello world$/);
// Test plugin provided previews
await page.getByRole('tab', { name: 'Sample Template Preview' }).click();
await page.getByRole('heading', { name: 'Hello world' }).waitFor();
const consoleLogPromise = page.waitForEvent('console');
await page
.getByLabel('split-button-preview-options', { exact: true })
.click();
const msg = (await consoleLogPromise).args();
expect(await msg[0].jsonValue()).toBe('updatePreview');
expect((await msg[1].jsonValue())[0]).toBe(newTextareaValue);
// deactivate the sample plugin again after the test
await setPluginState({
request,
plugin: 'sampleui',
state: false
});
});