13f609562SBartosz Kaszubowskiimport { screen } from '@testing-library/react'; 2586106d6SBartłomiej Klocek 3586106d6SBartłomiej Klocekimport AppConfigSchemaPropertiesTable, { 4586106d6SBartłomiej Klocek formatSchema, 5586106d6SBartłomiej Klocek createDescription, 6586106d6SBartłomiej Klocek Property, 7586106d6SBartłomiej Klocek} from './AppConfigSchemaPropertiesTable'; 8586106d6SBartłomiej Klocek 93f609562SBartosz Kaszubowskiimport { renderWithHeadings } from '~/common/test-utilities'; 10586106d6SBartłomiej Klocek 11586106d6SBartłomiej Klocekconst testSchema: Record<string, Property> = { 12586106d6SBartłomiej Klocek name: { 13586106d6SBartłomiej Klocek description: 'Name of your app.', 14586106d6SBartłomiej Klocek type: 'string', 15586106d6SBartłomiej Klocek meta: { 16586106d6SBartłomiej Klocek bareWorkflow: "Edit the 'Display Name' field in Xcode", 17586106d6SBartłomiej Klocek }, 18586106d6SBartłomiej Klocek }, 19586106d6SBartłomiej Klocek androidNavigationBar: { 20586106d6SBartłomiej Klocek description: 'Configuration for the bottom navigation bar on Android.', 21586106d6SBartłomiej Klocek type: 'object', 22586106d6SBartłomiej Klocek properties: { 23586106d6SBartłomiej Klocek visible: { 24586106d6SBartłomiej Klocek description: 'Determines how and when the navigation bar is shown.', 25586106d6SBartłomiej Klocek type: 'string', 26586106d6SBartłomiej Klocek properties: { 27586106d6SBartłomiej Klocek always: { 28586106d6SBartłomiej Klocek description: 'Test sub-sub-property', 29586106d6SBartłomiej Klocek type: 'boolean', 30586106d6SBartłomiej Klocek }, 31586106d6SBartłomiej Klocek }, 32586106d6SBartłomiej Klocek meta: { 33586106d6SBartłomiej Klocek expoKit: 'Set this property using Xcode.', 34586106d6SBartłomiej Klocek }, 35586106d6SBartłomiej Klocek enum: ['leanback', 'immersive', 'sticky-immersive'], 36586106d6SBartłomiej Klocek }, 37586106d6SBartłomiej Klocek backgroundColor: { 38586106d6SBartłomiej Klocek description: 'Specifies the background color of the navigation bar. ', 39586106d6SBartłomiej Klocek type: 'string', 40586106d6SBartłomiej Klocek pattern: '^#|(#)\\d{6}$', 41586106d6SBartłomiej Klocek meta: { 42586106d6SBartłomiej Klocek regexHuman: "6 character long hex color string, eg: `'#000000'`", 43586106d6SBartłomiej Klocek }, 44586106d6SBartłomiej Klocek }, 45586106d6SBartłomiej Klocek }, 46586106d6SBartłomiej Klocek meta: { 47586106d6SBartłomiej Klocek expoKit: 'Set this property using AppConstants.java.', 48586106d6SBartłomiej Klocek bareWorkflow: 'Set this property using just Xcode', 49586106d6SBartłomiej Klocek }, 50586106d6SBartłomiej Klocek }, 51586106d6SBartłomiej Klocek intentFilters: { 52586106d6SBartłomiej Klocek description: 'Configuration for setting an array of custom intent filters in Android manifest.', 53586106d6SBartłomiej Klocek example: [ 54586106d6SBartłomiej Klocek { 55586106d6SBartłomiej Klocek autoVerify: true, 56586106d6SBartłomiej Klocek data: { 5738fcf40fSJames Ide host: '*.example.com', 58586106d6SBartłomiej Klocek }, 59586106d6SBartłomiej Klocek }, 60586106d6SBartłomiej Klocek ], 6138fcf40fSJames Ide exampleString: '\n [{ \n "autoVerify": true, \n "data": {"host": "*.example.com" \n } \n }]', 62586106d6SBartłomiej Klocek type: 'array', 63586106d6SBartłomiej Klocek uniqueItems: true, 64586106d6SBartłomiej Klocek items: { 65586106d6SBartłomiej Klocek type: 'object', 66586106d6SBartłomiej Klocek properties: { 67586106d6SBartłomiej Klocek autoVerify: { 68586106d6SBartłomiej Klocek description: 69586106d6SBartłomiej Klocek 'You may also use an intent filter to set your app as the default handler for links', 70586106d6SBartłomiej Klocek type: 'boolean', 71586106d6SBartłomiej Klocek }, 72586106d6SBartłomiej Klocek data: { 73586106d6SBartłomiej Klocek type: ['array', 'object'], 74586106d6SBartłomiej Klocek items: { 75586106d6SBartłomiej Klocek type: 'object', 76586106d6SBartłomiej Klocek properties: { 7738fcf40fSJames Ide host: { description: 'the host, e.g. `example.com`', type: 'string' }, 78586106d6SBartłomiej Klocek }, 79586106d6SBartłomiej Klocek additionalProperties: false, 80586106d6SBartłomiej Klocek }, 81586106d6SBartłomiej Klocek properties: { 82586106d6SBartłomiej Klocek host: { type: 'string' }, 83586106d6SBartłomiej Klocek }, 84586106d6SBartłomiej Klocek additionalProperties: false, 85586106d6SBartłomiej Klocek }, 86586106d6SBartłomiej Klocek }, 87586106d6SBartłomiej Klocek additionalProperties: false, 88586106d6SBartłomiej Klocek required: ['action'], 89586106d6SBartłomiej Klocek }, 90586106d6SBartłomiej Klocek meta: { 91586106d6SBartłomiej Klocek bareWorkflow: 'This is set in AndroidManifest.xml directly.', 92586106d6SBartłomiej Klocek }, 93586106d6SBartłomiej Klocek }, 94586106d6SBartłomiej Klocek}; 95586106d6SBartłomiej Klocek 96586106d6SBartłomiej Klocekdescribe('AppConfigSchemaPropertiesTable', () => { 97586106d6SBartłomiej Klocek test('correctly matches snapshot', () => { 983f609562SBartosz Kaszubowski const { container } = renderWithHeadings( 99586106d6SBartłomiej Klocek <AppConfigSchemaPropertiesTable schema={testSchema} /> 100586106d6SBartłomiej Klocek ); 101586106d6SBartłomiej Klocek expect(container).toMatchSnapshot(); 102586106d6SBartłomiej Klocek }); 1033f609562SBartosz Kaszubowski 1043f609562SBartosz Kaszubowski test('description includes all required components', () => { 1053f609562SBartosz Kaszubowski renderWithHeadings( 1063f609562SBartosz Kaszubowski <AppConfigSchemaPropertiesTable schema={{ entry: testSchema.androidNavigationBar }} /> 1073f609562SBartosz Kaszubowski ); 1083f609562SBartosz Kaszubowski 109*a077d175SBartosz Kaszubowski expect(screen.getByText('Specifies the background color of the navigation bar.')); 1103f609562SBartosz Kaszubowski expect(screen.getByText('6 character long hex color string, eg:')); 1113f609562SBartosz Kaszubowski expect(screen.getByText('Set this property using just Xcode')); 1123f609562SBartosz Kaszubowski expect(screen.getByText('Set this property using AppConstants.java.')); 1133f609562SBartosz Kaszubowski }); 114586106d6SBartłomiej Klocek}); 115586106d6SBartłomiej Klocek 116586106d6SBartłomiej Klocekdescribe('formatSchema', () => { 117586106d6SBartłomiej Klocek const formattedSchema = formatSchema(Object.entries(testSchema)); 118*a077d175SBartosz Kaszubowski test('name is property at root level', () => { 119*a077d175SBartosz Kaszubowski expect(formattedSchema[0].name).toBe('name'); 120586106d6SBartłomiej Klocek }); 121*a077d175SBartosz Kaszubowski test('androidNavigationBar has two subproperties', () => { 122*a077d175SBartosz Kaszubowski expect(formattedSchema[1].subproperties.length).toBe(2); 123586106d6SBartłomiej Klocek }); 124*a077d175SBartosz Kaszubowski test('visible is androidNavigationBar subproperty', () => { 125*a077d175SBartosz Kaszubowski expect(formattedSchema[1].subproperties[0].name).toBe('visible'); 126586106d6SBartłomiej Klocek }); 127*a077d175SBartosz Kaszubowski test('always is visible subproperty', () => { 128*a077d175SBartosz Kaszubowski expect(formattedSchema[1].subproperties[0].subproperties[0].name).toBe('always'); 129586106d6SBartłomiej Klocek }); 130*a077d175SBartosz Kaszubowski test('backgroundColor is androidNavigationBar subproperty', () => { 131*a077d175SBartosz Kaszubowski expect(formattedSchema[1].subproperties[1].name).toBe('backgroundColor'); 132586106d6SBartłomiej Klocek }); 133*a077d175SBartosz Kaszubowski test('intentFilters is property at root level', () => { 134*a077d175SBartosz Kaszubowski expect(formattedSchema[2].name).toBe('intentFilters'); 135586106d6SBartłomiej Klocek }); 136*a077d175SBartosz Kaszubowski test('autoVerify is intentFilters subproperty', () => { 137*a077d175SBartosz Kaszubowski expect(formattedSchema[2].subproperties[0].name).toBe('autoVerify'); 138586106d6SBartłomiej Klocek }); 139*a077d175SBartosz Kaszubowski test('data is intentFilters subproperty', () => { 140*a077d175SBartosz Kaszubowski expect(formattedSchema[2].subproperties[1].name).toBe('data'); 141586106d6SBartłomiej Klocek }); 142*a077d175SBartosz Kaszubowski test('host is data subproperty', () => { 143*a077d175SBartosz Kaszubowski expect(formattedSchema[2].subproperties[1].subproperties[0].name).toBe('host'); 144586106d6SBartłomiej Klocek }); 145586106d6SBartłomiej Klocek}); 146586106d6SBartłomiej Klocek 147586106d6SBartłomiej Klocekdescribe('createDescription', () => { 1483f609562SBartosz Kaszubowski test('type and description are rendered correctly', () => { 149586106d6SBartłomiej Klocek const intentFiltersObject = Object.entries(testSchema)[2]; 150586106d6SBartłomiej Klocek const intentFiltersObjectValue = intentFiltersObject[1] as any; 151586106d6SBartłomiej Klocek const result = createDescription(intentFiltersObject); 152586106d6SBartłomiej Klocek 153*a077d175SBartosz Kaszubowski expect(result).toBe(`${intentFiltersObjectValue.description}`); 154586106d6SBartłomiej Klocek }); 155586106d6SBartłomiej Klocek 1563f609562SBartosz Kaszubowski test('regexHuman is added correctly', () => { 157586106d6SBartłomiej Klocek //Note: to access this subproperty is tedious without a call to formatSchema 158586106d6SBartłomiej Klocek const backgroundColorObject = Object.entries(Object.values(testSchema)[1].properties!)[1]; 159586106d6SBartłomiej Klocek const backgroundColorObjectValue = backgroundColorObject[1]; 160586106d6SBartłomiej Klocek const result = createDescription(backgroundColorObject); 161586106d6SBartłomiej Klocek 162586106d6SBartłomiej Klocek expect(result).toBe( 163*a077d175SBartosz Kaszubowski `${backgroundColorObjectValue.description}\n\n${backgroundColorObjectValue.meta!.regexHuman}` 164586106d6SBartłomiej Klocek ); 165586106d6SBartłomiej Klocek }); 166586106d6SBartłomiej Klocek}); 167