Skip to content

Commit

Permalink
fix: flaky tests
Browse files Browse the repository at this point in the history
  • Loading branch information
web-mi committed Jun 5, 2023
1 parent ee78f24 commit b1874bd
Show file tree
Hide file tree
Showing 8 changed files with 250 additions and 233 deletions.
403 changes: 207 additions & 196 deletions cypress/e2e/appointments.cy.ts

Large diffs are not rendered by default.

12 changes: 0 additions & 12 deletions cypress/e2e/messages.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ describe('Messages', () => {
});

cy.fastLogin();
cy.wait('@consultingTypeServiceBaseBasic');

cy.get('[data-cy=session-list-item]').click();
cy.wait('@messages');
Expand Down Expand Up @@ -71,7 +70,6 @@ describe('Messages', () => {
});

cy.fastLogin();
cy.wait('@consultingTypeServiceBaseBasic');

cy.get('[data-cy=session-list-item]').click();
cy.wait('@messages');
Expand All @@ -91,7 +89,6 @@ describe('Messages', () => {
describe('Initially loading the app', () => {
it('should not animate the envelope and no dot visible', () => {
cy.fastLogin();
cy.wait('@consultingTypeServiceBaseBasic');

cy.get('.navigation__item__count--active').should(
'not.exist'
Expand All @@ -106,7 +103,6 @@ describe('Messages', () => {
describe('New message from Live Service', () => {
it.skip('should animate the envelope and initial dot', () => {
cy.fastLogin();
cy.wait('@consultingTypeServiceBaseBasic');

cy.get('.cy-socket-connected-stomp');
cy.waitForSubscriptions(['/user/events']);
Expand All @@ -129,7 +125,6 @@ describe('Messages', () => {
describe('New message from Live Service', () => {
it.skip('should animate the envelope and initial dot', () => {
cy.fastLogin();
cy.wait('@consultingTypeServiceBaseBasic');
cy.get('.cy-socket-connected-stomp');
cy.waitForSubscriptions(['/user/events']);

Expand All @@ -152,7 +147,6 @@ describe('Messages', () => {
// ToDo: Test currenlty skipped because its not working like the test tries
it.skip('should animate envelope and initial dot and remove dot after message was read', () => {
cy.fastLogin();
cy.wait('@consultingTypeServiceBaseBasic');
cy.get('.cy-socket-connected-stomp');

cy.get('.sessionsListItem').first().click({
Expand Down Expand Up @@ -197,7 +191,6 @@ describe('Messages', () => {
it.skip('should animate the envelope and initial dot', () => {
cy.askerSession();
cy.fastLogin();
cy.wait('@consultingTypeServiceBaseBasic');
cy.get('.cy-socket-connected-stomp');

cy.get('.navigation__item__count--active').should(
Expand Down Expand Up @@ -235,7 +228,6 @@ describe('Messages', () => {
cy.askerSession({ session: { messagesRead: false } }, 0);

cy.fastLogin();
cy.wait('@consultingTypeServiceBaseBasic');

cy.get('.navigation__item__count--active').should('exist');
cy.get('.navigation__item__count--initial').should('exist');
Expand All @@ -251,7 +243,6 @@ describe('Messages', () => {
);

cy.fastLogin();
cy.wait('@consultingTypeServiceBaseBasic');
cy.get('.cy-socket-connected-stomp');
cy.waitForSubscriptions(['/user/events']);

Expand All @@ -278,7 +269,6 @@ describe('Messages', () => {
);

cy.fastLogin();
cy.wait('@consultingTypeServiceBaseBasic');
cy.get('.cy-socket-connected-stomp');
cy.waitForSubscriptions(['/user/events']);

Expand All @@ -302,7 +292,6 @@ describe('Messages', () => {
cy.askerSession({ session: { messagesRead: false } });

cy.fastLogin();
cy.wait('@consultingTypeServiceBaseBasic');
cy.get('.cy-socket-connected-stomp');
cy.waitForSubscriptions(['/user/events']);

Expand Down Expand Up @@ -340,7 +329,6 @@ describe('Messages', () => {
cy.askerSession({ session: { messagesRead: false } });

cy.fastLogin();
cy.wait('@consultingTypeServiceBaseBasic');
cy.get('.cy-socket-connected-stomp');
cy.waitForSubscriptions(['/user/events']);

Expand Down
2 changes: 0 additions & 2 deletions cypress/e2e/profile.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,6 @@ describe('profile', () => {
});

it('deactivate and activate email notification consultant', () => {
cy.wait('@consultingTypeServiceBaseBasic');

cy.contains('Profil').should('exist').click();
cy.contains('Einstellungen').should('exist').click();
cy.contains('E-Mail-Benachrichtigungen');
Expand Down
3 changes: 0 additions & 3 deletions cypress/e2e/release-notes.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ describe('release-note', () => {
cy.fastLogin({
username: USER_CONSULTANT
});
cy.wait('@consultingTypeServiceBaseBasic');
cy.wait('@releases');
cy.wait('@releases_markup');

Expand Down Expand Up @@ -89,7 +88,6 @@ describe('release-note', () => {
cy.fastLogin({
username: USER_CONSULTANT
});
cy.wait('@consultingTypeServiceBaseBasic');
cy.wait('@releases');
cy.wait('@releases_markup');

Expand All @@ -110,7 +108,6 @@ describe('release-note', () => {
cy.fastLogin({
username: USER_CONSULTANT
});
cy.wait('@consultingTypeServiceBaseBasic');

cy.get('.releaseNote').should('not.exist');
});
Expand Down
17 changes: 6 additions & 11 deletions cypress/e2e/sessions.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ describe('Sessions', () => {
cy.fastLogin({
username: USER_CONSULTANT
});
cy.wait('@consultingTypeServiceBaseBasic');

cy.get('a[href="/sessions/consultant/sessionView"]').click();
cy.get('.sessionsListItem').should('exist');
Expand Down Expand Up @@ -62,7 +61,6 @@ describe('Sessions', () => {
cy.fastLogin({
username: USER_CONSULTANT
});
cy.wait('@consultingTypeServiceBaseBasic');

cy.get('a[href="/sessions/consultant/sessionView"]').click();
cy.get('.sessionsListItem').should('have.length', 6);
Expand All @@ -74,7 +72,6 @@ describe('Sessions', () => {
cy.fastLogin({
username: USER_CONSULTANT
});
cy.wait('@consultingTypeServiceBaseBasic');

cy.get('a[href="/sessions/consultant/sessionView"]').click();
cy.wait('@consultantSessions');
Expand Down Expand Up @@ -103,7 +100,6 @@ describe('Sessions', () => {
cy.fastLogin({
username: USER_CONSULTANT
});
cy.wait('@consultingTypeServiceBaseBasic');

cy.get('a[href="/sessions/consultant/sessionView"]').click();
cy.get('.sessionsListItem').should('exist');
Expand Down Expand Up @@ -138,14 +134,17 @@ describe('Sessions', () => {
username: USER_CONSULTANT
});
cy.wait('@rcSettingsPublic');
cy.wait('@consultingTypeServiceBaseBasic');

cy.get('a[href="/sessions/consultant/sessionView"]').click();
cy.wait('@consultantSessions');
cy.wait('@consultantSessions')
.its('response.statusCode')
.should('eq', 200);
cy.get('.sessionsListItem.skeleton').should('not.exist');
cy.get('.sessionsListItem').should('exist');

cy.willReturn('consultantSessions', 401);
cy.willReturn('consultantSessions', {
statusCode: 401
});

cy.get('.sessionsList__scrollContainer').scrollTo('bottom');
cy.wait('@consultantSessions');
Expand All @@ -158,14 +157,12 @@ describe('Sessions', () => {
it('should list my sessions', () => {
generateMultipleAskerSessions(3);
cy.fastLogin();
cy.wait('@consultingTypeServiceBaseBasic');

cy.get('.sessionsListItem').should('have.length', 4);
});

it('should show a header with headline', () => {
cy.fastLogin();
cy.wait('@consultingTypeServiceBaseBasic');
cy.get('[data-cy=session-list-header]').should('exist');
cy.get('[data-cy=session-list-headline]').contains(
'Meine Beratungen'
Expand All @@ -179,7 +176,6 @@ describe('Sessions', () => {
MAX_ITEMS_TO_SHOW_WELCOME_ILLUSTRATION - 1
);
cy.fastLogin();
cy.wait('@consultingTypeServiceBaseBasic');

cy.get('[data-cy=session-list-welcome-illustration]').should(
'exist'
Expand All @@ -191,7 +187,6 @@ describe('Sessions', () => {
MAX_ITEMS_TO_SHOW_WELCOME_ILLUSTRATION
);
cy.fastLogin();
cy.wait('@consultingTypeServiceBaseBasic');

cy.get('[data-cy=session-list-welcome-illustration]').should(
'not.exist'
Expand Down
6 changes: 5 additions & 1 deletion cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ declare global {
): Chainable<Element>;
addMessage(props?: { [key: string]: any }, index?: number);
mockApi(): Chainable<Element>;
willReturn(name: string, data: any): Chainable<Element>;
willReturn(
name: string,
data: any,
extend?: boolean
): Chainable<Element>;
emitDirectMessage(index?: number): Chainable<Element>;
emitVideoCallRequest(): Chainable<Element>;
waitForSubscriptions(events: string[]): Chainable<Element>;
Expand Down
36 changes: 30 additions & 6 deletions cypress/support/commands/mockApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,15 @@ const defaultReturns = {
agencyConsultantsLanguages: ['de']
};

Cypress.Commands.add('willReturn', (name: string, data: any) => {
overrides[name] = data;
});
Cypress.Commands.add(
'willReturn',
(name: string, data: any, extend?: boolean) => {
overrides[name] = {
...(extend ? overrides[name] : {}),
...data
};
}
);

let username = null;

Expand Down Expand Up @@ -207,9 +213,11 @@ Cypress.Commands.add('mockApi', () => {
req.reply('{}');
}).as('sessionRead');

cy.intercept('GET', `${endpoints.consultantEnquiriesBase}*`, {}).as(
'consultantEnquiriesBase'
);
cy.intercept(
'GET',
`${endpoints.consultantEnquiriesBase}*`,
JSON.stringify({})
).as('consultantEnquiriesBase');

cy.intercept('POST', endpoints.keycloakLogout, {}).as('authLogout');

Expand Down Expand Up @@ -245,6 +253,12 @@ Cypress.Commands.add('mockApi', () => {
'apiLogout'
);

cy.intercept(
'GET',
`${endpoints.rc.users.getStatus}*`,
JSON.stringify({})
).as('rcUsersGetStatus');

cy.intercept(
`${endpoints.liveservice}/**/*`,
JSON.stringify({
Expand Down Expand Up @@ -438,6 +452,11 @@ Cypress.Commands.add(
) => {
username = args.username || USER_ASKER;

window.sessionStorage.removeItem('public_key');
window.sessionStorage.removeItem('private_key');
cy.clearCookie('lang');
cy.willReturn('userData', { preferredLanguage: null }, true);

cy.fixture('api.v1.login').then((res) => {
if (res.data.authToken) {
cy.setCookie('rc_token', res.data.authToken);
Expand Down Expand Up @@ -466,10 +485,15 @@ Cypress.Commands.add(

cy.visit('/app');
cy.wait('@usersData');
cy.wait('@settings');
cy.wait('@consultingTypeServiceBaseBasic');
cy.wait('@fetchMyKeys');
if (username === USER_ASKER) {
cy.wait('@askerSessions');
} else {
cy.wait('@consultantEnquiriesBase');
}
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(1000);
}
);
4 changes: 2 additions & 2 deletions src/globalState/provider/SessionsDataProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function reducer(
case UPDATE_SESSIONS: {
const { sessions } = action;
const newSessions = [...state.sessions];
sessions.forEach((s) => {
(sessions ?? []).forEach((s) => {
const newChatItem = getChatItemForSession(s);
const index = newSessions.findIndex((s) => {
const chatItem = getChatItemForSession(s);
Expand All @@ -90,7 +90,7 @@ function reducer(
case REMOVE_SESSIONS: {
const { ids } = action;
const newSessions = [...state.sessions];
ids.forEach((id) => {
(ids ?? []).forEach((id) => {
const index = newSessions.findIndex((s) => {
const chatItem = getChatItemForSession(s);
return chatItem.id === id || chatItem.groupId === id;
Expand Down

0 comments on commit b1874bd

Please sign in to comment.