Add Prettier and ESLint tooling (Refs #77)
This commit is contained in:
@@ -3,9 +3,13 @@ import { contextHref, returnLabel, safeReturnHref } from '../../src/lib/navigati
|
||||
|
||||
describe('navigation context', () => {
|
||||
it('retains nested origins, list scope, loaded results and anchors', () => {
|
||||
const source = new URL('http://localhost/leaderboard/players/42?game=t5&offset=25&returnTo=%2Fleaderboard%3Fq%3DAce#history-title');
|
||||
const source = new URL(
|
||||
'http://localhost/leaderboard/players/42?game=t5&offset=25&returnTo=%2Fleaderboard%3Fq%3DAce#history-title'
|
||||
);
|
||||
const match = new URL(contextHref('/matches/123', source), source);
|
||||
expect(safeReturnHref(match.searchParams.get('returnTo'), '/matches')).toBe(source.pathname + source.search + source.hash);
|
||||
expect(safeReturnHref(match.searchParams.get('returnTo'), '/matches')).toBe(
|
||||
source.pathname + source.search + source.hash
|
||||
);
|
||||
expect(returnLabel(match.searchParams.get('returnTo')!)).toBe('Back to player');
|
||||
expect(returnLabel('/collections?view=history&launches=30')).toBe('Back to launch history');
|
||||
});
|
||||
@@ -18,13 +22,31 @@ describe('navigation context', () => {
|
||||
});
|
||||
|
||||
it('preserves the selected diagnostic tab on both sides of a contextual link', () => {
|
||||
const url = new URL(contextHref('/servers/t5_zombie_theater_1?tab=logs&log=console', '/maintenance/incident?returnTo=%2Fmaintenance%3Fview%3Dactivity'), 'http://localhost');
|
||||
const url = new URL(
|
||||
contextHref(
|
||||
'/servers/t5_zombie_theater_1?tab=logs&log=console',
|
||||
'/maintenance/incident?returnTo=%2Fmaintenance%3Fview%3Dactivity'
|
||||
),
|
||||
'http://localhost'
|
||||
);
|
||||
expect(url.searchParams.get('tab')).toBe('logs');
|
||||
expect(url.searchParams.get('log')).toBe('console');
|
||||
expect(url.searchParams.get('returnTo')).toBe('/maintenance/incident?returnTo=%2Fmaintenance%3Fview%3Dactivity');
|
||||
expect(url.searchParams.get('returnTo')).toBe(
|
||||
'/maintenance/incident?returnTo=%2Fmaintenance%3Fview%3Dactivity'
|
||||
);
|
||||
});
|
||||
|
||||
it.each(['//evil.test', 'https://evil.test/', '/api/auth/logout', '/login', '/hosts/../../api/hosts', '/\\evil.test', '/hosts\n/42', '/unknown', '/' + 'x'.repeat(12000)])('rejects unsafe or unsupported return paths: %s', value => {
|
||||
it.each([
|
||||
'//evil.test',
|
||||
'https://evil.test/',
|
||||
'/api/auth/logout',
|
||||
'/login',
|
||||
'/hosts/../../api/hosts',
|
||||
'/\\evil.test',
|
||||
'/hosts\n/42',
|
||||
'/unknown',
|
||||
'/' + 'x'.repeat(12000)
|
||||
])('rejects unsafe or unsupported return paths: %s', (value) => {
|
||||
expect(safeReturnHref(value, '/betas')).toBe('/betas');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user