1
0
mirror of https://github.com/misskey-dev/misskey.git synced 2026-07-25 21:24:50 +02:00
Files
misskey/packages/frontend/test/unit/lib/nirax/resolve.test.ts
かっこかり 9472e72678 enhance(frontend/test): frontend e2eをPlaywrightに移行 (#17682)
* enhance(frontend/test): frontend e2eをVitest Browser Modeに移行

* fix

* fix unit tests

* fix

* fix

* update playwright

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* perf

* Revert "perf"

This reverts commit e60e965c3c.

* fix
2026-07-08 20:58:02 +09:00

74 lines
2.4 KiB
TypeScript

/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { assert, describe, test } from 'vitest';
import { createRouter } from './fixture.js';
describe('[NIRAX] resolve', () => {
test('staticなルートを解決できる', () => {
const router = createRouter();
const resolved = router.resolve('/');
assert.ok(resolved);
assert.strictEqual(resolved.route.path, '/');
assert.strictEqual(resolved.props.size, 0);
});
test('パスパラメータ付きルートを解決できる', () => {
const router = createRouter();
const resolved = router.resolve('/posts/abc%2Fdef');
assert.ok(resolved);
assert.strictEqual(resolved.route.path, '/posts/:postId');
assert.strictEqual(resolved.props.get('postId'), 'abc/def');
});
test('queryとhashのエイリアスを解決できる', () => {
const router = createRouter();
const resolved = router.resolve('/posts/abc?from=timeline#thread');
assert.ok(resolved);
assert.strictEqual(resolved.props.get('source'), 'timeline');
assert.strictEqual(resolved.props.get('section'), 'thread');
});
test('wildcardルートのパラメータを解決できる', () => {
const router = createRouter();
const resolved = router.resolve('/files/images/icons/logo%20mark.svg');
assert.ok(resolved);
assert.strictEqual(resolved.route.path, '/files/:path(*)');
assert.strictEqual(resolved.props.get('path'), 'images/icons/logo mark.svg');
});
test('optionalなパスパラメータが省略されたルートを解決できる', () => {
const router = createRouter();
const resolved = router.resolve('/optional');
assert.ok(resolved);
assert.strictEqual(resolved.route.path, '/optional/:slug?');
assert.strictEqual(resolved.props.has('slug'), false);
});
test('optionalなパスパラメータが存在するルートを解決できる', () => {
const router = createRouter();
const resolved = router.resolve('/optional/topic');
assert.ok(resolved);
assert.strictEqual(resolved.props.get('slug'), 'topic');
});
test('ネストされたルートを解決できる', () => {
const router = createRouter();
const resolved = router.resolve('/user/alice/followers');
assert.ok(resolved);
assert.strictEqual(resolved.route.path, '/user/:id');
assert.strictEqual(resolved.props.get('id'), 'alice');
assert.ok(resolved.child);
assert.strictEqual(resolved.child.route.path, '/followers');
});
});