Skip to content

Commit

Permalink
test: test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MekalaNagarajan-Centrica committed Nov 6, 2024
1 parent bff1d11 commit af3868d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
17 changes: 11 additions & 6 deletions packages/muon/tests/components/inputter/inputter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,13 @@ describe('Inputter', () => {

const validationMessage = shadowRoot.querySelector('.validation .message');
expect(validationMessage).to.not.be.null; // eslint-disable-line no-unused-expressions
expect(validationMessage.textContent.trim().replace(/\s\s+/g, ' ')).to.equal('input label Length must be between 8 and 20 characters.', 'validation message has correct value');
expect(validationMessage.textContent.trim().replace(/\s\s+/g, ' ')).to.equal('Length must be between 8 and 20 characters.', 'validation message has correct value');

const validationId = `${inputter._id}-validation`;
const validationLightDOM = inputter.querySelector(`#${validationId}`);
// eslint-disable-next-line no-unused-expressions
expect(validationLightDOM).to.be.ok;
expect(inputElement.getAttribute('aria-errormessage')).to.be.equal(validationId);
const validationIcon = shadowRoot.querySelector('.validation .icon');
expect(validationIcon).to.not.be.null; // eslint-disable-line no-unused-expressions
expect(validationIcon.name).to.equal('exclamation-circle', 'validation icon has correct value');
Expand Down Expand Up @@ -210,7 +215,7 @@ describe('Inputter', () => {

const validationMessage = shadowRoot.querySelector('.validation .message');
expect(validationMessage).to.not.be.null; // eslint-disable-line no-unused-expressions
expect(validationMessage.textContent.trim().replace(/\s\s+/g, ' ')).to.equal('input label Length must be between 8 and 20 characters.', 'validation message has correct value');
expect(validationMessage.textContent.trim().replace(/\s\s+/g, ' ')).to.equal('Length must be between 8 and 20 characters.', 'validation message has correct value');

const validationIcon = shadowRoot.querySelector('.validation .icon');
expect(validationIcon).to.not.be.null; // eslint-disable-line no-unused-expressions
Expand Down Expand Up @@ -251,7 +256,7 @@ describe('Inputter', () => {

const validationMessage = shadowRoot.querySelector('.validation .message');
expect(validationMessage).to.not.be.null; // eslint-disable-line no-unused-expressions
expect(validationMessage.textContent.trim().replace(/\s\s+/g, ' ')).to.equal('input label This field is required.', 'validation message has correct value');
expect(validationMessage.textContent.trim().replace(/\s\s+/g, ' ')).to.equal('This field is required.', 'validation message has correct value');

const validationIcon = shadowRoot.querySelector('.validation .icon');
expect(validationIcon).to.not.be.null; // eslint-disable-line no-unused-expressions
Expand Down Expand Up @@ -309,7 +314,7 @@ describe('Inputter', () => {

const validationMessage = shadowRoot.querySelector('.validation .message');
expect(validationMessage).to.not.be.null; // eslint-disable-line no-unused-expressions
expect(validationMessage.textContent.trim().replace(/\s\s+/g, ' ')).to.equal('input label This field is required.', 'validation message has correct value');
expect(validationMessage.textContent.trim().replace(/\s\s+/g, ' ')).to.equal('This field is required.', 'validation message has correct value');

const validationIcon = shadowRoot.querySelector('.validation .icon');
expect(validationIcon).to.not.be.null; // eslint-disable-line no-unused-expressions
Expand All @@ -319,7 +324,7 @@ describe('Inputter', () => {
await inputter.updateComplete;
expect(changeEventSpy.callCount).to.equal(3, '`change` event fired');
expect(changeEventSpy.lastCall.args[0].detail.value).to.equal('12-3', '`change` event has value `12-3`');
expect(validationMessage.textContent.trim().replace(/\s\s+/g, ' ')).to.equal('input label Length must be at least 4 characters.', 'validation message has correct value');
expect(validationMessage.textContent.trim().replace(/\s\s+/g, ' ')).to.equal('Length must be at least 4 characters.', 'validation message has correct value');

inputMask = shadowRoot.querySelector('.input-mask');
expect(inputMask.textContent).to.be.equal(' 0', '`input-mask` has correct value');
Expand Down Expand Up @@ -415,7 +420,7 @@ describe('Inputter', () => {
expect(validationMessage).to.not.be.null; // eslint-disable-line no-unused-expressions


Check warning on line 422 in packages/muon/tests/components/inputter/inputter.test.js

View workflow job for this annotation

GitHub Actions / lint

More than 1 blank line not allowed
expect(validationMessage.textContent?.trim().replace(/\s\s+/g, ' ')).to.equal('What is your heating source? This field is required.', 'validation message has correct value');
expect(validationMessage.textContent?.trim().replace(/\s\s+/g, ' ')).to.equal('This field is required.', 'validation message has correct value');

const validationIcon = shadowRoot.querySelector('.validation .icon');
expect(validationIcon).to.not.be.null; // eslint-disable-line no-unused-expressions
Expand Down
24 changes: 12 additions & 12 deletions packages/muon/tests/mixins/validation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe('form-element-validation', () => {
await formElement.updateComplete;
let validationMessage = shadowRoot.querySelector('.validation');
expect(validationMessage).to.not.be.null; // eslint-disable-line no-unused-expressions
expect(validationMessage.textContent.trim().replace(/\s\s+/g, ' ')).to.equal('input label This field is required.', 'validation message has correct value');
expect(validationMessage.textContent.trim().replace(/\s\s+/g, ' ')).to.equal('This field is required.', 'validation message has correct value');

await fillIn(inputElement, 'hello world');
expect(formElement.value).to.equal('hello world', '`value` property has value `hello world`');
Expand All @@ -113,7 +113,7 @@ describe('form-element-validation', () => {
await formElement.updateComplete;
validationMessage = shadowRoot.querySelector('.validation');
expect(validationMessage).to.not.be.null; // eslint-disable-line no-unused-expressions
expect(validationMessage.textContent.trim().replace(/\s\s+/g, ' ')).to.equal('input label Length must be between 5 and 10 characters.', 'validation message has correct value');
expect(validationMessage.textContent.trim().replace(/\s\s+/g, ' ')).to.equal('Length must be between 5 and 10 characters.', 'validation message has correct value');
});

it('text validation on input', async () => {
Expand Down Expand Up @@ -147,7 +147,7 @@ describe('form-element-validation', () => {
await formElement.updateComplete;
let validationMessage = shadowRoot.querySelector('.validation');
expect(validationMessage).to.not.be.null; // eslint-disable-line no-unused-expressions
expect(validationMessage.textContent.trim().replace(/\s\s+/g, ' ')).to.equal('input label This field is required.', 'validation message has correct value');
expect(validationMessage.textContent.trim().replace(/\s\s+/g, ' ')).to.equal('This field is required.', 'validation message has correct value');

await fillIn(inputElement, 'hello world', 'input');
expect(formElement.value).to.equal('hello world', '`value` property has value `hello world`');
Expand All @@ -157,7 +157,7 @@ describe('form-element-validation', () => {
await formElement.updateComplete;
validationMessage = shadowRoot.querySelector('.validation');
expect(validationMessage).to.not.be.null; // eslint-disable-line no-unused-expressions
expect(validationMessage.textContent.trim().replace(/\s\s+/g, ' ')).to.equal('input label Length must be between 5 and 10 characters.', 'validation message has correct value');
expect(validationMessage.textContent.trim().replace(/\s\s+/g, ' ')).to.equal('Length must be between 5 and 10 characters.', 'validation message has correct value');
});

it('text native validation', async () => {
Expand Down Expand Up @@ -191,7 +191,7 @@ describe('form-element-validation', () => {
await formElement.updateComplete;
let validationMessage = shadowRoot.querySelector('.validation');
expect(validationMessage).to.not.be.null; // eslint-disable-line no-unused-expressions
expect(validationMessage.textContent.trim().replace(/\s\s+/g, ' ').toLowerCase()).contains('input label this field is required', 'validation message has correct value');
expect(validationMessage.textContent.trim().replace(/\s\s+/g, ' ').toLowerCase()).contains('this field is required', 'validation message has correct value');

await fillIn(inputElement, 'test validation');
expect(formElement.value).to.equal('test validation', '`value` property has value `test validation`');
Expand Down Expand Up @@ -234,7 +234,7 @@ describe('form-element-validation', () => {
await formElement.updateComplete;
let validationMessage = shadowRoot.querySelector('.validation');
expect(validationMessage).to.not.be.null; // eslint-disable-line no-unused-expressions
expect(validationMessage.textContent.trim().replace(/\s\s+/g, ' ')).to.equal('input label This field is required.', 'validation message has correct value');
expect(validationMessage.textContent.trim().replace(/\s\s+/g, ' ')).to.equal('This field is required.', 'validation message has correct value');

await fillIn(inputElement, '56');
expect(formElement.value).to.equal('56', '`value` property has value `56`');
Expand All @@ -244,7 +244,7 @@ describe('form-element-validation', () => {
await formElement.updateComplete;
validationMessage = shadowRoot.querySelector('.validation');
expect(validationMessage).to.not.be.null; // eslint-disable-line no-unused-expressions
expect(validationMessage.textContent.trim().replace(/\s\s+/g, ' ')).to.equal('input label match the pattern.', 'validation message has correct value');
expect(validationMessage.textContent.trim().replace(/\s\s+/g, ' ')).to.equal('match the pattern.', 'validation message has correct value');

});

Expand Down Expand Up @@ -309,7 +309,7 @@ describe('form-element-validation', () => {
await formElement.updateComplete;
const validationMessage = shadowRoot.querySelector('.validation');
expect(validationMessage).to.not.be.null; // eslint-disable-line no-unused-expressions
expect(validationMessage.textContent.trim().replace(/\s\s+/g, ' ')).to.equal('What is your heating source? This field is required.', 'validation message has correct value');
expect(validationMessage.textContent.trim().replace(/\s\s+/g, ' ')).to.equal('This field is required.', 'validation message has correct value');
});

it('checkbox validation', async () => {
Expand Down Expand Up @@ -341,7 +341,7 @@ describe('form-element-validation', () => {
expect(changeEventSpy.callCount).to.equal(1, '`change` event fired');
const validationMessage = shadowRoot.querySelector('.validation');
expect(validationMessage).to.not.be.null; // eslint-disable-line no-unused-expressions
expect(validationMessage.textContent.trim().replace(/\s\s+/g, ' ')).to.equal('What is your heating source? This field is required.', 'validation message has correct value');
expect(validationMessage.textContent.trim().replace(/\s\s+/g, ' ')).to.equal('This field is required.', 'validation message has correct value');
});

it('select validation', async () => {
Expand Down Expand Up @@ -373,7 +373,7 @@ describe('form-element-validation', () => {
expect(changeEventSpy.callCount).to.equal(1, '`change` event fired');
const validationMessage = shadowRoot.querySelector('.validation');
expect(validationMessage).to.not.be.null; // eslint-disable-line no-unused-expressions
expect(validationMessage.textContent.trim().replace(/\s\s+/g, ' ')).to.equal('What is your heating source? This field is required.', 'validation message has correct value');
expect(validationMessage.textContent.trim().replace(/\s\s+/g, ' ')).to.equal('This field is required.', 'validation message has correct value');
});

it('date validation', async () => {
Expand Down Expand Up @@ -408,7 +408,7 @@ describe('form-element-validation', () => {

let validationMessage = shadowRoot.querySelector('.validation');
expect(validationMessage).to.not.be.null; // eslint-disable-line no-unused-expressions
expect(validationMessage.textContent.trim().replace(/\s\s+/g, ' ')).to.equal('input label This field is required.', 'validation message has correct value');
expect(validationMessage.textContent.trim().replace(/\s\s+/g, ' ')).to.equal('This field is required.', 'validation message has correct value');

await fillIn(inputElement, '10/11/2021');
await formElement.updateComplete;
Expand All @@ -418,6 +418,6 @@ describe('form-element-validation', () => {

validationMessage = shadowRoot.querySelector('.validation');
expect(validationMessage).to.not.be.null; // eslint-disable-line no-unused-expressions
expect(validationMessage.textContent.trim().replace(/\s\s+/g, ' ')).to.equal('input label Date must be on or after 11/11/2021.', 'validation message has correct value');
expect(validationMessage.textContent.trim().replace(/\s\s+/g, ' ')).to.equal('Date must be on or after 11/11/2021.', 'validation message has correct value');
});
});

0 comments on commit af3868d

Please sign in to comment.