2023-07-27 00:31:52 -05:00
|
|
|
/*
|
2024-02-13 09:50:11 -06:00
|
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
2023-07-27 00:31:52 -05:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2023-12-15 17:56:26 -06:00
|
|
|
import { afterEach, assert, describe, test } from 'vitest';
|
|
|
|
import { cleanup, render, type RenderResult } from '@testing-library/vue';
|
2023-03-12 19:46:33 -05:00
|
|
|
import './init';
|
2023-09-03 23:33:38 -05:00
|
|
|
import type * as Misskey from 'misskey-js';
|
2023-10-21 04:38:07 -05:00
|
|
|
import { directives } from '@/directives/index.js';
|
|
|
|
import { components } from '@/components/index.js';
|
2023-03-12 19:46:33 -05:00
|
|
|
import XHome from '@/pages/user/home.vue';
|
2023-12-15 17:56:26 -06:00
|
|
|
import 'intersection-observer';
|
2023-03-12 19:46:33 -05:00
|
|
|
|
|
|
|
describe('XHome', () => {
|
2023-09-03 23:33:38 -05:00
|
|
|
const renderHome = (user: Partial<Misskey.entities.UserDetailed>): RenderResult => {
|
2023-03-12 19:46:33 -05:00
|
|
|
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: [],
|
2023-10-21 04:38:07 -05:00
|
|
|
avatarUrl: 'https://example.com',
|
|
|
|
avatarDecorations: [],
|
2023-03-12 19:46:33 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
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: [],
|
2023-10-21 04:38:07 -05:00
|
|
|
avatarUrl: 'https://example.com',
|
|
|
|
avatarDecorations: [],
|
2023-03-12 19:46:33 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
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');
|
|
|
|
});
|
|
|
|
});
|