-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Expand file tree
/
Copy pathionic-global.spec.ts
More file actions
110 lines (88 loc) · 2.71 KB
/
ionic-global.spec.ts
File metadata and controls
110 lines (88 loc) · 2.71 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
const getMode = jest.fn();
const getElement = jest.fn();
jest.mock('@stencil/core', () => {
const original = jest.requireActual('@stencil/core');
return {
...original,
getMode,
getElement,
};
});
/**
* The implementation needs to be mocked before the implementation is imported.
*/
// eslint-disable-next-line import/first
import { getIonTheme, getIonMode } from '../ionic-global';
describe('Ionic Global', () => {
describe('getIonMode', () => {
const parentRef = { mode: 'md' };
const ref = { parentElement: parentRef };
beforeEach(() => {
getMode.mockImplementation((ref) => ref.mode ?? parentRef.mode);
getElement.mockImplementation(() => ({
closest: () => ({
getAttribute: () => parentRef.mode,
}),
}));
});
afterEach(() => {
getMode.mockReset();
getElement.mockReset();
});
it('should return the mode value of the element reference', () => {
const ref = { mode: 'ios' };
getMode.mockImplementation((ref) => ref.mode);
getElement.mockImplementation(() => ({
closest: () => ({
getAttribute: () => ref.mode,
}),
}));
expect(getIonMode(ref)).toBe('ios');
});
it('should return the mode value of the closest parent with a valid mode', () => {
expect(getIonMode(ref)).toBe('md');
});
it('should return the default mode if the mode cannot be determined', () => {
expect(getIonMode()).toBe('md');
});
it('should return the default theme if no mode is found', () => {
const ref = { mode: undefined };
expect(getIonMode(ref)).toBe('md');
});
});
describe('getIonTheme', () => {
const parentRef = { mode: 'md' };
beforeEach(() => {
getMode.mockImplementation((ref) => ref?.mode ?? parentRef.mode);
getElement.mockImplementation(() => ({
closest: () => ({
getAttribute: () => parentRef.mode,
}),
}));
});
afterEach(() => {
getMode.mockReset();
getElement.mockReset();
});
it('should return the theme value of the element reference', () => {
const ref = { mode: 'ios' };
expect(getIonTheme(ref)).toBe('ios');
});
it('should return the theme value of the closest parent with a valid theme', () => {
getElement.mockImplementation(() => ({
closest: () => ({
getAttribute: () => 'ios',
}),
}));
expect(getIonTheme()).toBe('ios');
});
it('should return the default theme if it cannot be determined', () => {
getElement.mockImplementation(() => ({
closest: () => ({
getAttribute: () => null,
}),
}));
expect(getIonTheme()).toBe('md');
});
});
});