Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 133 additions & 0 deletions e2e/TldUrl.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import type { Page, Request, Route } from '@playwright/test';
import { test, expect } from './global-setup';

const resultPath = '/en/result/226f6d4f44ae3f80/';

const isTldUrlRequest = (request: Request) =>
request.postDataJSON()?.method === 'get_tld_url';

async function mockTldUrl(page: Page, handle: (route: Route) => Promise<void>) {
await page.route(/\/api$/, async (route) => {
if (isTldUrlRequest(route.request())) {
await handle(route);
} else {
await route.fallback();
}
});
}

async function fulfillRpc(
route: Route,
payload:
| { result: { tld?: string; url?: string } }
| { error: { code: number; message: string } },
) {
await route.fulfill({
json: { jsonrpc: '2.0', id: route.request().postDataJSON().id, ...payload },
});
}

async function expectResults(page: Page) {
await expect(
page.getByRole('heading', { name: 'Test result for results.afNiC.Fr' }),
).toBeVisible();
await expect(page.locator('.zm-result')).toBeVisible();
}

test.describe('TLD URL on test results', () => {
for (const url of ['https://www.afnic.fr/', 'http://www.afnic.fr/']) {
test(`displays and copies ${url}`, async ({ page, context }) => {
await context.grantPermissions(['clipboard-read', 'clipboard-write']);
await mockTldUrl(page, (route) =>
fulfillRpc(route, { result: { tld: 'fr', url } }),
);
const requestPromise = page.waitForRequest(isTldUrlRequest);

await page.goto(resultPath);
const request = await requestPromise;
expect(request.postDataJSON().params).toEqual({
domain: 'results.afNiC.Fr',
});
await expectResults(page);

const button = page.locator('#zmTLDURLButton');
const dialog = page.locator('#copyTLDURLDialog');
await expect(button).toBeVisible();
await expect(button).toHaveText('.fr Info');
await expect(dialog).toBeHidden();
await button.click();
await expect(dialog).toBeVisible();
await expect(dialog.getByText('Placeholder information about the TLD URL.')).toBeVisible();
await expect(dialog.locator('input[name="url"]')).toHaveValue(url);
const openLink = dialog.getByRole('link', { name: 'Open TLD URL in a new tab' });
await expect(openLink).toHaveAttribute('href', url);
await expect(openLink).toHaveAttribute('target', '_blank');
await expect(openLink).toHaveAttribute('rel', 'noopener noreferrer');
const copyButton = dialog.getByRole('button');
await copyButton.click();
await expect(copyButton).toHaveAttribute('aria-label', 'Copied');
expect(await page.evaluate(() => navigator.clipboard.readText())).toBe(url);
});
}

const hiddenButtonCases = [
{
description: 'the URL is omitted',
response: { result: {} },
},
{
description: 'the URL is empty',
response: { result: { url: '' } },
},
{
description: 'the backend returns an RPC error',
response: { error: { code: -32601, message: 'Method not found' } },
},
{
description: 'the request fails',
response: null,
},
];

for (const { description, response } of hiddenButtonCases) {
test(`hides the button when ${description}`, async ({ page }) => {
const errors: Error[] = [];
page.on('pageerror', (error) => errors.push(error));
await mockTldUrl(page, (route) =>
response ? fulfillRpc(route, response) : route.abort('failed'),
);
const settled = response
? page.waitForEvent('requestfinished', isTldUrlRequest)
: page.waitForEvent('requestfailed', isTldUrlRequest);

await page.goto(resultPath);
await settled;
await expectResults(page);
await expect(page.locator('#zmTLDURLButton')).toBeHidden();
expect(errors).toEqual([]);
});
}

test('shows results while waiting for the TLD URL', async ({ page }) => {
let releaseRequest!: () => void;
const pending = new Promise<void>((resolve) => {
releaseRequest = resolve;
});
await mockTldUrl(page, async (route) => {
await pending;
await fulfillRpc(route, { result: { url: 'https://www.afnic.fr/' } });
});
const requestPromise = page.waitForRequest(isTldUrlRequest);

try {
await page.goto(resultPath, { waitUntil: 'domcontentloaded' });
await requestPromise;
await expectResults(page);
await expect(page.locator('#zmTLDURLButton')).toBeHidden();
} finally {
releaseRequest();
}

await expect(page.locator('#zmTLDURLButton')).toBeVisible();
});
});
7 changes: 7 additions & 0 deletions e2e/interceptors/mock.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -986,5 +986,12 @@ export function findMockResponse(url: string, method: string, body: any): any |
return element.json;
}
}

