1import * as WarningAggregator from '../../utils/warnings';
2import { getRequiresFullScreen, setRequiresFullScreen } from '../RequiresFullScreen';
3
4it(`returns true if nothing provided`, () => {
5  expect(getRequiresFullScreen({ ios: {} })).toBe(true);
6});
7it(`returns false if nothing provided after 43`, () => {
8  expect(getRequiresFullScreen({ ios: {}, sdkVersion: '43.0.0' })).toBe(false);
9  expect(getRequiresFullScreen({ ios: {}, sdkVersion: 'UNVERSIONED' })).toBe(false);
10});
11it(`asserts invalid SDK version`, () => {
12  expect(() => getRequiresFullScreen({ ios: {}, sdkVersion: '43.0' })).toThrow(/version/);
13});
14
15it(`returns the given value if provided`, () => {
16  expect(getRequiresFullScreen({ ios: { requireFullScreen: false } })).toBe(false);
17  expect(getRequiresFullScreen({ ios: { requireFullScreen: true } })).toBe(true);
18});
19
20it(`sets UIRequiresFullScreen value`, () => {
21  expect(setRequiresFullScreen({ ios: { requireFullScreen: false } }, {})).toMatchObject({
22    UIRequiresFullScreen: false,
23  });
24
25  expect(setRequiresFullScreen({}, {})).toMatchObject({
26    UIRequiresFullScreen: true,
27  });
28});
29
30beforeEach(() => {
31  // @ts-ignore: jest
32  // eslint-disable-next-line import/namespace
33  WarningAggregator.addWarningIOS = jest.fn();
34});
35
36it(`updates the UISupportedInterfaceOrientations~ipad values to support iPad multi-tasking`, () => {
37  expect(setRequiresFullScreen({ ios: { requireFullScreen: false } }, {})).toMatchObject({
38    UIRequiresFullScreen: false,
39    'UISupportedInterfaceOrientations~ipad': [
40      'UIInterfaceOrientationPortrait',
41      'UIInterfaceOrientationPortraitUpsideDown',
42      'UIInterfaceOrientationLandscapeLeft',
43      'UIInterfaceOrientationLandscapeRight',
44    ],
45  });
46
47  expect(WarningAggregator.addWarningIOS).not.toBeCalled();
48});
49
50it(`warns when the predefined UISupportedInterfaceOrientations~ipad values are invalid`, () => {
51  setRequiresFullScreen(
52    { ios: { requireFullScreen: false } },
53    {
54      'UISupportedInterfaceOrientations~ipad': [
55        'UIInterfaceOrientationPortrait',
56        'UIInterfaceOrientationPortraitUpsideDown',
57        'UIInterfaceOrientationLandscapeRight',
58      ],
59    }
60  );
61
62  expect(WarningAggregator.addWarningIOS).toBeCalledTimes(1);
63});
64
65it(`does not warn when predefined orientation mask matches required values`, () => {
66  setRequiresFullScreen(
67    { ios: { requireFullScreen: false } },
68    {
69      'UISupportedInterfaceOrientations~ipad': [
70        'UIInterfaceOrientationPortrait',
71        'UIInterfaceOrientationPortraitUpsideDown',
72        'UIInterfaceOrientationLandscapeLeft',
73        'UIInterfaceOrientationLandscapeRight',
74      ],
75    }
76  );
77
78  expect(WarningAggregator.addWarningIOS).not.toBeCalled();
79});
80
81it(`does not warn when predefined orientation mask is empty`, () => {
82  setRequiresFullScreen(
83    { ios: { requireFullScreen: false } },
84    {
85      'UISupportedInterfaceOrientations~ipad': [],
86    }
87  );
88
89  expect(WarningAggregator.addWarningIOS).not.toBeCalled();
90});
91
92it(`cannot remove predefined orientation mask`, () => {
93  let plist = {};
94  plist = setRequiresFullScreen({ ios: { requireFullScreen: false } }, plist);
95  expect(plist['UISupportedInterfaceOrientations~ipad']?.length).toBe(4);
96  plist = setRequiresFullScreen({ ios: { requireFullScreen: true } }, plist);
97  expect(plist['UISupportedInterfaceOrientations~ipad']?.length).toBe(4);
98  expect(WarningAggregator.addWarningIOS).not.toBeCalled();
99});
100