Tweak cypress tests

This commit is contained in:
Josh Johnson 2019-11-04 17:47:28 +00:00
parent 798fbdfaa8
commit 6100815f66
2 changed files with 22 additions and 20 deletions

View file

@ -963,36 +963,38 @@ describe('Choices - select one', () => {
});
});
describe('disabled-first-by-options', () => {
describe('disabling first choice via options', () => {
beforeEach(() => {
cy.get('[data-test-hook=disabled-first-choice-by-options]')
cy.get('[data-test-hook=disabled-first-choice-via-options]')
.find('.choices')
.click();
});
it('first choice is disabled', () => {
cy.get('[data-test-hook=disabled-first-choice-by-options]')
let disabledValue;
it('disables the first choice', () => {
cy.get('[data-test-hook=disabled-first-choice-via-options]')
.find('.choices__list--dropdown .choices__list')
.children()
.first()
.should('have.class', 'choices__item--disabled');
.should('have.class', 'choices__item--disabled')
.then($choice => {
disabledValue = $choice.val();
});
});
let selectValue;
it('first non-disabled choice is selected', () => {
cy.get('[data-test-hook=disabled-first-choice-by-options]')
.find('.choices__input.is-hidden')
.then($select => {
selectValue = $select.val();
it('selects the first enabled choice', () => {
cy.get('[data-test-hook=disabled-first-choice-via-options]')
.find('.choices__input[hidden]')
.then($option => {
expect($option.text().trim()).to.not.equal(disabledValue);
});
cy.get('[data-test-hook=disabled-first-choice-by-options]')
.find('.choices__list--dropdown .choices__list')
.children()
.eq(1)
cy.get('[data-test-hook=disabled-first-choice-via-options]')
.find('.choices__item.choices__item--selectable')
.first()
.should($choice => {
expect($choice.text().trim()).to.equal(selectValue);
expect($choice.text().trim()).to.not.equal(disabledValue);
});
});
});

View file

@ -95,14 +95,14 @@
name="choices-disabled-choice"
id="choices-disabled-choice"
>
<option value="Choice 1" disabled>Choice 1</option>
<option value="Choice 1">Choice 1</option>
<option value="Choice 2">Choice 2</option>
<option value="Choice 3">Choice 3</option>
<option value="Choice 4">Choice 4</option>
<option value="Choice 4" disabled>Choice 4</option>
</select>
</div>
<div data-test-hook="disabled-first-choice-by-options">
<div data-test-hook="disabled-first-choice-via-options">
<label for="choices-disabled-choice-via-options"
>Disabled first choice by options</label
>