Files
doona/e2e/group-includes.spec.ts
T
Zakk 8d81ddb689 feat(nodes): add, show and edit proxy chains (#702)
## Problem / 问题

After #701, doona reads proxy chains and keeps their references intact,
but it gives no way to see or build one. A chain row shows the raw
protocol `chain` and no hops. Adding or editing a chain means editing
the configuration text, because honk's `POST /nodes` only takes share
links.

## How I fixed it / 解决方法

Display:
- A chain row shows the protocol as "Proxy chain" (代理鏈 / 代理链).
- Its detail lists the hops from entry to exit, with each hop's protocol
and health, and marks a hop that is missing or ambiguous.
- UDP is shown as "No" with the reason when the hop protocols rule it
out. Otherwise it reads "depends on node settings", because the catalog
does not expose UDP flags.
- The node-level TCP connect test is hidden for chains, since honk
returns 422. Group latency no longer counts a chain member's
`no_node_address` row as a failure.

Editing:
- The add-node dialog has a "Proxy chain" mode with an ordered picker of
2 to 4 existing non-chain nodes. Hops can be added, removed and moved up
or down.
- Editing a chain reopens the same dialog. `appendChainEntry` and
`writeChainEntry` write the configuration text through source PUT.
- Before writing, the dialog checks hop count, self reference, direct,
block or chain hops, and the protocol position rules from honk's
`nodes.md` that the catalog can show. honk's diagnostics are shown for
everything else.
- Creating and editing chains is offered only when the engine is honk
and the main source is editable.

`writeNodeEntry` and `writeChainEntry` share one edit helper.
`SearchSelect` gains optional `error` and `action` props, so a hop's
controls sit beside its picker and its error spans the row. Other call
sites are unchanged.

Group `exit` editing, the rejected subscription refresh notice and the
manual pages follow in a stacked PR.

## Screenshots

| | |
|---|---|
|
![](https://gist.githubusercontent.com/Zakkaus/1e1f373d5d925683e7ddbf5e819ca774/raw/node-list-en-light-1280.png)
|
![](https://gist.githubusercontent.com/Zakkaus/1e1f373d5d925683e7ddbf5e819ca774/raw/node-list-zh-TW-dark-390.png)
|
|
![](https://gist.githubusercontent.com/Zakkaus/1e1f373d5d925683e7ddbf5e819ca774/raw/chain-detail-en-light-1280.png)
|
![](https://gist.githubusercontent.com/Zakkaus/1e1f373d5d925683e7ddbf5e819ca774/raw/chain-detail-zh-TW-dark-1280.png)
|
|
![](https://gist.githubusercontent.com/Zakkaus/1e1f373d5d925683e7ddbf5e819ca774/raw/chain-dialog-en-light-1280.png)
|
![](https://gist.githubusercontent.com/Zakkaus/1e1f373d5d925683e7ddbf5e819ca774/raw/chain-dialog-zh-TW-dark-390.png)
|
|
![](https://gist.githubusercontent.com/Zakkaus/1e1f373d5d925683e7ddbf5e819ca774/raw/chain-dialog-error-en-light-1280.png)
|
![](https://gist.githubusercontent.com/Zakkaus/1e1f373d5d925683e7ddbf5e819ca774/raw/chain-dialog-error-zh-TW-dark-1280.png)
|

All 32 variants (390 and 1280, en and zh-TW, light and dark) are kept
locally and available on request.

## Verified / 验证

- `pnpm typecheck`, `lint` (0 warnings), `check:i18n`, `format:check`,
`check:gen` and `build` all exit 0.
- `pnpm test` exits 0: 251 files, 4405 tests.
- `check:size`:
- Nodes route is 73162 B gzip against a 76000 B budget, up from 72320 B.
  - The lazily loaded chain picker chunk is 812 B.
- Playwright `e2e/nodes.spec.ts` on chromium: 101 passed. The 6 other
specs that the new mock chain touched pass, but the full suite was not
rerun after the last change.
- A separate review ablated each key hunk, and every one is now caught
by a test.

Not verified:
- Writes against a live honk.
- Firefox and WebKit e2e.

Net shipped code is about 414 lines, over the 300-line feature budget.
The PR carries display, editing and the engine gate together; splitting
it is possible if wanted.

---

- [ ] I understand this change and answer for every line
- [x] This branch is based on the current main
- [x] I ran the repository's gates and recorded the results in Verified
- [x] Each commit is one coherent change
- [ ] If behaviour changed, I updated the documentation
- [x] If interface text changed, I updated `en.json` and every complete
language's catalogue
- [x] If interface appearance changed, I attached light and dark
screenshots
- [ ] If the API contract changed, I ran `pnpm gen:api` and `pnpm
check:gen`
- [ ] I checked the boxes above without reading them
- [ ] I am an AI agent, and this content was submitted without human
review
2026-11-25 17:58:58 +11:00

504 lines
29 KiB
TypeScript

import {compileFilters} from '../src/dae/groupFilters';
import {expect, mockBackend, test, box} from './fixtures';
import {nestedIn, readGroupEntries, writeGroupEntry} from '../src/dae/groups';
import {regionFilters} from '../src/features/policies/group/groupIncludes';
test.use({storage: {'doona-lang': 'en'}});
const hk = regionFilters.find(region => region.id === 'HK')!.filter;
const jp = regionFilters.find(region => region.id === 'JP')!.filter;
const cardFor = (page: import('@playwright/test').Page, name: string) => page.getByRole('region', {name, exact: true});
async function regionalGroup(page: import('@playwright/test').Page) {
const backend = await mockBackend(page);
const main = (await backend.api.config()).sources.find(source => source.kind === 'main')!;
await backend.api.pollOperation(
await backend.api.replaceConfigSource(
main.id,
writeGroupEntry(main.content, 'visual', {filters: [hk], policy: 'min_moving_avg'}),
`"${main.content_sha256}"`
)
);
return backend;
}
test('one pencil opens the visual editor, no-op saves preserve bytes and tag removal can be undone', async ({page}) => {
const {api} = await regionalGroup(page);
await page.goto(`/#/policies?group=${(await api.groups()).find(group => group.name === 'visual')!.id}`);
const card = cardFor(page, 'visual');
await expect(card.getByRole('group', {name: 'Includes'})).toContainText('Hong Kong');
await card.getByRole('button', {name: 'More actions', exact: true}).click();
await expect(page.getByRole('menuitem', {name: 'Edit group', exact: true})).toHaveCount(0);
await page.keyboard.press('Escape');
await card.scrollIntoViewIfNeeded();
await card.getByRole('button', {name: 'Edit group', exact: true}).click();
const dialog = page.getByRole('dialog', {name: 'Edit group visual', exact: true});
const regions = dialog.getByRole('button', {name: 'Regions', exact: true});
const hongKong = dialog.getByRole('checkbox', {name: /^Hong Kong/});
await expect(regions).toHaveAttribute('aria-expanded', 'false');
await expect(hongKong).toBeHidden();
await expect(dialog.getByRole('button', {name: 'Remove Hong Kong', exact: true})).toBeVisible();
await regions.focus();
await regions.press('Enter');
await expect(regions).toHaveAttribute('aria-expanded', 'true');
const regionGroup = dialog.getByRole('group', {name: 'Regions', exact: true}).and(dialog.locator('.rp-checkbox-set'));
await expect(regionGroup).toHaveAccessibleName('Regions');
await expect(regionGroup.locator(':scope > span')).toBeHidden();
await expect(dialog.getByRole('checkbox', {name: /^Hong Kong/})).toBeChecked();
await regions.press('Space');
await expect(regions).toHaveAttribute('aria-expanded', 'false');
await expect(hongKong).toBeHidden();
await regions.press('Enter');
await expect(hongKong).toBeChecked();
const before = (await api.config()).sources.find(source => source.kind === 'main')!.content;
await dialog.getByRole('button', {name: 'Apply', exact: true}).click();
await expect(dialog).toHaveCount(0);
expect((await api.config()).sources.find(source => source.kind === 'main')!.content).toBe(before);
await card.scrollIntoViewIfNeeded();
await card.getByRole('button', {name: 'Edit group', exact: true}).click();
await expect(regions).toHaveAttribute('aria-expanded', 'false');
await regions.click();
await dialog
.locator('label')
.filter({has: page.getByRole('checkbox', {name: /^Japan/})})
.click();
const nodes = (await api.nodes({limit: 1000})).nodes;
await expect(dialog.getByRole('status')).toContainText(`${nodes.filter(compileFilters([hk, jp])).length} node`);
await dialog.getByRole('group', {name: 'Subscriptions', exact: true}).locator('label').first().click();
await regions.press('Space');
await expect(regions).toHaveAttribute('aria-expanded', 'false');
await expect(dialog.getByRole('button', {name: 'Remove Japan', exact: true})).toBeVisible();
await dialog.getByRole('button', {name: 'Remove Hong Kong', exact: true}).click();
await expect(dialog.getByText(/still match another filter/)).toBeVisible();
await expect(dialog.getByRole('button', {name: 'Remove Hong Kong', exact: true})).toHaveCount(0);
await regions.press('Enter');
await expect(hongKong).not.toBeChecked();
await regions.press('Space');
await dialog.getByRole('button', {name: 'Undo', exact: true}).click();
await expect(dialog.getByRole('button', {name: 'Remove Hong Kong', exact: true})).toBeVisible();
await regions.press('Enter');
await expect(dialog.getByRole('checkbox', {name: /^Hong Kong/})).toBeChecked();
await expect(dialog.getByRole('checkbox', {name: /^Japan/})).toBeChecked();
await dialog.getByRole('button', {name: 'Apply', exact: true}).click();
await expect(dialog).toHaveCount(0);
await expect(card.getByRole('group', {name: 'Includes'})).toContainText('Japan');
await card.scrollIntoViewIfNeeded();
await card.getByRole('button', {name: 'Edit group', exact: true}).click();
await expect(regions).toHaveAttribute('aria-expanded', 'false');
await regions.click();
await expect(hongKong).toBeChecked();
await expect(dialog.getByRole('checkbox', {name: /^Japan/})).toBeChecked();
await dialog.getByRole('button', {name: 'Cancel', exact: true}).click();
});
test('Nodes creates through the shared editor with region and subscription selections for an automatic policy', async ({page}) => {
const {api, requests} = await mockBackend(page);
await page.goto('/#/nodes?provider=inline');
await page
.getByRole('row')
.filter({has: page.getByRole('rowheader', {name: 'hk-01', exact: true})})
.getByRole('button', {name: 'Node actions', exact: true})
.click();
await page.getByRole('menuitem', {name: 'Add to group', exact: true}).click();
await page.getByRole('menuitem', {name: 'New group…', exact: true}).click();
await expect(page).toHaveURL(/#\/policies/);
const dialog = page.getByRole('dialog', {name: 'New group', exact: true});
await dialog.getByRole('textbox', {name: 'Group name', exact: true}).fill('visual');
await expect(dialog.getByRole('button', {name: /Selection policy/})).toContainText('Score');
const regions = dialog.getByRole('button', {name: 'Regions', exact: true});
await expect(regions).toHaveAttribute('aria-expanded', 'false');
await expect(dialog.getByRole('checkbox', {name: /^Hong Kong/})).toBeHidden();
await regions.click();
await dialog
.locator('label')
.filter({has: page.getByRole('checkbox', {name: /^Hong Kong/})})
.click();
await dialog.getByRole('group', {name: 'Subscriptions', exact: true}).locator('label').first().click();
const filters = ['name(hk-01)', hk, 'subtag(harbor)'];
const count = (await api.nodes({limit: 1000})).nodes.filter(compileFilters(filters)).length;
await expect(dialog.getByRole('status')).toContainText(`${count} node`);
expect(requests.filter(request => request.method() === 'PUT')).toHaveLength(0);
await dialog.getByRole('button', {name: 'Create', exact: true}).click();
await expect(dialog).toHaveCount(0);
const card = cardFor(page, 'visual');
await expect(card.getByRole('group', {name: 'Includes'})).toContainText('Hong Kong');
await expect(card.getByRole('group', {name: 'Includes'})).toContainText('harbor');
await expect.poll(async () => (await api.group((await api.groups()).find(group => group.name === 'visual')!.id)).members.length).toBe(count);
await expect(card).toContainText(`${count} members`);
const text = (await api.config()).sources.find(source => source.kind === 'main')!.content;
expect(readGroupEntries(text).find(group => group.name === 'visual')!.filters).toEqual(filters);
await expect(card.getByRole('heading', {name: 'visual', exact: true})).toBeFocused();
});
test('membership jumps stage the node without writing and node links focus their group', async ({page}) => {
const {api, requests} = await mockBackend(page);
await page.goto('/#/nodes?provider=inline');
await page
.getByRole('row')
.filter({has: page.getByRole('rowheader', {name: 'jp-01', exact: true})})
.getByRole('button', {name: 'Node actions', exact: true})
.click();
await page.getByRole('menuitem', {name: 'Add to group', exact: true}).click();
await page.getByRole('menuitem', {name: 'hk', exact: true}).click();
const dialog = page.getByRole('dialog', {name: 'Edit group hk', exact: true});
await expect(dialog.getByRole('group', {name: 'Includes'})).toContainText('jp-01');
expect(requests.filter(request => request.method() === 'PUT')).toHaveLength(0);
await dialog.getByRole('button', {name: 'Apply', exact: true}).click();
await expect.poll(async () => (await api.group('hk')).members.some(member => member.name === 'jp-01')).toBe(true);
const card = cardFor(page, 'hk');
await card.scrollIntoViewIfNeeded();
await card.getByRole('button', {name: 'Edit group', exact: true}).click();
await dialog.getByRole('link', {name: 'View on Nodes page', exact: true}).click();
await expect(page).toHaveURL(/#\/nodes\?group=hk/);
await expect(page.getByRole('button', {name: /Group$/})).toContainText('hk');
const row = page.getByRole('row').filter({has: page.getByRole('rowheader', {name: 'jp-01', exact: true})});
// The group joined last can sit behind the row's "+N" tag; the row's detail links every group.
await row.getByRole('rowheader').click();
await page.locator('.rp-table-detail').getByRole('link', {name: 'hk', exact: true}).click();
await expect(card.getByRole('heading', {name: 'hk', exact: true})).toBeFocused();
await expect(card).toHaveAttribute('data-highlighted', 'true');
await expect(page.getByRole('dialog')).toHaveCount(0);
});
for (const target of ['new', 'main', 'include'] as const)
test(`Nodes edits a ${target} group without runtime group inventory`, async ({page}) => {
const {api, capabilities, requests} = await mockBackend(page);
capabilities.resources.groups.available = false;
if (target === 'include')
await api.pollOperation(await api.createConfigSource('config.d/extra.dae', 'group {\n extra {\n filter: name(jp-01)\n policy: min_moving_avg\n }\n}\n'));
const name = target === 'new' ? 'config-only' : target === 'include' ? 'extra' : 'gaming';
await page.goto('/#/nodes?provider=inline');
await page
.getByRole('row')
.filter({has: page.getByRole('rowheader', {name: 'hk-01', exact: true})})
.getByRole('button', {name: 'Node actions', exact: true})
.click();
await page.getByRole('menuitem', {name: 'Add to group', exact: true}).click();
await page.getByRole('menuitem', {name: target === 'new' ? 'New group…' : name, exact: true}).click();
const dialog = page.getByRole('dialog', {name: target === 'new' ? 'New group' : `Edit group ${name}`, exact: true});
await expect(dialog.getByRole('button', {name: 'Remove hk-01', exact: true})).toBeVisible();
if (target === 'new') await dialog.getByRole('textbox', {name: 'Group name', exact: true}).fill(name);
await dialog.getByRole('button', {name: target === 'new' ? 'Create' : 'Apply', exact: true}).click();
await expect(dialog).toHaveCount(0);
const sources = (await api.config()).sources;
const declaring = sources.find(source => readGroupEntries(source.content).some(group => group.name === name))!;
expect(declaring.kind).toBe(target === 'include' ? 'include' : 'main');
expect(readGroupEntries(declaring.content).find(group => group.name === name)!.filters).toContain('name(hk-01)');
await expect(cardFor(page, name).getByRole('button', {name: 'Edit group', exact: true})).toBeEnabled();
expect(requests.filter(request => /\/api\/v1\/groups(?:\/|$)/.test(new URL(request.url()).pathname))).toHaveLength(0);
});
for (const reason of ['read-only', 'ambiguous'] as const)
test(`pencil is disabled with the ${reason} reason`, async ({page}) => {
const {api, handlers} = await regionalGroup(page);
handlers['GET config'] = async () => {
const config = await api.config();
return {
...config,
sources:
reason === 'read-only'
? config.sources.map(source => ({...source, writable: false}))
: [...config.sources, {...config.sources.find(source => source.kind === 'main')!, id: 'duplicate', path: '/etc/duplicate.dae'}]
};
};
await page.goto(`/#/policies?group=${(await api.groups()).find(group => group.name === 'visual')!.id}`);
const button = cardFor(page, 'visual').getByRole('button', {name: 'Edit group', exact: true});
await expect(button).toBeDisabled();
await expect(button).toHaveAccessibleDescription(reason === 'read-only' ? /read.only/ : /more than once/);
});
test('a group without configuration access offers a disabled pencil and a read-only view', async ({page}) => {
const {api, handlers} = await mockBackend(page);
handlers['GET capabilities'] = async () => {
const capabilities = await api.capabilities();
capabilities.resources.config.available = false;
capabilities.resources.events.available = false;
return capabilities;
};
await page.goto('/#/policies?group=office');
const card = cardFor(page, 'office');
const pencil = card.getByRole('button', {name: 'Edit group', exact: true});
await expect(pencil).toBeDisabled();
await expect(pencil).toHaveAccessibleDescription('The configuration is not ready for editing yet');
await card.getByRole('button', {name: 'More actions', exact: true}).click();
await page.getByRole('menuitem', {name: 'View configuration', exact: true}).click();
await expect(page.getByRole('dialog', {name: 'office configuration', exact: true})).toBeVisible();
await expect(page.getByRole('button', {name: 'Apply', exact: true})).toHaveCount(0);
});
test('old Arrange links redirect to Policies with no second tab', async ({page}) => {
await page.goto('/#/policies?tab=arrange');
await expect(page).toHaveURL(/#\/policies$/);
await expect(page.getByRole('tab', {name: 'Group membership'})).toHaveCount(0);
await expect(page.getByRole('button', {name: 'New group', exact: true})).toBeVisible();
});
test('node search adds a selection and keeps advanced filters unchanged', async ({page}) => {
const {api} = await mockBackend(page);
const main = (await api.config()).sources.find(source => source.kind === 'main')!;
const custom = "name(keyword: 'hk') && !name(keyword: '02')";
await api.pollOperation(
await api.replaceConfigSource(main.id, writeGroupEntry(main.content, 'visual', {filters: [custom], policy: 'min_moving_avg'}), `"${main.content_sha256}"`)
);
await page.goto(`/#/policies?group=${(await api.groups()).find(group => group.name === 'visual')!.id}`);
await cardFor(page, 'visual').getByRole('button', {name: 'Edit group', exact: true}).click();
const dialog = page.getByRole('dialog', {name: 'Edit group visual'});
await expect(dialog.getByRole('textbox', {name: 'Values', exact: true}).nth(0)).toHaveValue('hk');
await expect(dialog.getByRole('textbox', {name: 'Values', exact: true}).nth(1)).toHaveValue('02');
await dialog.getByRole('button', {name: 'Nodes', exact: true}).click();
await page.getByRole('searchbox', {name: 'Search nodes'}).fill('sg-01');
await page.getByRole('option', {name: 'sg-01', exact: true}).click();
await page.getByRole('searchbox', {name: 'Search nodes'}).fill('');
await page.keyboard.press('Escape');
await expect(page.getByRole('dialog', {name: 'Nodes', exact: true})).toHaveCount(0);
await expect(dialog.getByRole('group', {name: 'Includes'})).toContainText('sg-01');
await dialog.getByRole('button', {name: 'Apply', exact: true}).click();
await expect(dialog).toHaveCount(0);
expect(
readGroupEntries((await api.config()).sources.find(source => source.kind === 'main')!.content).find(group => group.name === 'visual')!.filters
).toEqual([custom, 'name(sg-01)']);
});
test('a linked group with no members does not show all nodes', async ({page}) => {
const {api} = await mockBackend(page);
const main = (await api.config()).sources.find(source => source.kind === 'main')!;
await api.pollOperation(
await api.replaceConfigSource(
main.id,
writeGroupEntry(main.content, 'empty', {filters: ['name(missing)'], policy: 'min_moving_avg'}),
`"${main.content_sha256}"`
)
);
await page.goto(`/#/nodes?group=${(await api.groups()).find(group => group.name === 'empty')!.id}`);
await expect(page.getByRole('rowheader', {name: 'hk-01', exact: true})).toHaveCount(0);
await expect(page.getByRole('button', {name: /Group$/})).toContainText('empty');
});
test.describe('phone jumps', () => {
test.use({viewport: {width: 390, height: 844}, hasTouch: true});
test('phone member links reach the filtered Nodes list and return to the highlighted heading', async ({page}) => {
const {api} = await mockBackend(page);
const main = (await api.config()).sources.find(source => source.kind === 'main')!;
await api.pollOperation(
await api.replaceConfigSource(
main.id,
writeGroupEntry(main.content, 'linked', {filters: ['subtag(harbor)'], policy: 'min_moving_avg'}),
`"${main.content_sha256}"`
)
);
const id = (await api.groups()).find(group => group.name === 'linked')!.id;
await page.goto(`/#/policies?group=${id}`);
const card = cardFor(page, 'linked');
await card.scrollIntoViewIfNeeded();
await card.getByRole('button', {name: 'Edit group', exact: true}).click();
await page.getByRole('dialog', {name: 'Edit group linked'}).getByRole('link', {name: 'View on Nodes page', exact: true}).click();
await expect(page).toHaveURL(new RegExp(`#/nodes\\?group=${id}$`));
await page.locator('.rp-table [role=grid]').last().getByRole('rowheader').first().click();
const jump = page.locator('.rp-table-detail').getByRole('link', {name: 'linked', exact: true});
await expect(jump).toBeVisible();
await jump.tap();
await expect(card.getByRole('heading', {name: 'linked', exact: true})).toBeFocused();
await expect(card).toHaveCSS('outline-style', 'solid');
expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(true);
});
});
test('removing the final node and turning every-node off both save an empty group', async ({page}) => {
const {api} = await mockBackend(page);
const main = (await api.config()).sources.find(source => source.kind === 'main')!;
await api.pollOperation(
await api.replaceConfigSource(
main.id,
writeGroupEntry(main.content, 'visual', {filters: ['name(hk-01)'], policy: 'min_moving_avg'}),
`"${main.content_sha256}"`
)
);
await page.goto(`/#/policies?group=${(await api.groups()).find(group => group.name === 'visual')!.id}`);
const card = cardFor(page, 'visual');
await card.getByRole('button', {name: 'Edit group', exact: true}).click();
const dialog = page.getByRole('dialog', {name: 'Edit group visual', exact: true});
await dialog.getByRole('button', {name: 'Remove hk-01', exact: true}).click();
await expect(dialog.getByRole('status')).toContainText('0 nodes');
const every = dialog.getByRole('switch', {name: 'All nodes', exact: true});
await every.press('Space');
await expect(every).toBeChecked();
await every.press('Space');
await expect(every).not.toBeChecked();
await expect(dialog.getByRole('status')).toContainText('0 nodes');
await dialog.getByRole('button', {name: 'Apply', exact: true}).click();
await expect(dialog).toHaveCount(0);
expect((await api.group((await api.groups()).find(group => group.name === 'visual')!.id)).members.map(node => node.name)).toEqual([]);
});
test('a group without filters shows every-node selected', async ({page}) => {
const {api} = await mockBackend(page);
const main = (await api.config()).sources.find(source => source.kind === 'main')!;
await api.pollOperation(
await api.replaceConfigSource(main.id, writeGroupEntry(main.content, 'visual', {filters: [], policy: 'min_moving_avg'}), `"${main.content_sha256}"`)
);
await page.goto(`/#/policies?group=${(await api.groups()).find(group => group.name === 'visual')!.id}`);
await cardFor(page, 'visual').getByRole('button', {name: 'Edit group', exact: true}).click();
await expect(page.getByRole('dialog', {name: 'Edit group visual', exact: true}).getByRole('switch', {name: 'All nodes', exact: true})).toBeChecked();
});
test('a stalled first group read does not hide the other policy cards', async ({page}) => {
const {handlers} = await mockBackend(page);
handlers['GET groups/proxy'] = () => new Promise(() => {});
await page.goto('/#/policies');
await expect(cardFor(page, 'auto')).toBeVisible({timeout: 7000});
});
test('the group picker scrolls only its list and can select its last option', async ({page}) => {
await page.setViewportSize({width: 1280, height: 600});
await mockBackend(page);
await page.goto('/#/policies');
await page.getByRole('button', {name: 'New group', exact: true}).click();
const dialog = page.getByRole('dialog', {name: 'New group', exact: true});
await dialog.getByRole('button', {name: 'Groups', exact: true}).click();
const popover = page.locator('.rp-search-popover');
const search = popover.getByRole('searchbox', {name: 'Search groups', exact: true});
await expect(search).toBeFocused();
await expect
.poll(() =>
popover.evaluate(
root =>
[root, ...root.querySelectorAll('*')].filter(el => el.scrollHeight > el.clientHeight && /^(auto|scroll)$/.test(getComputedStyle(el).overflowY)).length
)
)
.toBe(1);
const searchBefore = await box(search);
const list = popover.getByRole('listbox');
await list.evaluate(el => {
el.scrollTop = el.scrollHeight;
});
const last = list.getByRole('option', {name: 'backup', exact: true});
await expect(last).toBeInViewport();
expect((await box(search)).y).toBe(searchBefore.y);
await last.click();
await expect(last).toHaveAttribute('aria-selected', 'true');
await page.keyboard.press('Escape');
await expect(dialog.getByRole('button', {name: 'Remove backup', exact: true})).toBeVisible();
});
for (const width of [1440, 390]) {
test(`long member names preserve picker rows, labels and tag action sizes at ${width}px`, async ({page}) => {
await page.setViewportSize({width, height: 1000});
const {api, handlers} = await mockBackend(page);
const name = 'hk-production-primary-singapore-routing-fallback-upstream-001';
handlers['GET nodes'] = async () => {
const result = await api.nodes({limit: 1000});
return {...result, nodes: [...result.nodes, {...result.nodes[0], id: 'long-node', name}]};
};
await page.goto('/#/policies');
await page.getByRole('button', {name: 'New group', exact: true}).click();
const dialog = page.getByRole('dialog', {name: 'New group', exact: true});
await dialog.getByRole('button', {name: 'Regions', exact: true}).click();
const labels = dialog.getByRole('group', {name: 'Regions', exact: true}).locator(':scope > span');
await expect(labels).toHaveCSS('font-size', '12px');
await dialog.getByRole('button', {name: 'Nodes', exact: true}).click();
await page.getByRole('searchbox', {name: 'Search nodes', exact: true}).fill('production');
const option = page.getByRole('option', {name, exact: true});
await expect(option).toBeVisible();
const controlSize = await option.evaluate(el => Number.parseFloat(getComputedStyle(el).getPropertyValue('--rp-control')));
expect((await box(option)).height).toBeLessThanOrEqual(controlSize);
await expect(option.locator('.rp-truncate')).toHaveCSS('white-space', 'nowrap');
await option.click();
await page.keyboard.press('Escape');
await expect(dialog).toBeVisible();
await expect(page.getByRole('dialog', {name: 'Nodes', exact: true})).toHaveCount(0);
const action = dialog.getByRole('button', {name: `Remove ${name}`, exact: true});
const bounds = await box(action);
expect(bounds.width).toBe(bounds.height);
expect(await dialog.evaluate(el => el.scrollWidth <= el.clientWidth)).toBe(true);
});
}
test('recognised filters have one visual editor and nested group tags support removal and undo', async ({page}) => {
const {api} = await mockBackend(page);
await page.goto('/#/policies?group=proxy');
const card = cardFor(page, 'proxy');
await card.getByRole('button', {name: 'Edit group', exact: true}).click();
const dialog = page.getByRole('dialog', {name: 'Edit group proxy', exact: true});
const before = (await api.config()).sources.find(source => source.kind === 'main')!.content;
await dialog.getByRole('button', {name: 'Advanced', exact: true}).click();
await expect(dialog.getByRole('textbox')).toHaveCount(0);
await dialog.getByRole('button', {name: 'Groups', exact: true}).click();
await expect(page.getByRole('option', {name: 'hk', exact: true})).toHaveAttribute('aria-selected', 'true');
await expect(page.getByRole('option', {name: 'proxy', exact: true})).toBeDisabled();
await page.getByRole('option', {name: 'hk', exact: true}).click();
await page.keyboard.press('Escape');
await expect(dialog.getByRole('button', {name: 'Remove hk', exact: true})).toHaveCount(0);
await dialog.getByRole('button', {name: 'Undo', exact: true}).click();
await expect(dialog.getByRole('button', {name: 'Remove hk', exact: true})).toBeVisible();
await dialog.getByRole('button', {name: 'Apply', exact: true}).click();
await expect(dialog).toHaveCount(0);
expect((await api.config()).sources.find(source => source.kind === 'main')!.content).toBe(before);
await card.scrollIntoViewIfNeeded();
await card.getByRole('button', {name: 'Edit group', exact: true}).click();
await dialog.getByRole('button', {name: 'Groups', exact: true}).click();
await page.getByRole('searchbox', {name: 'Search groups', exact: true}).fill('office');
await page.getByRole('option', {name: 'office', exact: true}).click();
await page.keyboard.press('Escape');
await dialog.getByRole('button', {name: 'Remove hk', exact: true}).click();
await dialog.getByRole('button', {name: 'Apply', exact: true}).click();
await expect(dialog).toHaveCount(0);
const filters = readGroupEntries((await api.config()).sources.find(source => source.kind === 'main')!.content).find(group => group.name === 'proxy')!.filters;
expect(nestedIn({filters})).toEqual(['auto', 'jp', 'us', 'tw', 'sg', 'kr', 'office']);
await expect(card.getByRole('group', {name: 'Includes', exact: true})).not.toContainText('hk');
});
test('legacy region counts agree on the card, checkbox, tag and summary before and after editing', async ({page}) => {
const {api} = await mockBackend(page);
await page.goto('/#/policies?group=hk');
const card = cardFor(page, 'hk');
await expect(card.getByRole('group', {name: 'Includes', exact: true})).toHaveText('Hong Kong, 12 nodes');
await card.getByRole('button', {name: 'Edit group', exact: true}).click();
const dialog = page.getByRole('dialog', {name: 'Edit group hk', exact: true});
await dialog.getByRole('button', {name: 'Regions', exact: true}).click();
await expect(dialog.getByRole('checkbox', {name: 'Hong Kong, 12 nodes', exact: true})).toBeChecked();
await expect(dialog.getByRole('group', {name: 'Includes', exact: true})).toContainText('Hong Kong, 12 nodes');
await expect(dialog.getByRole('status')).toHaveText('12 nodes');
await dialog.getByRole('button', {name: 'Advanced', exact: true}).click();
await expect(dialog.getByRole('textbox')).toHaveCount(0);
const before = (await api.config()).sources.find(source => source.kind === 'main')!.content;
await dialog.getByRole('button', {name: 'Apply', exact: true}).click();
await expect(dialog).toHaveCount(0);
expect((await api.config()).sources.find(source => source.kind === 'main')!.content).toBe(before);
await card.scrollIntoViewIfNeeded();
await card.getByRole('button', {name: 'Edit group', exact: true}).click();
await dialog.getByRole('button', {name: 'Remove Hong Kong', exact: true}).click();
await expect(dialog.getByRole('status')).toHaveText('0 nodes');
await dialog.getByRole('button', {name: 'Regions', exact: true}).click();
await dialog
.locator('label')
.filter({has: page.getByRole('checkbox', {name: /^Hong Kong/})})
.click();
await expect(dialog.getByRole('checkbox', {name: 'Hong Kong, 14 nodes', exact: true})).toBeChecked();
await expect(dialog.getByRole('status')).toHaveText('14 nodes');
await dialog.getByRole('button', {name: 'Apply', exact: true}).click();
await expect(card.getByRole('group', {name: 'Includes', exact: true})).toHaveText('Hong Kong, 14 nodes');
});
test('the membership summary is a short count with names in a collapsed tag list', async ({page}) => {
await mockBackend(page);
await page.goto('/#/nodes?provider=inline');
await page
.getByRole('row')
.filter({has: page.getByRole('rowheader', {name: 'hk-01', exact: true})})
.getByRole('button', {name: 'Node actions', exact: true})
.click();
await page.getByRole('menuitem', {name: 'Add to group', exact: true}).click();
await page.getByRole('menuitem', {name: 'New group…', exact: true}).click();
const dialog = page.getByRole('dialog', {name: 'New group', exact: true});
await expect(dialog.getByRole('status')).toHaveText('1 node');
await expect(dialog.getByText(/Currently selects|no filter|holds every node/)).toHaveCount(0);
const matches = dialog.getByRole('button', {name: 'Matching nodes', exact: true});
await expect(matches).toHaveAttribute('aria-expanded', 'false');
await matches.click();
await expect(dialog.getByRole('group', {name: 'Matching nodes', exact: true}).last()).toHaveText('hk-01');
await dialog
.locator('label')
.filter({has: page.getByRole('switch', {name: 'All nodes', exact: true})})
.click();
await expect(dialog.getByRole('status')).toHaveText('126 nodes');
await expect(dialog.getByText(/Currently selects|no filter|holds every node/)).toHaveCount(0);
});