|
| 1 | +import * as screens from 'testData/screens'; |
| 2 | + |
| 3 | +const mockClassWithGetter = value => ({ |
| 4 | + get: jest.fn().mockReturnValue(value), |
| 5 | +}); |
| 6 | + |
| 7 | +const mockRequiredClasses = mockValues => { |
| 8 | + jest.mock('Dimensions', () => mockClassWithGetter(mockValues.dimensions)); |
| 9 | + jest.mock('PixelRatio', () => mockClassWithGetter(mockValues.pixelRatio)); |
| 10 | +}; |
| 11 | + |
| 12 | +const expectSize = size => { |
| 13 | + jest.isolateModules(() => { |
| 14 | + const { normalize } = require('config'); |
| 15 | + expect(normalize(1)).toEqual(size); |
| 16 | + }); |
| 17 | +}; |
| 18 | + |
| 19 | +describe('Normalize Text', () => { |
| 20 | + // iOS Devices |
| 21 | + |
| 22 | + it('should normalize correctly on iPhone 5', () => { |
| 23 | + mockRequiredClasses({ dimensions: screens.iPhone5, pixelRatio: 2 }); |
| 24 | + |
| 25 | + expectSize(0.95); |
| 26 | + }); |
| 27 | + |
| 28 | + it('should normalize correctly on iPhone 6', () => { |
| 29 | + mockRequiredClasses({ dimensions: screens.iPhone6, pixelRatio: 2 }); |
| 30 | + |
| 31 | + expectSize(1.15); |
| 32 | + }); |
| 33 | + |
| 34 | + it('should normalize correctly on iPhone 6 Plus', () => { |
| 35 | + mockRequiredClasses({ dimensions: screens.iPhone6Plus, pixelRatio: 3 }); |
| 36 | + |
| 37 | + expectSize(1.27); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should normalize correctly on iPhone 7', () => { |
| 41 | + mockRequiredClasses({ dimensions: screens.iPhone7, pixelRatio: 2 }); |
| 42 | + |
| 43 | + expectSize(1.15); |
| 44 | + }); |
| 45 | + |
| 46 | + it('should normalize correctly on iPhone 7 Plus', () => { |
| 47 | + mockRequiredClasses({ dimensions: screens.iPhone7Plus, pixelRatio: 3 }); |
| 48 | + |
| 49 | + expectSize(1.27); |
| 50 | + }); |
| 51 | + |
| 52 | + it('should normalize correctly on iPod Touch', () => { |
| 53 | + mockRequiredClasses({ dimensions: screens.iPodTouch, pixelRatio: 2 }); |
| 54 | + |
| 55 | + expectSize(0.95); |
| 56 | + }); |
| 57 | + |
| 58 | + it('should normalize correctly on iPad Pro', () => { |
| 59 | + mockRequiredClasses({ dimensions: screens.iPadPro, pixelRatio: 2 }); |
| 60 | + |
| 61 | + expectSize(1.25); |
| 62 | + }); |
| 63 | + |
| 64 | + it('should normalize correctly on iPad Gen 3/4', () => { |
| 65 | + mockRequiredClasses({ dimensions: screens.iPadGen3, pixelRatio: 2 }); |
| 66 | + |
| 67 | + expectSize(1.25); |
| 68 | + }); |
| 69 | + |
| 70 | + it('should normalize correctly on iPad Air', () => { |
| 71 | + mockRequiredClasses({ dimensions: screens.iPadAir, pixelRatio: 2 }); |
| 72 | + |
| 73 | + expectSize(1.25); |
| 74 | + }); |
| 75 | + |
| 76 | + it('should normalize correctly on iPad Mini', () => { |
| 77 | + mockRequiredClasses({ dimensions: screens.iPadMini, pixelRatio: 1 }); |
| 78 | + |
| 79 | + expectSize(1); |
| 80 | + }); |
| 81 | + |
| 82 | + // Android Devices |
| 83 | + |
| 84 | + it('should normalize correctly on Nexus 6P', () => { |
| 85 | + mockRequiredClasses({ dimensions: screens.Nexus6P, pixelRatio: 3.5 }); |
| 86 | + |
| 87 | + expectSize(1.25); |
| 88 | + }); |
| 89 | + |
| 90 | + it('should normalize correctly on Nexus 5X', () => { |
| 91 | + mockRequiredClasses({ dimensions: screens.Nexus5X, pixelRatio: 2.6 }); |
| 92 | + |
| 93 | + expectSize(1.15); |
| 94 | + }); |
| 95 | + |
| 96 | + it('should normalize correctly on Google Pixel', () => { |
| 97 | + mockRequiredClasses({ dimensions: screens.GooglePixel, pixelRatio: 2.6 }); |
| 98 | + |
| 99 | + expectSize(1.15); |
| 100 | + }); |
| 101 | + |
| 102 | + it('should normalize correctly on Google Pixel XL', () => { |
| 103 | + mockRequiredClasses({ dimensions: screens.GooglePixelXL, pixelRatio: 3.5 }); |
| 104 | + |
| 105 | + expectSize(1.25); |
| 106 | + }); |
| 107 | + |
| 108 | + it('should normalize correctly on Samsung Galaxy Note 5', () => { |
| 109 | + mockRequiredClasses({ |
| 110 | + dimensions: screens.SamsungGalaxyNote5, |
| 111 | + pixelRatio: 4, |
| 112 | + }); |
| 113 | + |
| 114 | + expectSize(1); |
| 115 | + }); |
| 116 | + |
| 117 | + it('should normalize correctly on Samsung Galaxy S7', () => { |
| 118 | + mockRequiredClasses({ dimensions: screens.SamsungGalaxyS7, pixelRatio: 4 }); |
| 119 | + |
| 120 | + expectSize(1); |
| 121 | + }); |
| 122 | + |
| 123 | + it('should normalize correctly on Samsung Galaxy S7 Edge', () => { |
| 124 | + mockRequiredClasses({ |
| 125 | + dimensions: screens.SamsungGalaxyS7Edge, |
| 126 | + pixelRatio: 4, |
| 127 | + }); |
| 128 | + |
| 129 | + expectSize(1); |
| 130 | + }); |
| 131 | + |
| 132 | + it('should normalize correctly on LG G5', () => { |
| 133 | + mockRequiredClasses({ dimensions: screens.LGG5, pixelRatio: 4 }); |
| 134 | + |
| 135 | + expectSize(1); |
| 136 | + }); |
| 137 | + |
| 138 | + it('should normalize correctly on OnePlus 3', () => { |
| 139 | + mockRequiredClasses({ dimensions: screens.OnePlus3, pixelRatio: 3 }); |
| 140 | + |
| 141 | + expectSize(1); |
| 142 | + }); |
| 143 | + |
| 144 | + it('should normalize correctly on Nexus 7', () => { |
| 145 | + mockRequiredClasses({ dimensions: screens.Nexus7, pixelRatio: 2 }); |
| 146 | + |
| 147 | + expectSize(1.25); |
| 148 | + }); |
| 149 | + |
| 150 | + it('should normalize correctly on Nexus 9', () => { |
| 151 | + mockRequiredClasses({ dimensions: screens.Nexus9, pixelRatio: 2 }); |
| 152 | + |
| 153 | + expectSize(1.25); |
| 154 | + }); |
| 155 | + |
| 156 | + it('should normalize correctly on Samsung Galaxy Tab 10', () => { |
| 157 | + mockRequiredClasses({ |
| 158 | + dimensions: screens.SamsungGalaxyTab10, |
| 159 | + pixelRatio: 1, |
| 160 | + }); |
| 161 | + |
| 162 | + expectSize(1); |
| 163 | + }); |
| 164 | + |
| 165 | + it('should normalize correctly on ChromebookPixel', () => { |
| 166 | + mockRequiredClasses({ dimensions: screens.ChromebookPixel, pixelRatio: 2 }); |
| 167 | + |
| 168 | + expectSize(1.25); |
| 169 | + }); |
| 170 | +}); |
0 commit comments