-
Notifications
You must be signed in to change notification settings - Fork 4
86b82fa34 - feat: add url fragment linking to tabs on edit sponsor page #751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
45342d4
4893cb6
b73855b
e5e4cec
f805edb
c2bb0ef
e4fc3fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,198 @@ | ||||||||||||||||||||||||||||||||||
| import React from "react"; | ||||||||||||||||||||||||||||||||||
| import userEvent from "@testing-library/user-event"; | ||||||||||||||||||||||||||||||||||
| import { act, screen } from "@testing-library/react"; | ||||||||||||||||||||||||||||||||||
| import EditSponsorPage, { | ||||||||||||||||||||||||||||||||||
| getFragmentFromValue, | ||||||||||||||||||||||||||||||||||
| getTabFromUrlFragment | ||||||||||||||||||||||||||||||||||
| } from "../edit-sponsor-page"; | ||||||||||||||||||||||||||||||||||
| import { renderWithRedux } from "../../../utils/test-utils"; | ||||||||||||||||||||||||||||||||||
| import { DEFAULT_STATE as currentSponsorDefaultState } from "../../../reducers/sponsors/sponsor-reducer"; | ||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||
| DEFAULT_ENTITY as defaultSummitEntity, | ||||||||||||||||||||||||||||||||||
| DEFAULT_STATE as currentSummitDefaultState | ||||||||||||||||||||||||||||||||||
| } from "../../../reducers/summits/current-summit-reducer"; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| global.window = { location: { pathname: "/sponsor-forms/items" } }; | ||||||||||||||||||||||||||||||||||
| jest.mock( | ||||||||||||||||||||||||||||||||||
| "../sponsor-forms-tab/components/manage-items/sponsor-forms-manage-items.js" | ||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||
| jest.mock("../sponsor-users-list-per-sponsor/index.js"); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| describe("EditSponsorPage", () => { | ||||||||||||||||||||||||||||||||||
| describe("getFragmentFromValue", () => { | ||||||||||||||||||||||||||||||||||
| it("returns correct values", () => { | ||||||||||||||||||||||||||||||||||
| const result1 = getFragmentFromValue(0); | ||||||||||||||||||||||||||||||||||
| expect(result1).toBe("general"); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const result2 = getFragmentFromValue(2); | ||||||||||||||||||||||||||||||||||
| expect(result2).toBe("pages"); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const result3 = getFragmentFromValue(3); | ||||||||||||||||||||||||||||||||||
| expect(result3).toBe("media_uploads"); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const result4 = getFragmentFromValue(7); | ||||||||||||||||||||||||||||||||||
| expect(result4).toBe("badge_scans"); | ||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| describe("getTabFromUrlFragment", () => { | ||||||||||||||||||||||||||||||||||
| it("returns correct values for defined fragments", () => { | ||||||||||||||||||||||||||||||||||
| const newUrl1 = "#general"; | ||||||||||||||||||||||||||||||||||
| window.location.hash = newUrl1; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const result1 = getTabFromUrlFragment(); | ||||||||||||||||||||||||||||||||||
| expect(result1).toBe(0); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const newUrl2 = "#pages"; | ||||||||||||||||||||||||||||||||||
| window.location.hash = newUrl2; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const result2 = getTabFromUrlFragment(); | ||||||||||||||||||||||||||||||||||
| expect(result2).toBe(2); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const newUrl3 = "#media_uploads"; | ||||||||||||||||||||||||||||||||||
| window.location.hash = newUrl3; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const result3 = getTabFromUrlFragment(); | ||||||||||||||||||||||||||||||||||
| expect(result3).toBe(3); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const newUrl4 = "#badge_scans"; | ||||||||||||||||||||||||||||||||||
| window.location.hash = newUrl4; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const result4 = getTabFromUrlFragment(); | ||||||||||||||||||||||||||||||||||
| expect(result4).toBe(7); | ||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| describe("Component", () => { | ||||||||||||||||||||||||||||||||||
| const originalWindowLocation = window.location; | ||||||||||||||||||||||||||||||||||
| it("should change the url fragment on tab click", async () => { | ||||||||||||||||||||||||||||||||||
| delete window.location; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| Object.defineProperty(window, "location", { | ||||||||||||||||||||||||||||||||||
| configurable: true, | ||||||||||||||||||||||||||||||||||
| writable: true, | ||||||||||||||||||||||||||||||||||
| value: { | ||||||||||||||||||||||||||||||||||
| ...originalWindowLocation, | ||||||||||||||||||||||||||||||||||
| hash: "#general" | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| renderWithRedux( | ||||||||||||||||||||||||||||||||||
| <EditSponsorPage | ||||||||||||||||||||||||||||||||||
| history={{}} | ||||||||||||||||||||||||||||||||||
| location={{ | ||||||||||||||||||||||||||||||||||
| pathname: "/sponsor-forms/items" | ||||||||||||||||||||||||||||||||||
| }} | ||||||||||||||||||||||||||||||||||
| match={{}} | ||||||||||||||||||||||||||||||||||
| />, | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
| initialState: { | ||||||||||||||||||||||||||||||||||
| currentSummitState: { | ||||||||||||||||||||||||||||||||||
| currentSummit: defaultSummitEntity, | ||||||||||||||||||||||||||||||||||
| ...currentSummitDefaultState | ||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||
| loggedUserState: { | ||||||||||||||||||||||||||||||||||
| member: { | ||||||||||||||||||||||||||||||||||
| groups: {} | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||
| currentSummitSponsorshipListState: { | ||||||||||||||||||||||||||||||||||
| sponsorships: [], | ||||||||||||||||||||||||||||||||||
| currentPage: 1, | ||||||||||||||||||||||||||||||||||
| lastPage: 1, | ||||||||||||||||||||||||||||||||||
| perPage: 100, | ||||||||||||||||||||||||||||||||||
| order: "order", | ||||||||||||||||||||||||||||||||||
| orderDir: 1, | ||||||||||||||||||||||||||||||||||
| totalSponsorships: 0 | ||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||
| currentSponsorState: { | ||||||||||||||||||||||||||||||||||
| sponsorships: [], | ||||||||||||||||||||||||||||||||||
| ...currentSponsorDefaultState | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const usersTabReference = screen.getByText("edit_sponsor.tab.forms"); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| await act(async () => { | ||||||||||||||||||||||||||||||||||
| await userEvent.click(usersTabReference); | ||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| expect(window.location.hash).toBe("forms"); | ||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+116
to
+123
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, find and read the test file
cat -n src/pages/sponsors/__tests__/edit-sponsor-page.test.js | head -200Repository: fntechgit/summit-admin Length of output: 6883 🏁 Script executed: # Find and read the EditSponsorPage component
cat -n src/pages/sponsors/edit-sponsor-page.js | head -300Repository: fntechgit/summit-admin Length of output: 11190 Fix hash format to match JSDOM behavior. 🔧 Suggested fix- expect(window.location.hash).toBe("forms");
+ expect(window.location.hash).toBe("#forms");📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| it("should change the tab rendered on fragment change", async () => { | ||||||||||||||||||||||||||||||||||
| delete window.location; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| Object.defineProperty(window, "location", { | ||||||||||||||||||||||||||||||||||
| configurable: true, | ||||||||||||||||||||||||||||||||||
| writable: true, | ||||||||||||||||||||||||||||||||||
| value: { | ||||||||||||||||||||||||||||||||||
| ...originalWindowLocation, | ||||||||||||||||||||||||||||||||||
| hash: "#general" | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| renderWithRedux( | ||||||||||||||||||||||||||||||||||
| <EditSponsorPage | ||||||||||||||||||||||||||||||||||
| history={{}} | ||||||||||||||||||||||||||||||||||
| location={{ | ||||||||||||||||||||||||||||||||||
| pathname: "/sponsor-forms/items" | ||||||||||||||||||||||||||||||||||
| }} | ||||||||||||||||||||||||||||||||||
| match={{}} | ||||||||||||||||||||||||||||||||||
| />, | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
| initialState: { | ||||||||||||||||||||||||||||||||||
| currentSummitState: { | ||||||||||||||||||||||||||||||||||
| currentSummit: defaultSummitEntity, | ||||||||||||||||||||||||||||||||||
| ...currentSummitDefaultState | ||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||
| loggedUserState: { | ||||||||||||||||||||||||||||||||||
| member: { | ||||||||||||||||||||||||||||||||||
| groups: {} | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||
| currentSummitSponsorshipListState: { | ||||||||||||||||||||||||||||||||||
| sponsorships: [], | ||||||||||||||||||||||||||||||||||
| currentPage: 1, | ||||||||||||||||||||||||||||||||||
| lastPage: 1, | ||||||||||||||||||||||||||||||||||
| perPage: 100, | ||||||||||||||||||||||||||||||||||
| order: "order", | ||||||||||||||||||||||||||||||||||
| orderDir: 1, | ||||||||||||||||||||||||||||||||||
| totalSponsorships: 0 | ||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||
| currentSponsorState: { | ||||||||||||||||||||||||||||||||||
| sponsorships: [], | ||||||||||||||||||||||||||||||||||
| ...currentSponsorDefaultState | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const generalTabPanel = screen.getByTestId("simple-tabpanel-0"); | ||||||||||||||||||||||||||||||||||
| expect(generalTabPanel).toBeDefined(); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| delete window.location; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| Object.defineProperty(window, "location", { | ||||||||||||||||||||||||||||||||||
| configurable: true, | ||||||||||||||||||||||||||||||||||
| writable: true, | ||||||||||||||||||||||||||||||||||
| value: { | ||||||||||||||||||||||||||||||||||
| ...originalWindowLocation, | ||||||||||||||||||||||||||||||||||
| hash: "#users" | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const usersTabPanel = screen.getByTestId("simple-tabpanel-1"); | ||||||||||||||||||||||||||||||||||
| expect(usersTabPanel).toBeDefined(); | ||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| afterEach(() => { | ||||||||||||||||||||||||||||||||||
| Object.defineProperty(window, "location", { | ||||||||||||||||||||||||||||||||||
| configurable: true, | ||||||||||||||||||||||||||||||||||
| value: originalWindowLocation | ||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.