-
Notifications
You must be signed in to change notification settings - Fork 207
Expand file tree
/
Copy pathcss-define-vars-test.native.js
More file actions
105 lines (94 loc) · 3.07 KB
/
Copy pathcss-define-vars-test.native.js
File metadata and controls
105 lines (94 loc) · 3.07 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
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import * as React from 'react';
import { css, html } from 'react-strict-dom';
import { act, create } from 'react-test-renderer';
describe('css.defineVars(): @media', () => {
const ReactNative = require('../../src/native/react-native');
beforeEach(() => {
ReactNative.useWindowDimensions.mockReturnValue({
height: 1000,
width: 2000
});
ReactNative.useColorScheme.mockReturnValue('light');
// avoid console messages for these tests
jest.spyOn(console, 'error');
console.error.mockImplementation(() => {});
jest.spyOn(console, 'warn');
console.warn.mockImplementation(() => {});
});
afterEach(() => {
ReactNative.useWindowDimensions.mockReturnValue({
height: 1000,
width: 2000
});
ReactNative.useColorScheme.mockReturnValue('light');
console.error.mockRestore();
console.warn.mockRestore();
jest.clearAllMocks();
});
const tokens = css.defineVars({
prefersColor: {
default: 'blue',
'@media (prefers-color-scheme: dark)': 'darkblue'
},
maxHeight: {
default: 100,
'@media (max-height: 400px)': 300
}
});
const styles = css.create({
root: {
backgroundColor: tokens.prefersColor,
maxHeight: tokens.maxHeight
}
});
describe('@media (prefers-color-scheme)', () => {
test('color-scheme: light - returns default', () => {
let root;
act(() => {
root = create(<html.div style={styles.root} />);
});
expect(root.toJSON().props.style.backgroundColor).toBe('blue');
});
test('color-scheme: dark - returns media query value)', () => {
ReactNative.useColorScheme.mockReturnValue('dark');
let root;
act(() => {
root = create(<html.div style={styles.root} />);
});
expect(root.toJSON().props.style.backgroundColor).toBe('darkblue');
});
});
describe('other media queries', () => {
test('matches (max-height: 400px) - returns default', () => {
ReactNative.useWindowDimensions.mockReturnValue({ height: 100 });
let root;
act(() => {
root = create(<html.span style={styles.root} />);
});
expect(root.toJSON().props.style.maxHeight).toBe(100);
});
test('matches (max-height: 400px) with color-scheme: dark - returns default', () => {
ReactNative.useColorScheme.mockReturnValue('dark');
ReactNative.useWindowDimensions.mockReturnValue({ height: 100 });
let root;
act(() => {
root = create(<html.span style={styles.root} />);
});
expect(root.toJSON().props.style.maxHeight).toBe(100);
});
test('does not match (max-height: 400px) - returns default', () => {
ReactNative.useWindowDimensions.mockReturnValue({ height: 1000 });
let root;
act(() => {
root = create(<html.span style={styles.root} />);
});
expect(root.toJSON().props.style.maxHeight).toBe(100);
});
});
});