// Default for get_tld_url: no URL, so the TLD link stays hidden unless a
// table entry or a test-specific route provides one.
if (method === 'POST' && body?.method === 'get_tld_url') {
return { jsonrpc: '2.0', id: body.id, result: {} };
}

return null;
}
2 changes: 2 additions & 0 deletions messages/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
"filterSeverityLevels": "Filtrer sværhedsgrader",
"profile": "Profil",
"tldURL": "TLD-URL",
"tldURLInfo": "Placeholder information about the TLD URL.",
"openTldURLInNewTab": "Åbn TLD-URL i en ny fane",
"exportResult": "Eksportér",
"exportJson": "JSON",
"exportHtml": "HTML",
Expand Down
2 changes: 2 additions & 0 deletions messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
"filterSeverityLevels": "Filter severity levels",
"profile": "Profile",
"tldURL": "TLD URL",
"tldURLInfo": "Placeholder information about the TLD URL.",
"openTldURLInNewTab": "Open TLD URL in a new tab",
"exportResult": "Export",
"exportJson": "JSON",
"exportHtml": "HTML",
Expand Down
2 changes: 2 additions & 0 deletions messages/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
"filterSeverityLevels": "Filtrar niveles de gravedad",
"profile": "Perfil",
"tldURL": "URL del TLD",
"tldURLInfo": "Placeholder information about the TLD URL.",
"openTldURLInNewTab": "Abrir la URL del TLD en una pestaña nueva",
"exportResult": "Exportar",
"exportJson": "JSON",
"exportHtml": "HTML",
Expand Down
2 changes: 2 additions & 0 deletions messages/fi.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
"filterSeverityLevels": "Suodata vakavuustasot",
"profile": "Profiili",
"tldURL": "TLD-URL",
"tldURLInfo": "Placeholder information about the TLD URL.",
"openTldURLInNewTab": "Avaa TLD-URL uudessa välilehdessä",
"exportResult": "Vie",
"exportJson": "JSON",
"exportHtml": "HTML",
Expand Down
2 changes: 2 additions & 0 deletions messages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
"filterSeverityLevels": "Filtrer les niveaux de sévérité",
"profile": "Profil",
"tldURL": "URL du TLD",
"tldURLInfo": "Placeholder information about the TLD URL.",
"openTldURLInNewTab": "Ouvrir l’URL du TLD dans un nouvel onglet",
"exportResult": "Exporter",
"exportJson": "JSON",
"exportHtml": "HTML",
Expand Down
2 changes: 2 additions & 0 deletions messages/nb.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
"filterSeverityLevels": "Filtrer alvorlighetsgrader",
"profile": "Profil",
"tldURL": "TLD-URL",
"tldURLInfo": "Placeholder information about the TLD URL.",
"openTldURLInNewTab": "Åpne TLD-URL i en ny fane",
"exportResult": "Eksportér",
"exportJson": "JSON",
"exportHtml": "HTML",
Expand Down
2 changes: 2 additions & 0 deletions messages/sl.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
"filterSeverityLevels": "Filter težavnosti",
"profile": "Profil",
"tldURL": "TLD URL",
"tldURLInfo": "Placeholder information about the TLD URL.",
"openTldURLInNewTab": "Odpri URL TLD v novem zavihku",
"exportResult": "Izvozi",
"exportJson": "JSON",
"exportHtml": "HTML",
Expand Down
2 changes: 2 additions & 0 deletions messages/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
"filterSeverityLevels": "Filtrera allvarlighetsnivå",
"profile": "Profil",
"tldURL": "TLD URL",
"tldURLInfo": "Placeholder information about the TLD URL.",
"openTldURLInNewTab": "Öppna TLD URL i en ny flik",
"exportResult": "Exportera",
"exportJson": "JSON",
"exportHtml": "HTML",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ export async function getTestResults(testId: string): Promise<ResultData> {
return rpc('get_test_results', { id: testId, language: language() }, false);
}

export type TldUrlData = {
tld?: string;
url?: string;
};

export async function getTldUrl(domain: string): Promise<TldUrlData> {
return rpc('get_tld_url', { domain }, false);
}

export type ParentZoneData = {
ds_list: DSInfo[];
ns_list: Nameservers[];
Expand Down
Loading
Loading