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: extract validation tests, improve test coverage #4093

Merged
merged 4 commits into from
Jun 27, 2022

Conversation

vursen
Copy link
Contributor

@vursen vursen commented Jun 25, 2022

Description

  • Extracted the number-field validation tests into a separate file for the sake of better readability.
  • Added more unit tests related to validation to improve test coverage in case of future refactorings.

A preparation for #4095

Type of change

  • Internal

Checklist

  • I have read the contribution guide: https://vaadin.com/docs-beta/latest/guide/contributing/overview/
  • I have added a description following the guideline.
  • The issue is created in the corresponding repository and I have referenced it.
  • I have added tests to ensure my change is effective and works as intended.
  • New and existing tests are passing locally with my change.
  • I have performed self-review and corrected misspellings.

@vursen vursen force-pushed the test/number-field/extract-validation-tests branch 3 times, most recently from e289f05 to 561f905 Compare June 25, 2022 20:15
@vursen vursen force-pushed the test/number-field/extract-validation-tests branch from 561f905 to 5c992bf Compare June 25, 2022 20:22
@vursen vursen changed the title test: extract validation tests test: extract validation tests, improve test coverage Jun 25, 2022
Comment on lines 15 to 19
it('should pass validation when the field by default', () => {
expect(field.checkValidity()).to.be.true;
expect(field.validate()).to.be.true;
expect(field.invalid).to.be.false;
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note: This is a new test.

Comment on lines +21 to +26
it('should not pass validation when the field is required and has no value', () => {
field.required = true;
expect(field.checkValidity()).to.be.false;
expect(field.validate()).to.be.false;
expect(field.invalid).to.be.true;
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note: This is a new test.

Comment on lines +28 to +34
it('should pass validation when the field is required and has a valid value', () => {
field.required = true;
field.value = '1';
expect(field.checkValidity()).to.be.true;
expect(field.validate()).to.be.true;
expect(field.invalid).to.be.false;
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note: This is a new test.

Comment on lines +210 to +217
it('should update "invalid" state when "required" is removed', () => {
field.required = true;
field.validate();
expect(field.invalid).to.be.true;

field.required = false;
expect(field.invalid).to.be.false;
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note: This is a new test.

Comment on lines +250 to +258
it('should not update "invalid" when "step" is removed but the field is still required', () => {
field.required = true;
field.step = 2;
field.validate();
expect(field.invalid).to.be.true;

field.step = '';
expect(field.invalid).to.be.true;
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note: This is a new test.

@vursen vursen requested a review from web-padawan June 27, 2022 07:58
vursen and others added 2 commits June 27, 2022 11:04
@sonarcloud
Copy link

sonarcloud bot commented Jun 27, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@web-padawan web-padawan merged commit 63348c9 into master Jun 27, 2022
@web-padawan web-padawan deleted the test/number-field/extract-validation-tests branch June 27, 2022 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants