test(form): Added test Field.astro to test for category validation prop (#217)

* test(form): Added test Field.astro to test for category validation prop

* test(form): Testing all categories instead of just one for better test coverage
This commit is contained in:
Lalit 2022-11-30 01:04:11 +05:30 committed by GitHub
parent 03565d1f78
commit bcbb517828
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -98,4 +98,39 @@ describe('Field.astro test', () => {
expect(actualResult).to.contain(expectedLabel); expect(actualResult).to.contain(expectedLabel);
expect(actualResult).to.contain(expectedAttribute); expect(actualResult).to.contain(expectedAttribute);
}); });
it('Should render correct validation attribute based on category prop', async () => {
// arrange
const categories = ['error', 'warn', 'info'];
const props = {
control: {
label: 'FAKE LABEL',
name: 'username',
validators: ['validator-required'],
errors: [
{
error: 'required',
category: 'error',
},
],
value: '',
},
showValidationHints: true,
};
// act
const results = await Promise.all(
categories.map(async (category) => {
props.control.errors = [{ error: 'required', category }];
component = await getComponentOutput('./components/Field.astro', props);
const actualResult = cleanString(component.html);
return actualResult;
})
);
// assert
categories.forEach((category, index) => {
expect(results[index]).to.contain(`data-validator-${category}="true"`);
});
});
}); });