Skip to content

Commit

Permalink
Merge pull request #947 from Onlineberatung/OB-Opt
Browse files Browse the repository at this point in the history
fix: flaky tests
  • Loading branch information
web-mi committed Jun 1, 2023
2 parents 4091c31 + 541d0a9 commit 9d7f34a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
8 changes: 6 additions & 2 deletions cypress/e2e/sessions.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,18 @@ describe('Sessions', () => {
cy.wait('@consultantSessions');

cy.get('[data-cy=session-list-item]').first().click();
// Could take some time because of slow editor load
cy.wait('@draftMessages', { timeout: 10000 });
cy.wait('@messages');
cy.wait('@sessionRooms');

cy.get('#iconH').click();
cy.get('#flyout').should('be.visible');
cy.get('#flyout a').first().click();
cy.wait('@agencyConsultants');

cy.get('#assignSelect').click();
cy.get('#react-select-2-option-0').click();
cy.get('.select__input__menu-list > div').first().click();
cy.get('.overlay').should('exist');
});

Expand Down Expand Up @@ -129,7 +132,7 @@ describe('Sessions', () => {

describe('Access Token expires while logged in', () => {
it('should logout if trying to paginate sessions', () => {
generateMultipleConsultantSessions(15);
generateMultipleConsultantSessions(16);

cy.fastLogin({
username: USER_CONSULTANT
Expand All @@ -139,6 +142,7 @@ describe('Sessions', () => {

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

cy.willReturn('consultantSessions', 401);
Expand Down
13 changes: 12 additions & 1 deletion src/api/apiGetAskerSessionList.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
import { endpoints } from '../resources/scripts/endpoints';
import { fetchData, FETCH_METHODS } from './fetchData';

let previousProm = null;

export const apiGetAskerSessionList = async (): Promise<any> => {
const url = endpoints.askerSessions;

return fetchData({
// ToDo: We are calling this endpoint on multiple places at the same time which makes the tests flaky
// This is a quick fix to prevent multiple calls to the same endpoint and should better be refactored
if (previousProm) {
return previousProm;
}

previousProm = fetchData({
url: url,
method: FETCH_METHODS.GET,
rcValidation: true
}).finally(() => {
previousProm = null;
});
return previousProm;
};
3 changes: 3 additions & 0 deletions src/api/fetchData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ export const fetchData = ({
} else if (error.name === 'AbortError') {
reqLog.finish(408);
reject(new Error(FETCH_ERRORS.TIMEOUT));
} else if (signal?.aborted) {
reqLog.finish(299);
reject(new Error(FETCH_ERRORS.ABORT));
} else {
reqLog.finish(520);
reject(error);
Expand Down
4 changes: 3 additions & 1 deletion src/components/app/NavigationBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,15 @@ export const NavigationBar = ({
setSessionId(sessionsData?.sessions?.[0]?.session?.id);
});
}
}, [dispatch, isConsultant]);

useEffect(() => {
if (tenant?.settings?.featureToolsEnabled && !isConsultant) {
userHasBudibaseTools(userData.userId).then((resp) =>
setHasTools(resp)
);
}
}, [dispatch, isConsultant, tenant, userData]);
}, [tenant, userData, isConsultant]);

const animateNavIconTimeoutRef = useRef(null);
useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
AUTHORITIES,
hasUserAuthority,
ListItemInterface,
SessionsDataContext,
UserDataContext
} from '../../../globalState';

Expand All @@ -15,11 +14,6 @@ export const useAskerHasAssignedConsultant = () => {
userData
);
const [hasAssignedConsultant, setAssignedConsultant] = useState(false);
const { sessions } = useContext(SessionsDataContext);
const hasConsultants = !!sessions
.filter((session) => session?.agency !== null)
.map((consultant) => consultant?.consultant)
.filter((el) => el != null).length;

useEffect(() => {
if (isAdviceSeeker) {
Expand All @@ -38,7 +32,7 @@ export const useAskerHasAssignedConsultant = () => {
);
});
}
}, [userData, isAdviceSeeker, hasConsultants]);
}, [isAdviceSeeker]);

return hasAssignedConsultant;
};

0 comments on commit 9d7f34a

Please sign in to comment.