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(() => { beforeEach(() => {
cy.get('[data-test-hook=disabled-first-choice-by-options]') cy.get('[data-test-hook=disabled-first-choice-via-options]')
.find('.choices') .find('.choices')
.click(); .click();
}); });
it('first choice is disabled', () => { let disabledValue;
cy.get('[data-test-hook=disabled-first-choice-by-options]')
it('disables the first choice', () => {
cy.get('[data-test-hook=disabled-first-choice-via-options]')
.find('.choices__list--dropdown .choices__list') .find('.choices__list--dropdown .choices__list')
.children() .children()
.first() .first()
.should('have.class', 'choices__item--disabled'); .should('have.class', 'choices__item--disabled')
.then($choice => {
disabledValue = $choice.val();
});
}); });
let selectValue; it('selects the first enabled choice', () => {
cy.get('[data-test-hook=disabled-first-choice-via-options]')
it('first non-disabled choice is selected', () => { .find('.choices__input[hidden]')
cy.get('[data-test-hook=disabled-first-choice-by-options]') .then($option => {
.find('.choices__input.is-hidden') expect($option.text().trim()).to.not.equal(disabledValue);
.then($select => {
selectValue = $select.val();
}); });
cy.get('[data-test-hook=disabled-first-choice-by-options]') cy.get('[data-test-hook=disabled-first-choice-via-options]')
.find('.choices__list--dropdown .choices__list') .find('.choices__item.choices__item--selectable')
.children() .first()
.eq(1)
.should($choice => { .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" name="choices-disabled-choice"
id="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 2">Choice 2</option>
<option value="Choice 3">Choice 3</option> <option value="Choice 3">Choice 3</option>
<option value="Choice 4">Choice 4</option> <option value="Choice 4" disabled>Choice 4</option>
</select> </select>
</div> </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" <label for="choices-disabled-choice-via-options"
>Disabled first choice by options</label >Disabled first choice by options</label
> >