Skip to content

Commit

Permalink
fix a couple flaky tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveDarsa committed Mar 28, 2024
1 parent 3368759 commit f856d41
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 40 deletions.
2 changes: 2 additions & 0 deletions cypress/e2e/general/settings.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ describe('Settings page', () => {
cy.visit(`${Cypress.env('url')}/settings`);

settings.deleteSshKey(testData.ssh.name);

settings.doEmptySshCheck();
});
});
2 changes: 1 addition & 1 deletion cypress/e2e/general/sidebarNav.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('Environment sidebar navigation', () => {
cy.waitForNetworkIdle('@idle', 500);

context('From /facts to /overview', () => {
cy.getBySel('overview-tab').first().click();
cy.getBySel('overview-tab').click();

cy.location('pathname').should('equal', `${suffix}`);
});
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/organizations/groups.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Organization Groups page', () => {
});

it('Adds a member to a group', () => {
group.doAddMemberToGroup(testData.organizations.users.email);
group.doAddMemberToGroup(testData.organizations.users.email, testData.organizations.groups.newGroupName);
});

it('Deletes groups', () => {
Expand Down
18 changes: 13 additions & 5 deletions cypress/e2e/organizations/notifications.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,18 @@ describe('Org Notifications page', () => {
});

it('Deletes notifications', () => {
notifications.doDeleteNotification('webhook');
notifications.doDeleteNotification('email');
notifications.doDeleteNotification('teams');
notifications.doDeleteNotification('rocketChat');
notifications.doDeleteNotification('slack');
const {
webhook: { name: webhooknName },
email: { name: emailName },
teams: { name: teamsName },
rocketChat: { name: rocketChatName },
slack: { name: slackName },
} = testData.organizations.notifications;

notifications.doDeleteNotification(webhooknName);
notifications.doDeleteNotification(emailName);
notifications.doDeleteNotification(teamsName);
notifications.doDeleteNotification(rocketChatName);
notifications.doDeleteNotification(slackName);
});
});
19 changes: 14 additions & 5 deletions cypress/e2e/rbac/organizations/platformAndOrgOwnerJourney.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,15 @@ orgownerAndPlatformOwner.forEach(owner => {
it('Navigates to groups and creates', () => {
cy.waitForNetworkIdle('@idle', 500);

const group1 = testData.organizations.groups.newGroupName;
const group2 = testData.organizations.groups.newGroupName2;

cy.get('.groups').click();
cy.location('pathname').should('equal', '/organizations/lagoon-demo-organization/groups');

group.doAddGroup(testData.organizations.groups.newGroupName, testData.organizations.groups.newGroupName2);
group.doAddGroup(group1, group2);
registerIdleHandler('groupQuery');
group.doAddMemberToGroup(testData.organizations.users.email);
group.doAddMemberToGroup(testData.organizations.users.email, group1);
});

it('Navigates to projects and creates a new one', () => {
Expand Down Expand Up @@ -152,11 +155,17 @@ orgownerAndPlatformOwner.forEach(owner => {

cy.waitForNetworkIdle('@idle', 500);

notifications.doDeleteNotification('webhook');
const {
webhook: { name: webhooknName },
email: { name: emailName },
slack: { name: slackName },
} = testData.organizations.notifications;

notifications.doDeleteNotification(webhooknName);
cy.wait('@gqlremoveNotificationMutation'); // wait for a delete mutation instead
notifications.doDeleteNotification('email');
notifications.doDeleteNotification(emailName);
cy.wait('@gqlremoveNotificationMutation');
notifications.doDeleteNotification('slack');
notifications.doDeleteNotification(slackName);
});
});
});
20 changes: 11 additions & 9 deletions cypress/support/actions/organizations/GroupsAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class GroupAction {
groupRepo.getAddGroupSubmitBtn().click();

cy.wait(['@gqladdGroupToOrganizationMutation', '@gqlgetOrganizationQuery']);
cy.getBySel('table-row').first().should('contain', newGroup1);
cy.getBySel('table-row').should('contain', newGroup1);

cy.log('Add another');
cy.reload();
Expand All @@ -20,7 +20,7 @@ export default class GroupAction {

cy.wait(['@gqladdGroupToOrganizationMutation', '@gqlgetOrganizationQuery']);

cy.getBySel('table-row').eq(1).should('contain', newGroup2);
cy.getBySel('table-row').should('contain', newGroup2);
}

doFailedAddGroup(newGroup1: string, newGroup2: string) {
Expand All @@ -40,18 +40,19 @@ export default class GroupAction {
doGroupSearch(group1: string, group2: string) {
cy.log('First group');
groupRepo.getSearchBar().type(group1);
cy.getBySel('table-row').eq(0).should('contain', group1);
cy.getBySel('table-row').should('contain', group1);

cy.log('No search results');
groupRepo.getSearchBar().clear().type('does not exist');
cy.contains('No groups found').should('be.visible');

cy.log('Second group');
groupRepo.getSearchBar().clear().type(group2);
cy.getBySel('table-row').eq(0).should('contain', group2);
cy.getBySel('table-row').should('contain', group2);
}
doAddMemberToGroup(userEmail: string) {
groupRepo.getAddUserBtn('adduser').first().click();
doAddMemberToGroup(userEmail: string, groupToAddTo: string) {
groupRepo.getGroupRowSiblings(groupToAddTo).find('[data-cy="adduser"]').click();

cy.getBySel('orgUser-email-input').type(userEmail);

cy.get('.react-select__indicator').click({ force: true });
Expand All @@ -61,8 +62,9 @@ export default class GroupAction {
cy.wait(['@gqladdUserToGroupMutation', '@gqlgetOrganizationQuery']);
cy.waitForNetworkIdle('@groupQuery', 500);

cy.getBySel('memberCount')
.first()
groupRepo
.getGroupRowSiblings(groupToAddTo)
.find('[data-cy="memberCount"]')
.invoke('text')
.then(text => {
const trimmedText = text.trim();
Expand All @@ -83,7 +85,7 @@ export default class GroupAction {
if (text.includes('0')) {
cy.contains('No groups found').should('exist');
} else {
cy.getBySel('table-row').eq(0).should('not.contain', groupName);
cy.getBySel('table-row').should('not.contain', groupName);
}
});
}
Expand Down
14 changes: 10 additions & 4 deletions cypress/support/actions/organizations/NotificationsAction.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { testData } from 'cypress/fixtures/variables';
import NotificationsRepository from 'cypress/support/repositories/organizations/NotificationsRepository';

const notificationRepo = new NotificationsRepository();
Expand Down Expand Up @@ -97,7 +98,11 @@ export default class NotificationsAction {
}

doEditNotification() {
notificationRepo.getLast('link').first().click();
const {
slack: { name: slackName },
} = testData.organizations.notifications;

notificationRepo.getEditBtn(slackName).click();

cy.getBySel('notification-name').first().type('-edited', { force: true });
cy.getBySel('input-webhook').first().type('-edited', { force: true });
Expand All @@ -106,10 +111,11 @@ export default class NotificationsAction {

cy.wait(`@gqlUpdateNotificationSlackMutation`);

cy.getBySel('notification-row').should('include.text', '-edited');
cy.getBySel('notification-row').should('include.text', `${slackName}-edited`);
}
doDeleteNotification(notification: keyof typeof notifMap) {
notificationRepo.getLast('btn-red').first().click();
doDeleteNotification(notification: string) {
notificationRepo.getNotificationDelete(notification).click();

cy.getBySel('confirmDelete').click();

cy.getBySel('notification-row').should('not.have.text', notification);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ export default class GroupsRepository {
getAddGroupSubmitBtn() {
return this.getElement('createGroup');
}
getGroupRowSiblings(groupName: string) {
return this.getElement('table-row').contains(groupName).parent().siblings();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
export default class NotificationsRepository {
getNotificationRowParents(notification: string) {
return cy.getBySel('notification-row').contains(notification).parent().parent();
}
getAddNotification() {
return cy.getBySel('addNotification');
}

getLast(identifier: string) {
return cy.getBySel('notification-row').find(`.${identifier}`);
getEditBtn(notification: string) {
return this.getNotificationRowParents(notification).find('.link');
}
getNotificationDelete(notification: string) {
return this.getNotificationRowParents(notification).find('.btn-red');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export default class SettingsRepository {
return cy.getBySel('sshKey').parent().next();
}
getDeleteBtn() {
return cy.getBySel('deleteKey').first().get('button').first();
return cy.getBySel('deleteKey').getBySel('deleteBtn');
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
"babel-loader": "^9.1.2",
"babel-plugin-macros": "^3.1.0",
"chromatic": "^10.2.0",
"cypress": "13.6.1",
"cypress": "13.7.1",
"cypress-network-idle": "^1.14.2",
"eslint-plugin-storybook": "^0.6.15",
"faker": "^6.6.6",
Expand Down
1 change: 1 addition & 0 deletions src/components/SshKeys/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const SshKeys = ({ me: { id, email, sshKeys: keys }, loading }) => {
}
return (
<Button
testId="deleteBtn"
variant="red"
action={() =>
deleteSshKeyById({
Expand Down
19 changes: 9 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3807,7 +3807,7 @@
dependencies:
undici-types "~5.26.4"

"@types/node@^18.0.0", "@types/node@^18.17.5":
"@types/node@^18.0.0":
version "18.19.21"
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.19.21.tgz#f4ca1ac8ffb05ee4b89163c2d6fac9a1a59ee149"
integrity sha512-2Q2NeB6BmiTFQi4DHBzncSoq/cJMLDdhPaAoJFnFCyD9a8VPZRf7a1GAwp1Edb7ROaZc5Jz/tnZyL6EsWMRaqw==
Expand Down Expand Up @@ -5387,7 +5387,7 @@ buffer-xor@^1.0.3:
resolved "https://registry.yarnpkg.com/buffer-xor/-/buffer-xor-1.0.3.tgz#26e61ed1422fb70dd42e6e36729ed51d855fe8d9"
integrity sha512-571s0T7nZWK6vB67HI5dyUF7wXiNcfaPPPTl6zYCNApANjIvYJTg7hlud/+cJpdAhS7dVzqMLmfhfHR3rAcOjQ==

buffer@^5.5.0, buffer@^5.6.0:
buffer@^5.5.0, buffer@^5.7.1:
version "5.7.1"
resolved "https://registry.yarnpkg.com/buffer/-/buffer-5.7.1.tgz#ba62e7c13133053582197160851a8f648e99eed0"
integrity sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==
Expand Down Expand Up @@ -6163,20 +6163,19 @@ cypress-real-events@^1.10.3:
resolved "https://registry.yarnpkg.com/cypress-real-events/-/cypress-real-events-1.12.0.tgz#ffeb2b23686ba5b16ac91dd9bc3b6785d36d38d3"
integrity sha512-oiy+4kGKkzc2PT36k3GGQqkGxNiVypheWjMtfyi89iIk6bYmTzeqxapaLHS3pnhZOX1IEbTDUVxh8T4Nhs1tyQ==

cypress@13.6.1:
version "13.6.1"
resolved "https://registry.yarnpkg.com/cypress/-/cypress-13.6.1.tgz#c5f714f08551666ed3ac1fa95718eabb23a416df"
integrity sha512-k1Wl5PQcA/4UoTffYKKaxA0FJKwg8yenYNYRzLt11CUR0Kln+h7Udne6mdU1cUIdXBDTVZWtmiUjzqGs7/pEpw==
cypress@13.7.1:
version "13.7.1"
resolved "https://registry.yarnpkg.com/cypress/-/cypress-13.7.1.tgz#d1208eb04efd46ef52a30480a5da71a03373261a"
integrity sha512-4u/rpFNxOFCoFX/Z5h+uwlkBO4mWzAjveURi3vqdSu56HPvVdyGTxGw4XKGWt399Y1JwIn9E1L9uMXQpc0o55w==
dependencies:
"@cypress/request" "^3.0.0"
"@cypress/xvfb" "^1.2.4"
"@types/node" "^18.17.5"
"@types/sinonjs__fake-timers" "8.1.1"
"@types/sizzle" "^2.3.2"
arch "^2.2.0"
blob-util "^2.0.2"
bluebird "^3.7.2"
buffer "^5.6.0"
buffer "^5.7.1"
cachedir "^2.3.0"
chalk "^4.1.0"
check-more-types "^2.24.0"
Expand All @@ -6194,7 +6193,7 @@ cypress@13.6.1:
figures "^3.2.0"
fs-extra "^9.1.0"
getos "^3.2.1"
is-ci "^3.0.0"
is-ci "^3.0.1"
is-installed-globally "~0.4.0"
lazy-ass "^1.6.0"
listr2 "^3.8.3"
Expand Down Expand Up @@ -8923,7 +8922,7 @@ is-callable@^1.1.3, is-callable@^1.1.4, is-callable@^1.2.7:
resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.2.7.tgz#3bc2a85ea742d9e36205dcacdd72ca1fdc51b055"
integrity sha512-1BC0BVFhS/p0qtw6enp8e+8OD0UrK0oFLztSjNzhcKA3WDuJxxAPXzPuPtKkjEY9UUoEWlX/8fgKeu2S8i9JTA==

is-ci@^3.0.0:
is-ci@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/is-ci/-/is-ci-3.0.1.tgz#db6ecbed1bd659c43dac0f45661e7674103d1867"
integrity sha512-ZYvCgrefwqoQ6yTyYUbQu64HsITZ3NfKX1lzaEYdkTDcfKzzCI/wthRRYKkdjHKFVgNiXKAKm65Zo1pk2as/QQ==
Expand Down

0 comments on commit f856d41

Please sign in to comment.