-
Notifications
You must be signed in to change notification settings - Fork 960
Expand file tree
/
Copy pathdiceAppearance.test.ts
More file actions
65 lines (50 loc) · 1.88 KB
/
Copy pathdiceAppearance.test.ts
File metadata and controls
65 lines (50 loc) · 1.88 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
import {beforeEach, describe, expect, it, vi} from 'vitest';
vi.mock('@components/wrappers/sticker', () => ({
default: vi.fn()
}));
vi.mock('@lib/lottie/lottieLoader', () => ({
default: {waitForFirstFrame: vi.fn()}
}));
import type {BubbleContext} from '@components/chat/bubbles';
import wrapDice from '@components/chat/bubbleParts/dice';
const createContext = (isInUnread: boolean, emoticon = '🎲') => {
const wrapSticker = vi.fn((_context: BubbleContext, _options: Parameters<BubbleContext['bubbles']['wrapSticker']>[1]) =>
Promise.resolve({render: Promise.resolve()}));
const context = {
messageMedia: {emoticon, value: 6},
bubble: document.createElement('div'),
bubbleContainer: document.createElement('div'),
attachmentDiv: document.createElement('div'),
isInUnread,
bubbles: {
managers: {
appStickersManager: {
getStickerSetByDice: vi.fn(() => Promise.resolve({documents: []}))
}
},
wrapSticker
}
} as unknown as BubbleContext;
return {context, wrapSticker};
};
beforeEach(() => {
vi.clearAllMocks();
});
describe('dice appearance', () => {
it('skips fade-in when rendering an already-settled result', () => {
const {context, wrapSticker} = createContext(false);
wrapDice(context);
expect(wrapSticker.mock.calls[0][1].noFadeIn).toBe(true);
});
it('keeps fade-in when an unread dice will play', () => {
const {context, wrapSticker} = createContext(true);
wrapDice(context);
expect(wrapSticker.mock.calls[0][1].noFadeIn).toBeUndefined();
});
it('skips fade-in for every part of an already-settled slot machine', () => {
const {context, wrapSticker} = createContext(false, '🎰');
wrapDice(context);
expect(wrapSticker.mock.calls.length).toBeGreaterThan(1);
expect(wrapSticker.mock.calls.every(([, options]) => options.noFadeIn === true)).toBe(true);
});
});