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:
parent
03565d1f78
commit
bcbb517828
1 changed files with 35 additions and 0 deletions
|
@ -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"`);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue