-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathpatch-notes.test.tsx
More file actions
131 lines (97 loc) · 4.43 KB
/
patch-notes.test.tsx
File metadata and controls
131 lines (97 loc) · 4.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import PatchNotes, { closeButtonTestId, dialogTestId, backdropTestId } from '$components/PatchNotes';
import {
getLocalStoragePatchNotesKey,
setLocalStoragePatchNotesKey,
setLocalStorageTourHasRun,
} from '$lib/localStorage';
import { LATEST_PATCH_NOTES_UPDATE, shouldShowPatchNotes, usePatchNotesStore } from '$stores/PatchNotesStore';
import { render, screen, act, waitFor } from '@testing-library/react';
import { afterEach, describe, expect, test, vi } from 'vitest';
describe('patch notes', () => {
/**
* A date that's guaranteed to be outdated.
*/
const outdatedPatchNotes = '00000000';
afterEach(() => {
vi.useRealTimers();
});
describe('patch notes displays appropriately', () => {
test('displays when latest patch notes is outdated ', () => {
vi.useFakeTimers();
vi.setSystemTime(new Date('2026-02-15T12:00:00.000Z'));
setLocalStoragePatchNotesKey(outdatedPatchNotes);
setLocalStorageTourHasRun('true');
usePatchNotesStore.setState({ showPatchNotes: shouldShowPatchNotes() });
render(<PatchNotes />);
expect(screen.queryByTestId(dialogTestId)).toBeTruthy();
});
test('no display when latest patch notes is up to date', () => {
vi.useFakeTimers();
vi.setSystemTime(new Date('2026-02-15T12:00:00.000Z'));
setLocalStoragePatchNotesKey(LATEST_PATCH_NOTES_UPDATE);
usePatchNotesStore.setState({ showPatchNotes: shouldShowPatchNotes() });
render(<PatchNotes />);
expect(screen.queryByTestId(dialogTestId)).toBeFalsy();
});
test('no auto display when patch notes are older than 30 calendar days', () => {
vi.useFakeTimers();
vi.setSystemTime(new Date('2026-03-02T12:00:00.000Z'));
setLocalStoragePatchNotesKey(outdatedPatchNotes);
setLocalStorageTourHasRun('true');
usePatchNotesStore.setState({ showPatchNotes: shouldShowPatchNotes() });
render(<PatchNotes />);
expect(screen.queryByTestId(dialogTestId)).toBeFalsy();
});
test('auto display still allowed on the 30th calendar day after release', () => {
vi.useFakeTimers();
vi.setSystemTime(new Date('2026-03-01T12:00:00.000Z'));
setLocalStoragePatchNotesKey(outdatedPatchNotes);
setLocalStorageTourHasRun('true');
usePatchNotesStore.setState({ showPatchNotes: shouldShowPatchNotes() });
render(<PatchNotes />);
expect(screen.queryByTestId(dialogTestId)).toBeTruthy();
});
});
describe('close patch notes with button', () => {
test('clicking the button closes the dialog', async () => {
usePatchNotesStore.setState({ showPatchNotes: true });
render(<PatchNotes />);
act(() => {
screen.getByTestId(closeButtonTestId).click();
});
await waitFor(() => {
expect(screen.queryByTestId(dialogTestId)).toBeNull();
});
});
test('the latest patch notes is saved to local storage', () => {
setLocalStoragePatchNotesKey(outdatedPatchNotes);
usePatchNotesStore.setState({ showPatchNotes: true });
render(<PatchNotes />);
act(() => {
screen.getByTestId(closeButtonTestId).click();
});
expect(getLocalStoragePatchNotesKey()).toEqual(LATEST_PATCH_NOTES_UPDATE);
});
});
describe('closing the dialog by clicking the backdrop ', () => {
test('clicking the backdrop closes the dialog', async () => {
usePatchNotesStore.setState({ showPatchNotes: true });
render(<PatchNotes />);
act(() => {
screen.getByTestId(backdropTestId).click();
});
await waitFor(() => {
expect(screen.queryByTestId(dialogTestId)).toBeNull();
});
});
test('the latest patch notes is saved to local storage', () => {
setLocalStoragePatchNotesKey(outdatedPatchNotes);
usePatchNotesStore.setState({ showPatchNotes: true });
render(<PatchNotes />);
act(() => {
screen.getByTestId(backdropTestId).click();
});
expect(getLocalStoragePatchNotesKey()).toEqual(LATEST_PATCH_NOTES_UPDATE);
});
});
});