diff --git a/e2e/config.spec.ts b/e2e/config.spec.ts index 3e4e9ba9..6f722c63 100644 --- a/e2e/config.spec.ts +++ b/e2e/config.spec.ts @@ -74,8 +74,8 @@ test('switching sources discards the draft after confirmation', async ({page}) = await expect(editor).toHaveAttribute('contenteditable', 'true'); await editor.click(); await page.keyboard.press('ControlOrMeta+End'); - await page.keyboard.type('domain(example.org) -> proxy'); - await expect(editor).toContainText('domain(example.org) -> proxy'); + await page.keyboard.type('# unsaved source note'); + await expect(editor).toContainText('# unsaved source note'); const picker = page.getByRole('button', {name: /Config file/}); await picker.click(); await page.getByRole('option', {name: /\/etc\/honk\/config\.dae/}).click(); @@ -95,26 +95,25 @@ test('editing validates, shows diagnostics on errors, and saves through a reload await expect(editor).toHaveAttribute('contenteditable', 'true'); await editor.click(); await page.keyboard.press('ControlOrMeta+End'); - await page.keyboard.type('domain(geosite: netflix) -> nowhere'); + await page.keyboard.type('unknown_section {}'); await page.keyboard.press('Enter'); await page.getByRole('button', {name: 'Validate', exact: true}).click(); const diagnostics = page.getByRole('list', {name: 'Diagnostics'}); await expect(diagnostics.getByRole('listitem')).toHaveCount(1); - await expect(diagnostics).toContainText('No group named "nowhere"'); + await expect(diagnostics).toContainText('Unknown section "unknown_section"'); await expect(page.locator('.rp-toast.negative')).toContainText('Validation found 1 error'); await editor.click(); await page.keyboard.press('ControlOrMeta+End'); await page.keyboard.press('ArrowUp'); - await page.keyboard.press('End'); - for (let i = 0; i < 'nowhere'.length; i++) await page.keyboard.press('Backspace'); - await page.keyboard.type('proxy'); + await page.keyboard.press('Home'); + await page.keyboard.type('# '); await expect(page.locator('.rp-badge', {hasText: 'Not applied'})).toBeVisible(); await expect(page.locator('.rp-card').first()).toContainText('Reloading or closing the page loses the changes'); await page.getByRole('button', {name: 'Apply', exact: true}).click(); await expect(page.locator('.rp-toast.positive', {hasText: 'written'})).toContainText('configuration reloaded'); await expect(page.locator('.rp-badge', {hasText: 'Not applied'})).toHaveCount(0); await expect(page.getByRole('button', {name: 'Apply', exact: true})).toHaveCount(0); - await expect(page.locator('.cm-content[aria-label="/etc/honk/rules.dae"]')).toContainText('domain(geosite: netflix) -> proxy'); + await expect(page.locator('.cm-content[aria-label="/etc/honk/rules.dae"]')).toContainText('# unknown_section {}'); await expect(page.locator('.rp-toolbar').first()).toContainText('41'); await expect(page.locator('.rp-toolbar').nth(1)).toContainText('3 lines,'); }); @@ -749,10 +748,10 @@ test('a new file in the include directory is created empty and opens in the sour const editor = page.locator('.cm-content[aria-label="/etc/honk/config.d/work.dae"]'); await expect(editor).toHaveAttribute('contenteditable', 'true'); await editor.click(); - await page.keyboard.type('domain(geosite: netflix) -> proxy'); + await page.keyboard.type('# include file notes'); await page.getByRole('button', {name: 'Apply', exact: true}).click(); await expect(page.locator('.rp-toast.positive', {hasText: 'written'})).toContainText('configuration reloaded'); - await expect(editor).toContainText('domain(geosite: netflix) -> proxy'); + await expect(editor).toContainText('# include file notes'); // The backend's refusal of an existing name stays in the dialog. await page.getByRole('button', {name: 'New file', exact: true}).click(); await name.fill('work'); diff --git a/e2e/router.spec.ts b/e2e/router.spec.ts index e2384ddd..5b6eaad8 100644 --- a/e2e/router.spec.ts +++ b/e2e/router.spec.ts @@ -74,10 +74,13 @@ test('discard resets a source draft even when the destination selects the same e test('cancelled Back and Forward restore the cursor without replacing history entries', async ({page}) => { await page.goto('/#/settings'); + await expect(page.getByRole('region', {name: 'Backend', exact: true})).toBeVisible(); await page.evaluate(() => { location.hash = '#/config?tab=source'; }); + await expect(page.locator('.cm-content')).toBeVisible(); await page.locator('.rp-nav[href="#/connections"]').click(); + await expect(page).toHaveURL(/#\/connections$/); await page.goBack(); await appendDraft(page, 'keep until discarded'); const dialog = page.getByRole('alertdialog'); diff --git a/src/features/config/sourceForms.test.ts b/src/features/config/sourceForms.test.ts index cc88948e..f2c5c0cf 100644 --- a/src/features/config/sourceForms.test.ts +++ b/src/features/config/sourceForms.test.ts @@ -12,6 +12,7 @@ it('routes located globals to their sole form and protects them from raw changes expect(sameFormValues(before, before.replace('keep', 'other'), 'include', engine)).toBe(true); expect(sameFormValues(before, before.replace(':53', ':54'), 'include', engine)).toBe(true); expect(sameFormValues(before, before + '\n# comment', 'include', engine)).toBe(true); + expect(sameFormValues(before, before + '\nrouting { include rules.dae }', 'include', engine)).toBe(true); expect(sameFormValues(before, before + '\nglobal { mptcp: true }', 'include', engine)).toBe(false); }); diff --git a/src/features/config/sourceForms.ts b/src/features/config/sourceForms.ts index af89662d..474f571e 100644 --- a/src/features/config/sourceForms.ts +++ b/src/features/config/sourceForms.ts @@ -85,7 +85,8 @@ export function sameFormValues(before: string, after: string, source: string, en return scanConfig(value) .tokens.filter(token => token.kind !== 'comment') .map(token => value.slice(token.from, token.to)); - }); + }) + .filter(value => value.length > 0); const includedTargets = (text: string) => { const {blocks} = scanConfig(text); let outside = text;