1
1
mirror of https://github.com/kokonect-link/cherrypick synced 2024-12-14 14:48:53 +09:00
cherrypick/packages/frontend/test/home.test.ts

68 lines
2.0 KiB
TypeScript
Raw Normal View History

/*
2023-08-01 17:16:39 +09:00
* SPDX-FileCopyrightText: syuilo and other misskey, cherrypick contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { describe, test, assert, afterEach } from 'vitest';
import { render, cleanup, type RenderResult } from '@testing-library/vue';
import './init';
2023-09-05 18:24:34 +09:00
import type * as Misskey from 'cherrypick-js';
import { directives } from '@/directives/index.js';
import { components } from '@/components/index.js';
import XHome from '@/pages/user/home.vue';
describe('XHome', () => {
const renderHome = (user: Partial<Misskey.entities.UserDetailed>): RenderResult => {
return render(XHome, {
props: { user, disableNotes: true },
global: { directives, components },
});
};
afterEach(() => {
cleanup();
});
test('Should render the remote caution when user.host exists', async () => {
const home = renderHome({
id: 'blobcat',
name: 'blobcat',
host: 'example.com',
uri: 'https://example.com/@user',
url: 'https://example.com/@user/profile',
roles: [],
createdAt: '1970-01-01T00:00:00.000Z',
fields: [],
pinnedNotes: [],
avatarUrl: 'https://example.com',
avatarDecorations: [],
});
const anchor = home.container.querySelector<HTMLAnchorElement>('a[href^="https://example.com/"]');
assert.exists(anchor, 'anchor to the remote exists');
assert.strictEqual(anchor?.href, 'https://example.com/@user/profile');
assert.ok(anchor?.parentElement?.classList.contains('warn'), 'the parent is a warning');
});
test('The remote caution should fall back to uri if url is null', async () => {
const home = renderHome({
id: 'blobcat',
name: 'blobcat',
host: 'example.com',
uri: 'https://example.com/@user',
url: null,
roles: [],
createdAt: '1970-01-01T00:00:00.000Z',
fields: [],
pinnedNotes: [],
avatarUrl: 'https://example.com',
avatarDecorations: [],
});
const anchor = home.container.querySelector<HTMLAnchorElement>('a[href^="https://example.com/"]');
assert.exists(anchor, 'anchor to the remote exists');
assert.strictEqual(anchor?.href, 'https://example.com/@user');
});
});