forked from OpenStackweb/summit-admin
-
Notifications
You must be signed in to change notification settings - Fork 4
feat: migrate track chair list and edit to mui components #918
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
Open
tomrndom
wants to merge
6
commits into
master
Choose a base branch
from
fix/track-chair-list-mui
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e7841ab
feat: migrate track chair list and edit to mui components
tomrndom 0cb4096
fix: adjust validation for empty summit id before useEffect
tomrndom ec2c8d9
fix: adjust validation and dependnecy on useEffect
tomrndom d6f6226
fix: add isSaving props into list and dialog components
tomrndom d048d69
fix: adjust isSaving prop, disable member on edit, add unit tests
tomrndom 5d16356
fix: adjust onClose responsability into dialog component
tomrndom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
207 changes: 207 additions & 0 deletions
207
src/pages/track_chairs/__tests__/track-chair-list-page.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,207 @@ | ||
| import React from "react"; | ||
| import { act, screen } from "@testing-library/react"; | ||
| import userEvent from "@testing-library/user-event"; | ||
| import { renderWithRedux } from "utils/test-utils"; | ||
| import { | ||
| saveTrackChair, | ||
| addTrackChair, | ||
| deleteTrackChair | ||
| } from "../../../actions/track-chair-actions"; | ||
| import TrackChairListPage from "../track-chair-list-page"; | ||
|
|
||
| jest.mock("../../../actions/track-chair-actions", () => ({ | ||
| getTrackChairs: jest.fn(() => () => Promise.resolve()), | ||
| deleteTrackChair: jest.fn(() => () => Promise.resolve()), | ||
| saveTrackChair: jest.fn(() => () => Promise.resolve()), | ||
| addTrackChair: jest.fn(() => () => Promise.resolve()), | ||
| exportTrackChairs: jest.fn(() => () => Promise.resolve()) | ||
| })); | ||
|
|
||
| jest.mock( | ||
| "openstack-uicore-foundation/lib/components/mui/table", | ||
| () => | ||
| function MockMuiTable({ data, onEdit, onDelete }) { | ||
| return ( | ||
| <div> | ||
| {data.map((item) => ( | ||
| <div key={item.id}> | ||
| <button | ||
| data-testid={`edit-${item.id}`} | ||
| onClick={() => onEdit(item)} | ||
| > | ||
| edit-{item.id} | ||
| </button> | ||
| <button | ||
| data-testid={`delete-${item.id}`} | ||
| onClick={() => onDelete(item.id)} | ||
| > | ||
| delete-{item.id} | ||
| </button> | ||
| </div> | ||
| ))} | ||
| </div> | ||
| ); | ||
| } | ||
| ); | ||
|
|
||
| jest.mock( | ||
| "openstack-uicore-foundation/lib/components/mui/search-input", | ||
| () => () => null | ||
| ); | ||
|
|
||
| // Capture the dialog's props so tests can call onSave/onClose with specific values | ||
| let capturedDialogProps = null; | ||
| jest.mock("../components/track-chair-dialog", () => ({ | ||
| __esModule: true, | ||
| default: (props) => { | ||
| capturedDialogProps = props; | ||
| return <div data-testid="track-chair-dialog" />; | ||
| } | ||
| })); | ||
|
|
||
| const mockTracks = [ | ||
| { id: 1, name: "Track A", chair_visible: true }, | ||
| { id: 2, name: "Track B", chair_visible: true } | ||
| ]; | ||
|
|
||
| const mockTrackChair = { | ||
| id: 10, | ||
| name: "Jane Doe (jane@example.com)", | ||
| member: { | ||
| id: 42, | ||
| first_name: "Jane", | ||
| last_name: "Doe", | ||
| email: "jane@example.com" | ||
| }, | ||
| categories: [{ id: 1, name: "Track A" }], | ||
| trackIds: [1], | ||
| trackNames: "Track A" | ||
| }; | ||
|
|
||
| const initialState = { | ||
| currentSummitState: { | ||
| currentSummit: { id: 1, name: "Test Summit", tracks: mockTracks } | ||
| }, | ||
| trackChairListState: { | ||
| trackChairs: [], | ||
| trackId: null, | ||
| term: "", | ||
| order: "id", | ||
| orderDir: 1, | ||
| currentPage: 1, | ||
| lastPage: 1, | ||
| perPage: 10, | ||
| totalTrackChairs: 0 | ||
| } | ||
| }; | ||
|
|
||
| describe("TrackChairListPage", () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| capturedDialogProps = null; | ||
| }); | ||
|
|
||
| const renderPage = (stateOverrides = {}) => | ||
| renderWithRedux(<TrackChairListPage history={{ push: jest.fn() }} />, { | ||
| initialState: { | ||
| ...initialState, | ||
| trackChairListState: { | ||
| ...initialState.trackChairListState, | ||
| ...stateOverrides | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| describe("dialog visibility", () => { | ||
| it("shows after clicking Add and closes when onClose is called", async () => { | ||
| renderPage(); | ||
| expect( | ||
| screen.queryByTestId("track-chair-dialog") | ||
| ).not.toBeInTheDocument(); | ||
|
|
||
| await act(async () => { | ||
| await userEvent.click(screen.getByRole("button", { name: /add/i })); | ||
| }); | ||
| expect(screen.getByTestId("track-chair-dialog")).toBeInTheDocument(); | ||
|
|
||
| await act(async () => { | ||
| capturedDialogProps.onClose(); | ||
| }); | ||
| expect( | ||
| screen.queryByTestId("track-chair-dialog") | ||
| ).not.toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| describe("handleEdit", () => { | ||
| it("passes the correct entity shape to the dialog", async () => { | ||
| renderPage({ trackChairs: [mockTrackChair] }); | ||
|
|
||
| await act(async () => { | ||
| await userEvent.click(screen.getByTestId(`edit-${mockTrackChair.id}`)); | ||
| }); | ||
|
|
||
| expect(capturedDialogProps.entity).toEqual({ | ||
| id: mockTrackChair.id, | ||
| member: mockTrackChair.member, | ||
| originalMemberId: mockTrackChair.member.id, | ||
| trackIds: [1] // mapped from categories | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe("handleDelete", () => { | ||
| it("calls deleteTrackChair with the row id", async () => { | ||
| renderPage({ trackChairs: [mockTrackChair] }); | ||
|
|
||
| await act(async () => { | ||
| await userEvent.click( | ||
| screen.getByTestId(`delete-${mockTrackChair.id}`) | ||
| ); | ||
| }); | ||
|
|
||
| expect(deleteTrackChair).toHaveBeenCalledWith(mockTrackChair.id); | ||
| }); | ||
| }); | ||
|
|
||
| describe("handleSave", () => { | ||
| it("calls addTrackChair when saving a new chair (no id)", async () => { | ||
| renderPage(); | ||
|
|
||
| await act(async () => { | ||
| await userEvent.click(screen.getByRole("button", { name: /add/i })); | ||
| }); | ||
|
|
||
| await act(async () => { | ||
| await capturedDialogProps.onSave({ | ||
| id: 0, | ||
| member: { value: 99, label: "New Member" }, | ||
| trackIds: [1] | ||
| }); | ||
| }); | ||
|
|
||
| expect(addTrackChair).toHaveBeenCalledWith({ id: 99 }, [1]); | ||
| expect(saveTrackChair).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("calls saveTrackChair when only tracks change on an existing chair", async () => { | ||
| renderPage({ trackChairs: [mockTrackChair] }); | ||
|
|
||
| await act(async () => { | ||
| await userEvent.click(screen.getByTestId(`edit-${mockTrackChair.id}`)); | ||
| }); | ||
|
|
||
| // Same member (value: 42 === originalMemberId: 42), different tracks | ||
| await act(async () => { | ||
| await capturedDialogProps.onSave({ | ||
| id: mockTrackChair.id, | ||
| member: { value: 42 }, | ||
| trackIds: [1, 2] | ||
| }); | ||
| }); | ||
|
|
||
| expect(saveTrackChair).toHaveBeenCalledWith(mockTrackChair.id, [1, 2]); | ||
| expect(addTrackChair).not.toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Risk:
{...rest}can override critical internal props.Spreading
{...rest}after all other props means consumer-provided props likeonChange,value,loading, ormultiplecan override the component's internal Formik-integrated handlers, breaking form synchronization silently.Consider one of these safer patterns:
{...rest}before critical props so internal props take precedence.disabled,sx,className,testId).🛡️ Recommended fix: spread rest before critical props
Or if you need full flexibility, spread before:
return ( <Autocomplete + {...rest} options={options} value={value} onChange={handleChange} loading={loading} multiple={isMulti} ... - {...rest} /> );Note: If spreading before, document which props consumers can safely override.
🤖 Prompt for AI Agents