Skip to content

Commit

Permalink
Merge pull request #7478 from GCTC-NTGC/7391-fix-bas-set-state-career…
Browse files Browse the repository at this point in the history
…-timeline

[Fix] Bad set state call in application career timeline
  • Loading branch information
esizer authored Aug 3, 2023
2 parents 362e374 + 6917c3b commit f220d80
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import { aliasMutation, aliasQuery } from "../../support/graphql-test-utils";

describe("Submit Application for IAP Workflow Tests", () => {
beforeEach(() => {
cy.intercept("POST", "/graphql", function (req) {
aliasQuery(req, "getMyExperiences");
});

cy.getSkills().then((allSkills) => {
cy.wrap([allSkills[0].id]).as("testSkillIds"); // take the first ID for testing
});
Expand Down Expand Up @@ -228,6 +232,7 @@ describe("Submit Application for IAP Workflow Tests", () => {
);
cy.findByRole("button", { name: /Save and go back/i }).click();
cy.expectToast(/Successfully added experience!/i);
cy.wait("@gqlgetMyExperiencesQuery");
// returned to main career timeline review page
cy.contains(/1 education and certificate experience/i)
.should("exist")
Expand Down
2 changes: 2 additions & 0 deletions apps/e2e/cypress/e2e/talentsearch/submit-application.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe("Submit Application Workflow Tests", () => {
aliasQuery(req, "GetApplication");
aliasQuery(req, "getApplicationData");
aliasQuery(req, "MyApplications");
aliasQuery(req, "getMyExperiences");

aliasMutation(req, "createApplication");
aliasMutation(req, "UpdateApplication");
Expand Down Expand Up @@ -248,6 +249,7 @@ describe("Submit Application Workflow Tests", () => {
cy.wait("@gqlCreateEducationExperienceMutation");
cy.expectToast(/Successfully added experience!/i);
// returned to main career timeline review page
cy.wait("@gqlgetMyExperiencesQuery");
cy.contains(/1 education and certificate experience/i)
.should("exist")
.and("be.visible");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ const ApplicationCareerTimelineEditPage = () => {
fetching: experienceFetching,
error: experienceError,
},
] = useGetMyExperiencesQuery();
] = useGetMyExperiencesQuery({
requestPolicy: "cache-first",
});

const application = applicationData?.poolCandidate;
const experience = experienceData?.me?.experiences?.find(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import ExperienceSortAndFilter, {
} from "~/components/ExperienceSortAndFilter/ExperienceSortAndFilter";
import { sortAndFilterExperiences } from "~/components/ExperienceSortAndFilter/sortAndFilterUtil";

import { OperationContext } from "urql";
import { ApplicationPageProps } from "../ApplicationApi";
import { useApplicationContext } from "../ApplicationContext";

Expand Down Expand Up @@ -432,6 +433,17 @@ export const ApplicationCareerTimeline = ({
);
};

const context: Partial<OperationContext> = {
additionalTypenames: [
"AwardExperience",
"CommunityExperience",
"EducationExperience",
"PersonalExperience",
"WorkExperience",
], // This lets urql know when to invalidate cache if request returns empty list. https://formidable.com/open-source/urql/docs/basics/document-caching/#document-cache-gotchas
requestPolicy: "cache-first",
};

const ApplicationCareerTimelinePage = () => {
const { applicationId } = useParams();
const [
Expand All @@ -452,7 +464,9 @@ const ApplicationCareerTimelinePage = () => {
fetching: experienceFetching,
error: experienceError,
},
] = useGetMyExperiencesQuery();
] = useGetMyExperiencesQuery({
context,
});

const application = applicationData?.poolCandidate;
const experiences = experienceData?.me?.experiences as ExperienceForDate[];
Expand Down

0 comments on commit f220d80

Please sign in to comment.