|
1 | 1 | jest.mock('react-native');
|
2 |
| -import { scale, verticalScale, moderateScale } from '../lib/scalingUtils'; |
| 2 | +import { scale, verticalScale, moderateScale } from '../lib/scaling-utils'; |
3 | 3 | import ScaledSheet from '../lib/ScaledSheet';
|
4 | 4 |
|
5 | 5 | const getRandomInt = (min = 1, max = 100) => Math.floor(Math.random() * (max - min + 1)) + min;
|
6 | 6 |
|
7 |
| -test('Scale works', () => { |
8 |
| - const number = getRandomInt(); |
9 |
| - const input = { test: `${number}@s` } |
10 |
| - expect(ScaledSheet.create(input).test).toBe(scale(number)); |
11 |
| -}); |
| 7 | +describe('ScaledSheet', () => { |
| 8 | + test('Scale works', () => { |
| 9 | + const number = getRandomInt(); |
| 10 | + const input = { test: `${number}@s` } |
| 11 | + expect(ScaledSheet.create(input).test).toBe(scale(number)); |
| 12 | + }); |
12 | 13 |
|
13 |
| -test('verticalScale works', () => { |
14 |
| - const number = getRandomInt(); |
15 |
| - const input = { test: `${number}@vs` } |
16 |
| - expect(ScaledSheet.create(input).test).toBe(verticalScale(number)); |
17 |
| -}); |
| 14 | + test('verticalScale works', () => { |
| 15 | + const number = getRandomInt(); |
| 16 | + const input = { test: `${number}@vs` } |
| 17 | + expect(ScaledSheet.create(input).test).toBe(verticalScale(number)); |
| 18 | + }); |
18 | 19 |
|
19 |
| -test('moderateScale with default factor works', () => { |
20 |
| - const number = getRandomInt(); |
21 |
| - const input = { test: `${number}@ms` } |
22 |
| - expect(ScaledSheet.create(input).test).toBe(moderateScale(number)); |
23 |
| -}); |
| 20 | + test('moderateScale with default factor works', () => { |
| 21 | + const number = getRandomInt(); |
| 22 | + const input = { test: `${number}@ms` } |
| 23 | + expect(ScaledSheet.create(input).test).toBe(moderateScale(number)); |
| 24 | + }); |
24 | 25 |
|
25 |
| -test('moderateScale with custom factor works', () => { |
26 |
| - const number = getRandomInt(); |
27 |
| - const input = { test: `${number}@ms0.7` } |
28 |
| - expect(ScaledSheet.create(input).test).toBe(moderateScale(number, 0.7)); |
29 |
| -}); |
| 26 | + test('moderateScale with custom factor works', () => { |
| 27 | + const number = getRandomInt(); |
| 28 | + const input = { test: `${number}@ms0.7` } |
| 29 | + expect(ScaledSheet.create(input).test).toBe(moderateScale(number, 0.7)); |
| 30 | + }); |
30 | 31 |
|
31 |
| -test('Scale works with a negative value', () => { |
32 |
| - const number = getRandomInt(-100, -1); |
33 |
| - const input = { test: `${number}@s` } |
34 |
| - expect(ScaledSheet.create(input).test).toBe(scale(number)); |
35 |
| -}); |
| 32 | + test('Scale works with a negative value', () => { |
| 33 | + const number = getRandomInt(-100, -1); |
| 34 | + const input = { test: `${number}@s` } |
| 35 | + expect(ScaledSheet.create(input).test).toBe(scale(number)); |
| 36 | + }); |
36 | 37 |
|
37 |
| -test('moderateScale works with a negative value', () => { |
38 |
| - const number = getRandomInt(-100, -1); |
39 |
| - const input = { test: `${number}@ms0.3` } |
40 |
| - expect(ScaledSheet.create(input).test).toBe(moderateScale(number, 0.3)); |
41 |
| -}); |
| 38 | + test('moderateScale works with a negative value', () => { |
| 39 | + const number = getRandomInt(-100, -1); |
| 40 | + const input = { test: `${number}@ms0.3` } |
| 41 | + expect(ScaledSheet.create(input).test).toBe(moderateScale(number, 0.3)); |
| 42 | + }); |
42 | 43 |
|
43 |
| -test('Scale works on a deeply nested object', () => { |
44 |
| - const number = getRandomInt(); |
45 |
| - const input = { test: { test: { test: `${number}@s` } } } |
46 |
| - expect(ScaledSheet.create(input).test.test.test).toBe(scale(number)); |
47 |
| -}); |
| 44 | + test('Scale works on a deeply nested object', () => { |
| 45 | + const number = getRandomInt(); |
| 46 | + const input = { test: { test: { test: `${number}@s` } } } |
| 47 | + expect(ScaledSheet.create(input).test.test.test).toBe(scale(number)); |
| 48 | + }); |
48 | 49 |
|
49 |
| -test('No special annotation should leave the number intact', () => { |
50 |
| - const number = getRandomInt(); |
51 |
| - const input = { test: number } |
52 |
| - expect(ScaledSheet.create(input).test).toBe(number); |
53 |
| -}); |
| 50 | + test('No special annotation should leave the number intact', () => { |
| 51 | + const number = getRandomInt(); |
| 52 | + const input = { test: number } |
| 53 | + expect(ScaledSheet.create(input).test).toBe(number); |
| 54 | + }); |
54 | 55 |
|
55 |
| -test('ScaledSheet should map a complete StyleSheet with special annotations', () => { |
56 |
| - const input = { |
57 |
| - container: { |
58 |
| - width: '30@s', |
59 |
| - height: '50@vs', |
60 |
| - margin: { |
61 |
| - width: 12, |
62 |
| - height: '12@s', |
63 |
| - paddingBottom: -1 |
| 56 | + test('ScaledSheet should map a complete StyleSheet with special annotations', () => { |
| 57 | + const input = { |
| 58 | + container: { |
| 59 | + width: '30@s', |
| 60 | + height: '50@vs', |
| 61 | + margin: { |
| 62 | + width: 12, |
| 63 | + height: '12@s', |
| 64 | + paddingBottom: -1 |
| 65 | + } |
| 66 | + }, |
| 67 | + row: { |
| 68 | + |
| 69 | + height: '34@ms', |
| 70 | + |
| 71 | + |
| 72 | + marginTop: '-10@s', |
64 | 73 | }
|
65 |
| - }, |
66 |
| - row: { |
67 |
| - |
68 |
| - height: '34@ms', |
69 |
| - |
70 |
| - |
71 |
| - marginTop: '-10@s', |
72 |
| - } |
73 |
| - }; |
| 74 | + }; |
74 | 75 |
|
75 |
| - const expectedOutput = { |
76 |
| - container: { |
77 |
| - width: scale(30), |
78 |
| - height: verticalScale(50), |
79 |
| - margin: { |
80 |
| - width: 12, |
81 |
| - height: scale(12), |
82 |
| - paddingBottom: -1 |
| 76 | + const expectedOutput = { |
| 77 | + container: { |
| 78 | + width: scale(30), |
| 79 | + height: verticalScale(50), |
| 80 | + margin: { |
| 81 | + width: 12, |
| 82 | + height: scale(12), |
| 83 | + paddingBottom: -1 |
| 84 | + } |
| 85 | + }, |
| 86 | + row: { |
| 87 | + padding: moderateScale(10, 0.3), |
| 88 | + height: moderateScale(34), |
| 89 | + marginRight: moderateScale(0.5, 0.9), |
| 90 | + marginLeft: moderateScale(-0.5, 0.9), |
| 91 | + marginTop: scale(-10), |
83 | 92 | }
|
84 |
| - }, |
85 |
| - row: { |
86 |
| - padding: moderateScale(10, 0.3), |
87 |
| - height: moderateScale(34), |
88 |
| - marginRight: moderateScale(0.5, 0.9), |
89 |
| - marginLeft: moderateScale(-0.5, 0.9), |
90 |
| - marginTop: scale(-10), |
91 |
| - } |
92 |
| - }; |
| 93 | + }; |
93 | 94 |
|
94 |
| - expect(JSON.stringify(ScaledSheet.create(input))).toBe(JSON.stringify(expectedOutput)); |
95 |
| -}); |
| 95 | + expect(JSON.stringify(ScaledSheet.create(input))).toBe(JSON.stringify(expectedOutput)); |
| 96 | + }); |
| 97 | +}) |
0 commit comments