1import { ExpoConfig } from '@expo/config-types';
2
3import { getColorsAsObject } from '../Colors';
4import {
5  getStatusBarColor,
6  getStatusBarStyle,
7  setStatusBarColors,
8  setStatusBarStyles,
9} from '../StatusBar';
10import { getAppThemeLightNoActionBarGroup, getStylesGroupAsObject } from '../Styles';
11
12it(`returns statusbar color if provided`, () => {
13  expect(getStatusBarColor({ androidStatusBar: { backgroundColor: '#111111' } })).toMatch(
14    '#111111'
15  );
16});
17
18it(`returns statusbar style if provided`, () => {
19  expect(getStatusBarStyle({ androidStatusBar: { barStyle: 'dark-content' } })).toMatch(
20    'dark-content'
21  );
22});
23
24it(`default statusbar style to light-content if none provided`, () => {
25  expect(getStatusBarStyle({})).toMatch('light-content');
26});
27
28describe('e2e: write statusbar color and style to files correctly', () => {
29  it(`sets the colorPrimaryDark item in styles.xml and adds color to colors.xml if 'androidStatusBar.backgroundColor' is given`, async () => {
30    const config: ExpoConfig = {
31      name: 'foo',
32      slug: 'bar',
33      androidStatusBar: { backgroundColor: '#654321', barStyle: 'dark-content' },
34    };
35    const styles = setStatusBarStyles(config, { resources: {} });
36    const colors = setStatusBarColors(config, { resources: {} });
37
38    const group = getStylesGroupAsObject(styles, getAppThemeLightNoActionBarGroup())!;
39    expect(group.colorPrimaryDark).toBe('@color/colorPrimaryDark');
40    expect(group['android:windowLightStatusBar']).toBe('true');
41    // Ensure the version guard is added
42    expect(styles.resources.style![0].item[0].$['tools:targetApi']).toBe('23');
43    expect(getColorsAsObject(colors)!.colorPrimaryDark).toBe('#654321');
44  });
45
46  it(`skips setting the status bar to translucent if no 'androidStatusBar.backgroundColor' is given`, async () => {
47    const config: ExpoConfig = {
48      name: 'foo',
49      slug: 'bar',
50      androidStatusBar: {},
51    };
52
53    const styles = setStatusBarStyles(config, { resources: {} });
54    const colors = setStatusBarColors(config, { resources: {} });
55
56    const group = getStylesGroupAsObject(styles, getAppThemeLightNoActionBarGroup());
57
58    expect(group).toStrictEqual(null);
59    expect(colors.resources).toStrictEqual({});
60  });
61});
62