Skip to content

Commit

Permalink
can pull leftHomePage data from url
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Shiel committed Nov 21, 2024
1 parent ce14e91 commit fe75fcd
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 3 deletions.
2 changes: 1 addition & 1 deletion client/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ clean:

.PHONY: develop
develop: .env.development node_modules/gatsby
npx gatsby develop -p 80
npx gatsby develop -p 8000

.PHONY: format
format:
Expand Down
7 changes: 6 additions & 1 deletion client/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import {
EMAIL_URL_PARAM_KEY,
EVENTS_KEY,
LS_EMAIL_KEY,
LS_LEFT_HOME_PAGE,
LS_USER_ID_KEY,
LS_X_API_EMAIL_KEY,
POST_SURVEY_TIME_KEY,
Expand Down Expand Up @@ -429,6 +430,11 @@ function IndexPage(props: {
]);

useEffect(() => {
const leftHomePageData = getParamURL(LS_LEFT_HOME_PAGE);
if (leftHomePageData) {
setLocalStorage(LS_LEFT_HOME_PAGE, leftHomePageData);
removeQueryParam(LS_LEFT_HOME_PAGE);
}
const chatSessionId = uuid();
dispatch(setChatSessionId(chatSessionId));

Expand Down Expand Up @@ -485,7 +491,6 @@ function IndexPage(props: {
) {
return;
}

const findMentor = async () => {
// check local store=
if (!mentor) {
Expand Down
2 changes: 1 addition & 1 deletion cypress/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ export default defineConfig({
setupNodeEvents(on, config) {
return require("./cypress/plugins/index.js")(on, config);
},
baseUrl: "http://localhost:80/",
baseUrl: "http://localhost:8000/",
},
});
24 changes: 24 additions & 0 deletions cypress/cypress/e2e/url-params.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,28 @@ describe("Display Mentor Grid", () => {
);
cy.get("[data-cy=username-modal-container]").should("not.exist");
});

it("leftHomePage data is pulled from url params", () => {
mockDefaultSetup(cy, {
config: {
displayGuestPrompt: false,
},
});
cy.visit(
`/?mentor=carlos&leftHomePage=${encodeURIComponent(
JSON.stringify({
targetMentors: ["carlos"],
time: new Date().toISOString(),
})
)}`
);
cy.wait(1000);
cy.window().then((win) => {
const leftHomePageData = JSON.parse(
win.localStorage.getItem("leftHomePage")
);
console.log("leftHomePageData", leftHomePageData);
cy.wrap(leftHomePageData.targetMentors).should("deep.equal", ["carlos"]);
});
});
});
11 changes: 11 additions & 0 deletions cypress/cypress/support/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,3 +378,14 @@ export function updateLocalStorageUserData(
JSON.stringify({ ...startingData, ...updatedObject })
);
}

export function appendHomePageData(targetMentors: string[], url: string) {
const time = new Date().toISOString();
const data = {
targetMentors,
time,
};
const urlParams = new URLSearchParams(url);
urlParams.set("leftHomePage", JSON.stringify(data));
return `${url}?${urlParams.toString()}`;
}

0 comments on commit fe75fcd

Please sign in to comment.