|
1 | | -/* |
2 | | - * Copyright 2019 Google LLC |
3 | | - * |
4 | | - * Licensed under the Apache License, Version 2.0 (the 'License'); |
5 | | - * you may not use this file except in compliance with the License. |
6 | | - * You may obtain a copy of the License at |
7 | | - * |
8 | | - * https://www.apache.org/licenses/LICENSE-2.0 |
9 | | - * |
10 | | - * Unless required by applicable law or agreed to in writing, software |
11 | | - * distributed under the License is distributed on an 'AS IS' BASIS, |
12 | | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | | - * See the License for the specific language governing permissions and |
14 | | - * limitations under the License. |
15 | | - */ |
16 | | - |
17 | | -import { renderHook, act } from '@testing-library/react-hooks'; |
18 | | - |
19 | | -afterEach(function() { |
20 | | - // Reload hook for every test |
21 | | - jest.resetModules(); |
22 | | -}); |
23 | | - |
24 | | -describe('useSaveData', () => { |
25 | | - test(`should return "true" for unsupported case`, () => { |
26 | | - const { useSaveData } = require('./'); |
27 | | - const { result } = renderHook(() => useSaveData()); |
28 | | - |
29 | | - expect(result.current.unsupported).toBe(true); |
30 | | - expect(result.current.saveData).toEqual(null); |
31 | | - }); |
32 | | - |
33 | | - test('should return initialSaveDataStatus for unsupported case', () => { |
34 | | - const initialSaveDataStatus = true; |
35 | | - const { useSaveData } = require('./'); |
36 | | - const { result } = renderHook(() => useSaveData(initialSaveDataStatus)); |
37 | | - |
38 | | - expect(result.current.unsupported).toBe(true); |
39 | | - expect(result.current.saveData).toBe(initialSaveDataStatus); |
40 | | - }); |
41 | | - |
42 | | - test(`should return "true" for enabled save data`, () => { |
43 | | - global.navigator.connection = { |
44 | | - saveData: true |
45 | | - }; |
46 | | - const { useSaveData } = require('./'); |
47 | | - const { result } = renderHook(() => useSaveData()); |
48 | | - |
49 | | - expect(result.current.unsupported).toBe(false); |
50 | | - expect(result.current.saveData).toEqual(navigator.connection.saveData); |
51 | | - }); |
52 | | - |
53 | | - test(`should return "false" for disabled save data`, () => { |
54 | | - global.navigator.connection = { |
55 | | - saveData: false |
56 | | - }; |
57 | | - const { useSaveData } = require('./'); |
58 | | - const { result } = renderHook(() => useSaveData()); |
59 | | - |
60 | | - expect(result.current.unsupported).toBe(false); |
61 | | - expect(result.current.saveData).toEqual(navigator.connection.saveData); |
62 | | - }); |
63 | | - |
64 | | - test('should not return initialSaveDataStatus for supported case', () => { |
65 | | - const initialSaveDataStatus = false; |
66 | | - global.navigator.connection = { |
67 | | - saveData: true |
68 | | - }; |
69 | | - const { useSaveData } = require('./'); |
70 | | - const { result } = renderHook(() => useSaveData(initialSaveDataStatus)); |
71 | | - |
72 | | - expect(result.current.unsupported).toBe(false); |
73 | | - expect(result.current.saveData).toEqual(navigator.connection.saveData); |
74 | | - }); |
75 | | -}); |
| 1 | +/* |
| 2 | + * Copyright 2019 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the 'License'); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an 'AS IS' BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import { renderHook, act } from '@testing-library/react-hooks'; |
| 18 | + |
| 19 | +afterEach(function() { |
| 20 | + // Reload hook for every test |
| 21 | + jest.resetModules(); |
| 22 | +}); |
| 23 | + |
| 24 | +describe('useSaveData', () => { |
| 25 | + test(`should return "true" for unsupported case`, () => { |
| 26 | + const { useSaveData } = require('./'); |
| 27 | + const { result } = renderHook(() => useSaveData()); |
| 28 | + |
| 29 | + expect(result.current.unsupported).toBe(true); |
| 30 | + expect(result.current.saveData).toEqual(null); |
| 31 | + }); |
| 32 | + |
| 33 | + test('should return initialSaveData for unsupported case', () => { |
| 34 | + const initialSaveData = true; |
| 35 | + const { useSaveData } = require('./'); |
| 36 | + const { result } = renderHook(() => useSaveData(initialSaveData)); |
| 37 | + |
| 38 | + expect(result.current.unsupported).toBe(true); |
| 39 | + expect(result.current.saveData).toBe(initialSaveData); |
| 40 | + }); |
| 41 | + |
| 42 | + test(`should return "true" for enabled save data`, () => { |
| 43 | + global.navigator.connection = { |
| 44 | + saveData: true |
| 45 | + }; |
| 46 | + const { useSaveData } = require('./'); |
| 47 | + const { result } = renderHook(() => useSaveData()); |
| 48 | + |
| 49 | + expect(result.current.unsupported).toBe(false); |
| 50 | + expect(result.current.saveData).toEqual(navigator.connection.saveData); |
| 51 | + }); |
| 52 | + |
| 53 | + test(`should return "false" for disabled save data`, () => { |
| 54 | + global.navigator.connection = { |
| 55 | + saveData: false |
| 56 | + }; |
| 57 | + const { useSaveData } = require('./'); |
| 58 | + const { result } = renderHook(() => useSaveData()); |
| 59 | + |
| 60 | + expect(result.current.unsupported).toBe(false); |
| 61 | + expect(result.current.saveData).toEqual(navigator.connection.saveData); |
| 62 | + }); |
| 63 | + |
| 64 | + test('should not return initialSaveData for supported case', () => { |
| 65 | + const initialSaveData = false; |
| 66 | + global.navigator.connection = { |
| 67 | + saveData: true |
| 68 | + }; |
| 69 | + const { useSaveData } = require('./'); |
| 70 | + const { result } = renderHook(() => useSaveData(initialSaveData)); |
| 71 | + |
| 72 | + expect(result.current.unsupported).toBe(false); |
| 73 | + expect(result.current.saveData).toEqual(navigator.connection.saveData); |
| 74 | + }); |
| 75 | +}); |
0 commit comments