From bcbb517828d268ca199105212f33ef8736edb056 Mon Sep 17 00:00:00 2001 From: Lalit Date: Wed, 30 Nov 2022 01:04:11 +0530 Subject: [PATCH] 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 --- packages/form/test/Field.astro.test.ts | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/packages/form/test/Field.astro.test.ts b/packages/form/test/Field.astro.test.ts index 165f036..79a9be9 100644 --- a/packages/form/test/Field.astro.test.ts +++ b/packages/form/test/Field.astro.test.ts @@ -98,4 +98,39 @@ describe('Field.astro test', () => { expect(actualResult).to.contain(expectedLabel); 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"`); + }); + }); });