Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: cleanup text-field unit tests covered by mixins tests #8715

Merged
merged 2 commits into from
Feb 21, 2025

Conversation

web-padawan
Copy link
Member

@web-padawan web-padawan commented Feb 21, 2025

Description

The following unit tests are now covered by mixins, and we have typings tests that ensure the text field does apply them:

  • autoselect - covered by InputControlMixin
  • clearButtonVisible - covered by ClearButtonMixin
  • binding (value) - covered by InputMixin
  • clear() method - covered by InputMixin

Also the property delegation logic was moved to mixins:

  • disabled property - covered by DelegateFocusMixin
  • autocorrect, autocomplete, autocapitalize - covered by InputFieldMixin
  • placeholder, readonly, required, title - covered by InputControlMixin

IMO having these tests only in @vaadin/text-field package is not necessary. In particular, they are not present in other field components that use same mixins e.g. @vaadin/number-field - in V14, this component was based on text-field but it's no longer the case.

Note: since we don't have JS API to test that the component uses certain mixins (see #2357), we have to rely on the typings tests, which is not ideal. However, this would only break the component if some mixins are changed in .js but not in .d.ts which would be an issue on its own. So IMO we can rely on typings tests for now.

Type of change

  • Test

});
});

describe('binding', () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All tests in this suite are covered here:

});
});

describe('has-value attribute', () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved tests for number and boolean to this suite, others are already covered:

});
});

describe(`methods`, () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both tests in this suite are covered here:

await assertAttrCanBeSet(prop, true);
await assertAttrCanBeSet(prop, false);
});
});
});

describe('clear button', () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the default value test to this suite, all the rest are already covered there:

@@ -159,74 +99,5 @@ describe('text-field', () => {
expect(textField.hasAttribute('focused')).to.be.true;
});
});

describe('autoselect', () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved two tests to this suite:

@web-padawan web-padawan force-pushed the test/restructure-text-field-tests branch from 8c3ee54 to 7750b0e Compare February 21, 2025 12:50
fire(input, 'input');
expect(textField.value).to.be.equal('foo');
it('should set ariaTarget property to the input element', () => {
expect(textField.ariaTarget).to.equal(textField.inputElement);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ariaTarget property was not covered at all (tests passed with it being removed).
I also added explicit tests for focusElement and stateTarget for consistency.

@web-padawan web-padawan requested a review from vursen February 21, 2025 12:54
Comment on lines -40 to -41
['disabled'].forEach((prop) => {
it(`should set boolean property ${prop}`, async () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Covered here:

it('should propagate disabled property to the input', () => {

});
});

['autocomplete', 'autocorrect', 'readonly', 'required'].forEach((prop) => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Covered here:


Comment on lines -58 to -64
['autocomplete'].forEach((prop) => {
it(`should set boolean attribute ${prop}`, async () => {
await assertAttrCanBeSet(prop, 'on');
});
});

['autocapitalize'].forEach((prop) => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Covered here:

@web-padawan web-padawan merged commit 560ad43 into main Feb 21, 2025
9 checks passed
@web-padawan web-padawan deleted the test/restructure-text-field-tests branch February 21, 2025 13:19
@vaadin-bot
Copy link
Collaborator

This ticket/PR has been released with Vaadin 24.7.0.alpha12 and is also targeting the upcoming stable 24.7.0 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants