Skip to content

Commit

Permalink
Write test for parseRows function
Browse files Browse the repository at this point in the history
  • Loading branch information
melton-jason committed May 13, 2024
1 parent 986ea33 commit 131ad7b
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const {
parseFormTableColumns,
getColumnDefinitions,
getColumnDefinition,
parseRows,
} = exportsForTests;

requireContext();
Expand Down Expand Up @@ -529,3 +530,105 @@ theories(getColumnDefinition, [
out: 'B',
},
]);

const testRows = `
<viewdef>
<rows>
<row>
<cell type="label" labelFor="tt" label="test" />
</row>
<row>
<cell type="field" name=" stationFieldNumber " uiType="text" colSpan="4" align="right" id="tt" />
<cell type="field" name="collectingTrip.text1" uiType="checkbox" label="2" colSpan="1" align="right" />
</row>
<row>
</row>
<row>
<cell type="subview" id="dt" viewname="Collectors" name="collectors"/>
</row>
</rows>
</viewdef>`;

test('parseRows', async () => {
const viewDef = xml(testRows);
const rowsContainer = viewDef.children.rows[0];
const rawRows = rowsContainer?.children?.row ?? [];

await expect(parseRows(rawRows, tables.CollectingEvent)).resolves.toEqual([
[
{
align: 'right',
ariaLabel: undefined,
colSpan: 1,
fieldNames: undefined,
id: undefined,
labelForCellId: 'tt',
text: 'test',
title: undefined,
type: 'Label',
verticalAlign: 'center',
visible: true,
},
],
[
{
align: 'left',
ariaLabel: undefined,
colSpan: 2,
fieldDefinition: {
defaultValue: undefined,
isReadOnly: false,
max: undefined,
maxLength: undefined,
min: undefined,
minLength: undefined,
step: undefined,
type: 'Text',
},
fieldNames: ['stationFieldNumber'],
id: 'tt',
isRequired: false,
type: 'Field',
verticalAlign: 'center',
visible: true,
},
{
align: 'left',
ariaLabel: undefined,
colSpan: 1,
fieldDefinition: {
defaultValue: undefined,
isReadOnly: false,
label: '2',
printOnSave: false,
type: 'Checkbox',
},
fieldNames: ['collectingTrip', 'text1'],
id: undefined,
isRequired: false,
type: 'Field',
verticalAlign: 'center',
visible: true,
},
],
[],
[
{
align: 'left',
ariaLabel: undefined,
colSpan: 1,
fieldNames: ['collectors'],
formType: 'formTable',
icon: undefined,
id: 'dt',
isButton: false,
isCollapsed: false,
sortField: undefined,
type: 'SubView',
verticalAlign: 'stretch',
viewName: 'Collectors',
visible: true,
},
],
]);
});
Original file line number Diff line number Diff line change
Expand Up @@ -585,4 +585,5 @@ export const exportsForTests = {
parseFormTableColumns,
getColumnDefinitions,
getColumnDefinition,
parseRows,
};

0 comments on commit 131ad7b

Please sign in to comment.