Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ncovercash committed Oct 25, 2024
1 parent 69ccec7 commit 5ebc9fa
Showing 1 changed file with 47 additions and 15 deletions.
62 changes: 47 additions & 15 deletions src/QueryBuilder/ResultViewer/DynamicTable/DynamicTable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,30 @@ describe('DynamicTable component', () => {
labelAlias: 'Value',
property: 'value',
},
{
name: 'is_cool',
dataType: {
dataType: 'booleanType',
},
labelAlias: 'Is cool',
property: 'isCool',
},
{
name: 'is_not_cool',
dataType: {
dataType: 'booleanType',
},
labelAlias: 'Is not cool',
property: 'isNotCool',
},
{
name: 'is_empty_bool',
dataType: {
dataType: 'booleanType',
},
labelAlias: 'Empty bool column',
property: 'isEmptyBool',
},
];

it.each(['[]', undefined, null])(
Expand All @@ -55,8 +79,19 @@ describe('DynamicTable component', () => {
},
);

const values =
'[{"code": "STATE-MONOSER", "value": 100.0, "fundId": "bbd4a5e1-c9f3-44b9-bfdf-d184e04f0ba0", "encumbrance": "eb506834-6c70-4239-8d1a-6414a5b08010", "distributionType": "percentage"}]';
const values = `
[
{
"code": "STATE-MONOSER",
"value": 100.0,
"fundId": "bbd4a5e1-c9f3-44b9-bfdf-d184e04f0ba0",
"encumbrance": "eb506834-6c70-4239-8d1a-6414a5b08010",
"distributionType": "percentage",
"isCool": true,
"isNotCool": false,
"isEmptyBool": null
}
]`;

it('renders table with correct properties and values', () => {
const { getByText } = render(<DynamicTable properties={properties} values={values} />);
Expand All @@ -67,20 +102,17 @@ describe('DynamicTable component', () => {
expect(label).toBeInTheDocument();
});

const codeValue = getByText('STATE-MONOSER');

expect(codeValue).toBeInTheDocument();

const encumbranceValue = getByText('eb506834-6c70-4239-8d1a-6414a5b08010');

expect(encumbranceValue).toBeInTheDocument();

const fundIdValue = getByText('bbd4a5e1-c9f3-44b9-bfdf-d184e04f0ba0');

expect(fundIdValue).toBeInTheDocument();
expect(getByText('STATE-MONOSER')).toBeInTheDocument();
expect(getByText('eb506834-6c70-4239-8d1a-6414a5b08010')).toBeInTheDocument();
expect(getByText('bbd4a5e1-c9f3-44b9-bfdf-d184e04f0ba0')).toBeInTheDocument();
expect(getByText('100')).toBeInTheDocument();

const numberValue = getByText('100');
// will fail if multiple, to ensure multiple case works
const trueCell = getByText('ui-plugin-query-builder.options.true');
const falseCell = getByText('ui-plugin-query-builder.options.false');

expect(numberValue).toBeInTheDocument();
expect(trueCell).toBeInTheDocument();
expect(falseCell).toBeInTheDocument();
expect(trueCell.compareDocumentPosition(falseCell)).toBe(Node.DOCUMENT_POSITION_FOLLOWING);
});
});

0 comments on commit 5ebc9fa

Please sign in to comment.