forked from carbon-design-system/carbon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Visual Regression Tests for Checkbox (carbon-design-system#9324)
* test(checkbox): add e2e test, percy snapshot * test(checkbox): add checkbox skeleton to e2e snapshot * fix(checkbox): correct skeleton import path Co-authored-by: Andrea N. Cardona <[email protected]> Co-authored-by: Josefina Mancilla <[email protected]>
- Loading branch information
1 parent
6444576
commit a83021a
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
packages/react/src/components/Checkbox/Checkbox-test.e2e.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* Copyright IBM Corp. 2016, 2018 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import 'carbon-components/scss/components/checkbox/_checkbox.scss'; | ||
|
||
import React from 'react'; | ||
import { mount } from '@cypress/react'; | ||
import Checkbox from '../Checkbox'; | ||
import CheckboxSkeleton from '../Checkbox/Checkbox.Skeleton'; | ||
|
||
describe('Checkbox', () => { | ||
beforeEach(() => { | ||
mount( | ||
<fieldset className={`fieldset`}> | ||
<legend className={`label`}>Checkbox heading</legend> | ||
<Checkbox labelText={`Checkbox label 1`} id="checkbox-label-1" /> | ||
<Checkbox labelText={`Checkbox label 2`} id="checkbox-label-2" /> | ||
<CheckboxSkeleton /> | ||
</fieldset> | ||
); | ||
}); | ||
|
||
it('should render unselected', () => { | ||
cy.findByText(/Checkbox label 1/).should('be.visible'); | ||
cy.findByText(/Checkbox label 2/).should('be.visible'); | ||
|
||
// snapshots should always be taken _after_ an assertion that | ||
// a element/component should be visible. This is to ensure | ||
// the DOM has settled and the element has fully loaded. | ||
cy.percySnapshot(); | ||
}); | ||
|
||
it('should be selected and focused on click', () => { | ||
// must force the interaction because cypress detects the original | ||
// input hidden due to how we style the checkbox | ||
cy.findByLabelText('Checkbox label 1').click({ force: true }); | ||
cy.findByLabelText(/Checkbox label 1/) | ||
.should('be.visible') | ||
.and('have.focus') | ||
.and('be.checked'); | ||
|
||
cy.findByLabelText('Checkbox label 2').click({ force: true }); | ||
cy.findByLabelText(/Checkbox label 2/) | ||
.should('be.visible') | ||
.and('have.focus') | ||
.and('be.checked'); | ||
|
||
// snapshots should always be taken _after_ an assertion that | ||
// a element/component should be visible. This is to ensure | ||
// the DOM has settled and the element has fully loaded. | ||
cy.percySnapshot(); | ||
}); | ||
}); |