Skip to content

Commit

Permalink
test: Fix flaky Cypress popup specification (#1837)
Browse files Browse the repository at this point in the history
Fixes flaky Cypress popup specification

[category:Test]
  • Loading branch information
NicholasBoll authored Oct 10, 2022
1 parent 4e6efc0 commit 97f4886
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Optional breaking changes message. If your PR includes breaking changes. It is e
<!-- Provide a bit of context about what this PR does. Add any additional checklist items you'd like the reviewer to check -->

- [ ] PR title is short and descriptive
- [ ] PR summary describes the change (Fixes/Resovles linked correctly)
- [ ] PR summary describes the change (Fixes/Resolves linked correctly)
- [ ] PR Release Notes describes additional information useful to call out in a release message or removed if not applicable
- [ ] Breaking Changes provides useful information to upgrade to this code or removed if not applicable

Expand Down
12 changes: 8 additions & 4 deletions cypress/integration/Popup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,12 +393,14 @@ describe('Popup', () => {
});
});

context('given the [Testing/React/Popups/Popup, MixedPopupTypes] story is rendered', () => {
context('given the [Testing/React/Popups/Popup, ReturnFocusTest] story is rendered', () => {
beforeEach(() => {
h.stories.load('Testing/React/Popups/Popup', 'ReturnFocusTest');
});

context('when the "Open Popup" is clicked', () => {
// We disable the default scroll behavior so we can tightly control how these specs scroll. This
// means we'll have to manually add `scrollIntoView` to get Cypress to scroll only where we want
context('when the "Open Popup" is clicked', {scrollBehavior: false}, () => {
beforeEach(() => {
cy.findByRole('button', {name: 'Open Popup'})
.scrollIntoView()
Expand All @@ -410,14 +412,16 @@ describe('Popup', () => {
cy.get('body').click('bottom');
});

it('should focus the "Open Popup" button', {scrollBehavior: false}, () => {
it('should focus the "Open Popup" button', () => {
cy.findByRole('button', {name: 'Open Popup'}).should('have.focus');
});
});

context('when the user clicks the input', () => {
beforeEach(() => {
cy.findByRole('textbox', {name: 'Name'}).click();
cy.findByRole('textbox', {name: 'Name'})
.scrollIntoView()
.click();
});

it('should not focus the "Open Popup" button', () => {
Expand Down
10 changes: 8 additions & 2 deletions modules/docs/utils/get-specifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,23 @@ function getSpecifications() {
const after = noop;
const afterEach = noop;

const describe = (name, cb) => {
const describe = (name, optionsOrCb, cb) => {
const childrenBefore = children;
const obj = {};
obj.type = 'describe';
obj.name = name;
obj.children = [];
children.push(obj);
children = obj.children;
cb();
if (typeof optionsOrCb === 'function') {
optionsOrCb();
} else if (typeof optionsOrCb === 'function') {
cb();
}
children = childrenBefore;
};
describe.skip = noop;
describe.only = noop;
const context = describe;

const it = name => {
Expand All @@ -45,6 +50,7 @@ function getSpecifications() {
children.push(obj);
};
it.skip = noop;
it.only = noop;

// eslint-disable-next-line no-eval
eval(contents);
Expand Down

0 comments on commit 97f4886

Please sign in to comment.