feat(KAN-39): rebuild general project settings and inheritance
This commit is contained in:
@@ -0,0 +1,263 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import process from 'node:process';
|
||||
|
||||
const { chromium } = await import(
|
||||
process.env.PLAYWRIGHT_MODULE ?? 'playwright'
|
||||
);
|
||||
const browser = await chromium.launch({ channel: 'chrome', headless: true });
|
||||
const base = 'http://127.0.0.1:4187';
|
||||
const context = await browser.newContext({
|
||||
viewport: { width: 1440, height: 1000 },
|
||||
});
|
||||
const page = await context.newPage();
|
||||
page.setDefaultTimeout(10000);
|
||||
const errors = [];
|
||||
page.on('pageerror', (error) => errors.push(error.message));
|
||||
const mutations = [];
|
||||
page.on('request', (request) => {
|
||||
if (['POST', 'DELETE'].includes(request.method())) {
|
||||
mutations.push(request);
|
||||
}
|
||||
});
|
||||
const dialog = () => page.getByRole('dialog');
|
||||
const button = (name) => page.getByRole('button', { name, exact: true });
|
||||
const confirmReset = () =>
|
||||
dialog().getByRole('button', { name: 'Reset to template', exact: true });
|
||||
const result = (value) =>
|
||||
context.addCookies([{ name: 'general_test_result', value, url: base }]);
|
||||
const visit = async (query = '?reset') => {
|
||||
await result('success');
|
||||
await page.goto(base + '/projects/1/settings/general' + query);
|
||||
await page.getByRole('heading', { name: 'General', exact: true }).waitFor();
|
||||
};
|
||||
const noOverflow = async () =>
|
||||
assert.equal(
|
||||
await page.evaluate(
|
||||
() => document.documentElement.scrollWidth <= window.innerWidth,
|
||||
),
|
||||
true,
|
||||
);
|
||||
const formState = (form, state) =>
|
||||
form
|
||||
.locator('[data-form-state="' + state + '"]')
|
||||
.waitFor({ state: 'visible' });
|
||||
try {
|
||||
for (const width of [1440, 390, 320]) {
|
||||
await page.setViewportSize({ width, height: 1000 });
|
||||
for (const theme of ['light', 'dark']) {
|
||||
await page.emulateMedia({ colorScheme: theme });
|
||||
await visit();
|
||||
await noOverflow();
|
||||
const nav = page.getByRole('navigation', {
|
||||
name: 'Project settings',
|
||||
exact: true,
|
||||
});
|
||||
assert.equal(
|
||||
await nav
|
||||
.getByRole('link', { name: 'General', exact: true })
|
||||
.getAttribute('aria-current'),
|
||||
'page',
|
||||
);
|
||||
assert.equal(
|
||||
await nav
|
||||
.getByRole('link', { name: 'Ticket settings', exact: true })
|
||||
.getAttribute('href'),
|
||||
'/projects/1/settings/metadata',
|
||||
);
|
||||
const sources = page.getByRole('list', { name: 'Setting sources' });
|
||||
await sources.getByText('Inherited', { exact: true }).waitFor();
|
||||
await sources
|
||||
.getByText('Local override', { exact: true })
|
||||
.first()
|
||||
.waitFor();
|
||||
assert.equal(await button('Switch template').isDisabled(), true);
|
||||
assert.equal(await button('Delete project').isDisabled(), true);
|
||||
if (width === 390 || width === 1440) {
|
||||
await page.screenshot({
|
||||
path: '/private/tmp/KAN-39-' + width + '-' + theme + '.png',
|
||||
fullPage: true,
|
||||
});
|
||||
}
|
||||
const trigger = button('Reset Project settings to template');
|
||||
await trigger.focus();
|
||||
await page.keyboard.press('Enter');
|
||||
await dialog().waitFor();
|
||||
await page.keyboard.press('Tab');
|
||||
assert.equal(
|
||||
await dialog().evaluate((element) =>
|
||||
element.contains(document.activeElement),
|
||||
),
|
||||
true,
|
||||
);
|
||||
await noOverflow();
|
||||
await page.keyboard.press('Escape');
|
||||
await dialog().waitFor({ state: 'hidden' });
|
||||
assert.equal(
|
||||
await trigger.evaluate(
|
||||
(element) => document.activeElement === element,
|
||||
),
|
||||
true,
|
||||
);
|
||||
assert.equal(
|
||||
mutations.length,
|
||||
0,
|
||||
'Opening and cancelling reset must not send a mutation',
|
||||
);
|
||||
}
|
||||
}
|
||||
await visit('?reset&noTemplate');
|
||||
await page.getByText('No linked template', { exact: true }).waitFor();
|
||||
assert.equal(await button('Reset Project settings to template').count(), 0);
|
||||
await visit('?reset&baseline');
|
||||
assert.equal(
|
||||
await page.getByText('Local override', { exact: true }).count(),
|
||||
0,
|
||||
);
|
||||
await visit('?reset&noAlternatives');
|
||||
await page
|
||||
.getByText('No other published templates', { exact: true })
|
||||
.waitFor();
|
||||
assert.equal(await button('Switch template').count(), 0);
|
||||
|
||||
await visit();
|
||||
await button('Reset Ticket statuses to template').click();
|
||||
await dialog().waitFor();
|
||||
assert.equal(await confirmReset().isDisabled(), true);
|
||||
const replacement = page.locator('#replacement-10');
|
||||
await replacement.selectOption('1');
|
||||
await result('validation');
|
||||
const resetRequest = page.waitForRequest(
|
||||
(request) => request.method() === 'POST',
|
||||
);
|
||||
await confirmReset().click();
|
||||
assert.deepEqual((await resetRequest).postDataJSON(), {
|
||||
areas: ['ticket_statuses'],
|
||||
status_replacements: { 10: 1 },
|
||||
});
|
||||
await formState(dialog(), 'validation');
|
||||
await page
|
||||
.getByText('This area could not be reset.', { exact: true })
|
||||
.waitFor();
|
||||
assert.equal(await replacement.inputValue(), '1');
|
||||
await result('server');
|
||||
await confirmReset().click();
|
||||
await formState(dialog(), 'server');
|
||||
await result('success');
|
||||
await dialog()
|
||||
.getByRole('button', { name: 'Try again', exact: true })
|
||||
.click();
|
||||
await dialog().waitFor({ state: 'hidden' });
|
||||
const sources = page.getByRole('list', { name: 'Setting sources' });
|
||||
assert.equal(
|
||||
await sources.getByText('Local override', { exact: true }).count(),
|
||||
1,
|
||||
'Resetting statuses preserves project settings override',
|
||||
);
|
||||
assert.equal(await button('Reset Ticket statuses to template').count(), 0);
|
||||
await button('Reset Project settings to template').click();
|
||||
await confirmReset().click();
|
||||
await dialog().waitFor({ state: 'hidden' });
|
||||
assert.equal(
|
||||
await sources.getByText('Local override', { exact: true }).count(),
|
||||
0,
|
||||
);
|
||||
assert.equal(await page.getByText('Enabled', { exact: true }).count(), 2);
|
||||
|
||||
await visit();
|
||||
const switchForm = page
|
||||
.locator('form')
|
||||
.filter({ has: page.locator('#source_template_id') });
|
||||
const select = page.locator('#source_template_id');
|
||||
assert.equal(
|
||||
await select.locator('option[value="1"]').count(),
|
||||
0,
|
||||
'Current template must not be selectable',
|
||||
);
|
||||
await select.selectOption('2');
|
||||
await page.locator('#switch_confirmation_key').fill('core');
|
||||
assert.equal(await button('Switch template').isDisabled(), true);
|
||||
const countBefore = mutations.length;
|
||||
await switchForm.evaluate((element) =>
|
||||
element.dispatchEvent(
|
||||
new Event('submit', { bubbles: true, cancelable: true }),
|
||||
),
|
||||
);
|
||||
assert.equal(
|
||||
mutations.length,
|
||||
countBefore,
|
||||
'Submit guard must reject a mismatching key',
|
||||
);
|
||||
await page.locator('#switch_confirmation_key').fill('CORE');
|
||||
await result('validation');
|
||||
await button('Switch template').click();
|
||||
await formState(switchForm, 'validation');
|
||||
assert.equal(
|
||||
await page.locator('#switch_confirmation_key').inputValue(),
|
||||
'CORE',
|
||||
);
|
||||
assert.equal(
|
||||
await page
|
||||
.locator('#switch_confirmation_key')
|
||||
.getAttribute('aria-invalid'),
|
||||
'true',
|
||||
);
|
||||
await page.route('**/switch-template', (route) => route.abort('failed'));
|
||||
await button('Switch template').click();
|
||||
await formState(switchForm, 'network');
|
||||
await page.unroute('**/switch-template');
|
||||
await result('success');
|
||||
const switched = page.waitForRequest(
|
||||
(request) => request.method() === 'POST',
|
||||
);
|
||||
await switchForm
|
||||
.getByRole('button', { name: 'Try again', exact: true })
|
||||
.click();
|
||||
assert.deepEqual((await switched).postDataJSON(), {
|
||||
confirmation_key: 'CORE',
|
||||
source_template_id: 2,
|
||||
});
|
||||
await page.getByText('Delivery baseline', { exact: true }).waitFor();
|
||||
assert.equal(
|
||||
await page.locator('#switch_confirmation_key').inputValue(),
|
||||
'',
|
||||
);
|
||||
assert.equal(await button('Switch template').isDisabled(), true);
|
||||
|
||||
await visit();
|
||||
const deleteForm = page
|
||||
.locator('form')
|
||||
.filter({ has: page.locator('#confirmation_key') });
|
||||
await page.locator('#confirmation_key').fill('core');
|
||||
assert.equal(await button('Delete project').isDisabled(), true);
|
||||
const beforeDelete = mutations.length;
|
||||
await deleteForm.evaluate((element) =>
|
||||
element.dispatchEvent(
|
||||
new Event('submit', { bubbles: true, cancelable: true }),
|
||||
),
|
||||
);
|
||||
assert.equal(mutations.length, beforeDelete);
|
||||
await page.locator('#confirmation_key').fill('CORE');
|
||||
await result('validation');
|
||||
await button('Delete project').click();
|
||||
await formState(deleteForm, 'validation');
|
||||
assert.equal(
|
||||
await page.locator('#confirmation_key').getAttribute('aria-invalid'),
|
||||
'true',
|
||||
);
|
||||
assert.equal(await page.locator('#confirmation_key').inputValue(), 'CORE');
|
||||
await result('success');
|
||||
const deleted = page.waitForRequest(
|
||||
(request) => request.method() === 'DELETE',
|
||||
);
|
||||
await button('Delete project').click();
|
||||
const deletion = await deleted;
|
||||
assert.equal(new URL(deletion.url()).pathname, '/projects/1');
|
||||
assert.deepEqual(deletion.postDataJSON(), { confirmation_key: 'CORE' });
|
||||
await page.getByRole('heading', { name: 'Destination reached' }).waitFor();
|
||||
assert.deepEqual(errors, []);
|
||||
console.log(
|
||||
'Project general settings browser checks passed: setting sources, scoped resets, confirmations, replacements, errors, retries, keyboard, 320/390/1440px and both themes.',
|
||||
);
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { createApp, h } from 'vue';
|
||||
import { createInertiaApp } from '@inertiajs/vue3';
|
||||
import '../../resources/css/app.css';
|
||||
import General from '../../resources/js/pages/projects/settings/General.vue';
|
||||
import { createAppearance } from '../../resources/js/composables/useAppearance';
|
||||
import { createLocalization } from '../../resources/js/lib/localization';
|
||||
|
||||
createInertiaApp({
|
||||
resolve: (name) =>
|
||||
name === 'General'
|
||||
? General
|
||||
: { render: () => h('h1', 'Destination reached') },
|
||||
setup: ({ el, App, props, plugin }) =>
|
||||
createApp({ render: () => h(App, props) })
|
||||
.use(plugin)
|
||||
.use(createLocalization())
|
||||
.use(createAppearance())
|
||||
.mount(el),
|
||||
});
|
||||
@@ -0,0 +1,307 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import process from 'node:process';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import vue from '@vitejs/plugin-vue';
|
||||
import tailwind from '@tailwindcss/vite';
|
||||
import { createServer } from 'vite';
|
||||
import { createSSRApp, h } from 'vue';
|
||||
import { renderToString } from 'vue/server-renderer';
|
||||
import { createInertiaApp } from '@inertiajs/vue3';
|
||||
|
||||
const serve = process.argv.includes('--serve');
|
||||
const server = await createServer({
|
||||
configFile: false,
|
||||
cacheDir: 'node_modules/.vite/project-general-settings-fixture',
|
||||
plugins: [vue(), ...(serve ? [tailwind()] : [])],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': fileURLToPath(new URL('../../resources/js', import.meta.url)),
|
||||
},
|
||||
},
|
||||
server: serve
|
||||
? { host: '127.0.0.1', port: 4187, strictPort: true, hmr: false }
|
||||
: { middlewareMode: true, hmr: false, watch: null },
|
||||
appType: 'custom',
|
||||
});
|
||||
const area = (value, label) => ({ value, label });
|
||||
const template = {
|
||||
id: 1,
|
||||
name: 'Team baseline',
|
||||
is_published: true,
|
||||
copy_areas: [],
|
||||
};
|
||||
const alternative = { ...template, id: 2, name: 'Delivery baseline' };
|
||||
function initial() {
|
||||
return {
|
||||
project: {
|
||||
id: 1,
|
||||
key: 'CORE',
|
||||
name: 'Core platform',
|
||||
project_template_id: 1,
|
||||
project_template: template,
|
||||
show_author: false,
|
||||
show_story_points: false,
|
||||
},
|
||||
sourceTemplates: [template, alternative],
|
||||
status: null,
|
||||
templateState: {
|
||||
templateId: 1,
|
||||
templateName: 'Team baseline',
|
||||
inheritsFromTemplate: true,
|
||||
inheritedAreas: [area('board_columns', 'Board columns')],
|
||||
overriddenAreas: [
|
||||
area('project_settings', 'Project settings'),
|
||||
area('ticket_statuses', 'Ticket statuses'),
|
||||
],
|
||||
effectiveConfiguration: {},
|
||||
resetRequirements: {
|
||||
ticket_statuses: {
|
||||
removedStatuses: [
|
||||
{ id: 10, name: 'Local review', ticketCount: 3 },
|
||||
],
|
||||
replacementOptions: [{ id: 1, name: 'Ready' }],
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
function makePage(
|
||||
extra = {},
|
||||
url = '/projects/1/settings/general',
|
||||
component = 'General',
|
||||
) {
|
||||
return {
|
||||
component,
|
||||
url,
|
||||
version: null,
|
||||
clearHistory: false,
|
||||
encryptHistory: false,
|
||||
props: {
|
||||
name: 'KanbanGit',
|
||||
errors: {},
|
||||
sidebarOpen: true,
|
||||
appearance: 'system',
|
||||
auth: {
|
||||
user: {
|
||||
id: 1,
|
||||
name: 'Alex Morgan',
|
||||
email: 'alex@example.test',
|
||||
avatar: null,
|
||||
avatar_color: '#10B981',
|
||||
avatar_is_generated: true,
|
||||
},
|
||||
permissions: {
|
||||
globalAdmin: false,
|
||||
projectCreate: false,
|
||||
canManageTeams: false,
|
||||
},
|
||||
},
|
||||
navigation: {
|
||||
project: {
|
||||
id: 1,
|
||||
name: 'Core platform',
|
||||
key: 'CORE',
|
||||
canManage: true,
|
||||
},
|
||||
},
|
||||
...initial(),
|
||||
...extra,
|
||||
},
|
||||
};
|
||||
}
|
||||
if (serve) {
|
||||
let data = initial();
|
||||
server.middlewares.use(async (request, response, next) => {
|
||||
if (!request.url.startsWith('/projects')) {
|
||||
return next();
|
||||
}
|
||||
const url = new URL(request.url, 'http://localhost');
|
||||
const mutation = request.method !== 'GET';
|
||||
const result =
|
||||
request.headers.cookie?.match(/general_test_result=(\w+)/)?.[1] ??
|
||||
'success';
|
||||
if (!mutation && url.searchParams.has('reset')) {
|
||||
data = initial();
|
||||
}
|
||||
let extra = {};
|
||||
let component = 'General';
|
||||
let pageUrl = '/projects/1/settings/general';
|
||||
if (mutation) {
|
||||
if (['server', 'forbidden'].includes(result)) {
|
||||
response.statusCode = result === 'forbidden' ? 403 : 503;
|
||||
response.end('Simulated request failure');
|
||||
return;
|
||||
}
|
||||
let body = '';
|
||||
for await (const chunk of request) {
|
||||
body += chunk;
|
||||
}
|
||||
const submitted = JSON.parse(body || '{}');
|
||||
if (result === 'validation') {
|
||||
extra.errors = url.pathname.endsWith('reset-template')
|
||||
? { 'areas.0': 'This area could not be reset.' }
|
||||
: { confirmation_key: 'Enter the exact project key.' };
|
||||
} else if (request.method === 'DELETE') {
|
||||
component = 'Destination';
|
||||
pageUrl = '/projects';
|
||||
} else if (url.pathname.endsWith('reset-template')) {
|
||||
const reset = data.templateState.overriddenAreas.find(
|
||||
(item) => item.value === submitted.areas[0],
|
||||
);
|
||||
data.templateState.overriddenAreas =
|
||||
data.templateState.overriddenAreas.filter(
|
||||
(item) => item.value !== reset.value,
|
||||
);
|
||||
data.templateState.inheritedAreas.push(reset);
|
||||
if (reset.value === 'project_settings') {
|
||||
data.project.show_author = true;
|
||||
data.project.show_story_points = true;
|
||||
}
|
||||
data.status = 'Project template baseline was reset.';
|
||||
} else {
|
||||
data.project.project_template = alternative;
|
||||
data.project.project_template_id = 2;
|
||||
data.templateState.templateName = alternative.name;
|
||||
data.templateState.templateId = 2;
|
||||
data.status = 'Project template baseline was switched.';
|
||||
}
|
||||
}
|
||||
if (url.searchParams.has('noTemplate')) {
|
||||
extra = {
|
||||
project: {
|
||||
...data.project,
|
||||
project_template: null,
|
||||
project_template_id: null,
|
||||
},
|
||||
templateState: null,
|
||||
};
|
||||
}
|
||||
if (url.searchParams.has('baseline')) {
|
||||
extra.templateState = {
|
||||
...data.templateState,
|
||||
inheritsFromTemplate: false,
|
||||
};
|
||||
}
|
||||
if (url.searchParams.has('noAlternatives')) {
|
||||
extra.sourceTemplates = [template];
|
||||
}
|
||||
const page = makePage({ ...data, ...extra }, pageUrl, component);
|
||||
response.setHeader('Vary', 'X-Inertia');
|
||||
if (request.headers['x-inertia']) {
|
||||
response.setHeader('X-Inertia', 'true');
|
||||
response.setHeader('Content-Type', 'application/json');
|
||||
response.end(JSON.stringify(page));
|
||||
return;
|
||||
}
|
||||
const escaped = JSON.stringify(page)
|
||||
.replaceAll('&', '&')
|
||||
.replaceAll('"', '"')
|
||||
.replaceAll('<', '<');
|
||||
response.setHeader('Content-Type', 'text/html');
|
||||
response.end(
|
||||
await server.transformIndexHtml(
|
||||
request.url,
|
||||
'<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"></head><body><div id="app" data-page="' +
|
||||
escaped +
|
||||
'"></div><script type="module" src="/tests/Fixtures/project-general-settings-preview.mjs"></script></body></html>',
|
||||
),
|
||||
);
|
||||
});
|
||||
await server.listen();
|
||||
console.log('Project general settings fixture ready.');
|
||||
} else {
|
||||
try {
|
||||
const { createLocalization } = await server.ssrLoadModule(
|
||||
'/resources/js/lib/localization.ts',
|
||||
);
|
||||
const { createAppearance } = await server.ssrLoadModule(
|
||||
'/resources/js/composables/useAppearance.ts',
|
||||
);
|
||||
const { en } = await server.ssrLoadModule(
|
||||
'/resources/js/locales/en.ts',
|
||||
);
|
||||
const component = (
|
||||
await server.ssrLoadModule(
|
||||
'/resources/js/pages/projects/settings/General.vue',
|
||||
)
|
||||
).default;
|
||||
const render = async (extra = {}, locale = createLocalization()) =>
|
||||
(
|
||||
await createInertiaApp({
|
||||
page: makePage(extra),
|
||||
resolve: () => component,
|
||||
render: renderToString,
|
||||
setup: ({ App, props, plugin }) =>
|
||||
createSSRApp({ render: () => h(App, props) })
|
||||
.use(plugin)
|
||||
.use(locale)
|
||||
.use(createAppearance()),
|
||||
})
|
||||
).body;
|
||||
const html = await render();
|
||||
assert.match(html, /Local override/);
|
||||
assert.match(html, /Inherited/);
|
||||
assert.match(html, /Team baseline/);
|
||||
assert.match(html, /Show author/);
|
||||
assert.match(html, /href="\/projects\/1\/settings\/metadata"/);
|
||||
assert.match(html, /aria-current="page"/);
|
||||
assert.match(html, /Reset Project settings to template/);
|
||||
assert.match(html, /Type CORE exactly/);
|
||||
const buttons = html.match(/<button\b[^>]*>[\s\S]*?<\/button>/g);
|
||||
for (const label of ['Switch template', 'Delete project']) {
|
||||
const button = buttons.find((item) => item.includes(label));
|
||||
assert.match(button, /disabled/);
|
||||
assert.match(button, /type="submit"/);
|
||||
}
|
||||
const standalone = await render({
|
||||
templateState: null,
|
||||
project: { ...initial().project, project_template: null },
|
||||
});
|
||||
assert.match(standalone, /No linked template/);
|
||||
assert.doesNotMatch(standalone, /Reset Project settings to template/);
|
||||
assert.doesNotMatch(
|
||||
await render({
|
||||
templateState: {
|
||||
...initial().templateState,
|
||||
inheritsFromTemplate: false,
|
||||
},
|
||||
}),
|
||||
/Local override/,
|
||||
);
|
||||
assert.match(
|
||||
await render({ sourceTemplates: [template] }),
|
||||
/No other published templates/,
|
||||
);
|
||||
const inherited = await render({
|
||||
templateState: {
|
||||
...initial().templateState,
|
||||
inheritedAreas: [area('project_settings', 'Project settings')],
|
||||
overriddenAreas: [],
|
||||
},
|
||||
});
|
||||
assert.doesNotMatch(
|
||||
inherited,
|
||||
/Local override|Reset Project settings to template/,
|
||||
);
|
||||
assert.match(
|
||||
await render(
|
||||
{},
|
||||
createLocalization(
|
||||
{ locale: 'de' },
|
||||
{
|
||||
de: {
|
||||
...en,
|
||||
'projectSettings.danger': 'Gefahrenbereich',
|
||||
'inheritance.area.projectSettings':
|
||||
'Projekteinstellungen',
|
||||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
/Gefahrenbereich/,
|
||||
);
|
||||
console.log('Project general settings rendering checks passed.');
|
||||
} finally {
|
||||
await server.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user