]> git.r.bdr.sh - rbdr/forum/blob - src/lib/components/topic_summary/topic_summary.test.ts
a4c46bf023da220f2187d6faa8a94e567b7d695c
[rbdr/forum] / src / lib / components / topic_summary / topic_summary.test.ts
1 /**
2 * @jest-environment jsdom
3 */
4
5 import '@testing-library/jest-dom/extend-expect';
6
7 import { render } from '@testing-library/svelte';
8 import '$lib/i18n';
9
10 import TopicSummary from './topic_summary.svelte';
11
12 const internals = {
13 results: null
14 };
15
16 describe('Topic Summary component', () => {
17
18 beforeEach(() => {
19
20 internals.results = render(TopicSummary, { props: {
21 topic: {
22 id: 'ea2431c8-5c1c-4ed0-907a-45e012696ab8',
23 title: 'I sure am a test topic',
24 ttl: 160 * 1000,
25 updated_at: Date.now()
26 }
27 } });
28 });
29
30 test('It should display the title', () => {
31
32 expect(internals.results.getByText('I sure am a test topic'))
33 .toBeVisible();
34 });
35
36 test('Topic title should be a permalink', () => {
37
38 expect(internals.results.getByText('I sure am a test topic').closest('a'))
39 .toHaveAttribute('href', '/t/ea2431c8-5c1c-4ed0-907a-45e012696ab8');
40 });
41
42 test('It should display remaining time in readable format', () => {
43
44 expect(internals.results.getByText(/2 minutes remaining/))
45 .toBeVisible();
46 });
47 });