forked from OpenStackweb/summit-admin
-
Notifications
You must be signed in to change notification settings - Fork 4
fix: restore selection plan edit route and page, remove popup #1069
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
5
commits into
master
Choose a base branch
from
fix/edit-selection-plan-page
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
5 commits
Select commit
Hold shift + click to select a range
c5e2557
fix: restore selection plan edit route and page, remove popup, update…
tomrndom 9dddaf5
fix: add missing catch on save selection plan
tomrndom 475df1f
fix: keep form in sync with layout, add tests
tomrndom 1ebd0de
fix: adjust breadcrumb, fix issue on new selection plans
tomrndom 26c1409
fix: add missing catch, update test
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,183 @@ | ||
| /** | ||
| * Copyright 2026 OpenStack Foundation | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * */ | ||
|
|
||
| import React from "react"; | ||
| import { screen, act } from "@testing-library/react"; | ||
| import { Router, Route, Switch } from "react-router-dom"; | ||
| import { createMemoryHistory } from "history"; | ||
| import flushPromises from "flush-promises"; | ||
| import { renderWithRedux } from "../../utils/test-utils"; | ||
| import { getSelectionPlan } from "../../actions/selection-plan-actions"; | ||
| import { getMarketingSettingsBySelectionPlan } from "../../actions/marketing-actions"; | ||
| import SelectionPlanIdLayout from "../selection-plan-id-layout"; | ||
|
|
||
| jest.mock("i18n-react", () => ({ | ||
| __esModule: true, | ||
| default: { translate: (k) => k } | ||
| })); | ||
|
|
||
| // The page renders null until it's ready, so the breadcrumb's presence is our signal. | ||
| jest.mock("react-breadcrumbs", () => ({ | ||
| Breadcrumb: () => <div data-testid="breadcrumb" /> | ||
| })); | ||
|
|
||
| jest.mock("../../actions/selection-plan-actions", () => ({ | ||
| __esModule: true, | ||
| ...jest.requireActual("../../actions/selection-plan-actions"), | ||
| getSelectionPlan: jest.fn(), | ||
| resetSelectionPlanForm: jest.fn(() => ({ type: "RESET_SELECTION_PLAN_FORM" })) | ||
| })); | ||
|
|
||
| jest.mock("../../actions/marketing-actions", () => ({ | ||
| __esModule: true, | ||
| ...jest.requireActual("../../actions/marketing-actions"), | ||
| getMarketingSettingsBySelectionPlan: jest.fn() | ||
| })); | ||
|
|
||
| // Stub the page: the real form needs a fuller marketing-settings shape than set up here. | ||
| jest.mock("../../pages/selection-plans/edit-selection-plan-page", () => ({ | ||
| __esModule: true, | ||
| default: () => <div data-testid="edit-selection-plan-page" /> | ||
| })); | ||
|
|
||
| const renderAt = (path, currentSelectionPlan) => { | ||
| const history = createMemoryHistory({ initialEntries: [path] }); | ||
| return renderWithRedux( | ||
| <Router history={history}> | ||
| <Route | ||
| path="/app/summits/:summit_id/selection-plans/:selection_plan_id" | ||
| component={SelectionPlanIdLayout} | ||
| /> | ||
| </Router>, | ||
| { | ||
| initialState: { | ||
| currentSelectionPlanState: { entity: currentSelectionPlan }, | ||
| currentSummitState: { currentSummit: { id: 1 } } | ||
| } | ||
| } | ||
| ); | ||
| }; | ||
|
|
||
| const settle = () => act(async () => flushPromises()); | ||
|
|
||
| const isPageRendered = () => screen.queryByTestId("breadcrumb") !== null; | ||
|
|
||
| // Mirrors the sibling /new and /:id(\d+) routes in selection-plan-layout.js. | ||
| const NewOrEditHarness = ({ history }) => ( | ||
| <Router history={history}> | ||
| <Switch> | ||
| <Route | ||
| strict | ||
| exact | ||
| path="/app/summits/:summit_id/selection-plans/new" | ||
| component={SelectionPlanIdLayout} | ||
| /> | ||
| <Route | ||
| path="/app/summits/:summit_id/selection-plans/:selection_plan_id(\d+)" | ||
| component={SelectionPlanIdLayout} | ||
| /> | ||
| </Switch> | ||
| </Router> | ||
| ); | ||
|
|
||
| describe("SelectionPlanIdLayout load guard", () => { | ||
| beforeEach(() => { | ||
| getSelectionPlan.mockReset(); | ||
| getMarketingSettingsBySelectionPlan.mockReset(); | ||
| getSelectionPlan.mockImplementation(() => () => Promise.resolve()); | ||
| getMarketingSettingsBySelectionPlan.mockImplementation( | ||
| () => () => Promise.resolve() | ||
| ); | ||
| }); | ||
|
|
||
| it("does not render on direct load until the matching plan finishes fetching", async () => { | ||
| getSelectionPlan.mockImplementation(() => () => new Promise(() => {})); | ||
| renderAt("/app/summits/1/selection-plans/5", { id: 5 }); | ||
| expect(isPageRendered()).toBe(false); | ||
| }); | ||
|
|
||
| it("stops rendering when switching to a different plan id until the store catches up", async () => { | ||
| const history = createMemoryHistory({ | ||
| initialEntries: ["/app/summits/1/selection-plans/5"] | ||
| }); | ||
| renderWithRedux( | ||
| <Router history={history}> | ||
| <Route | ||
| path="/app/summits/:summit_id/selection-plans/:selection_plan_id" | ||
| component={SelectionPlanIdLayout} | ||
| /> | ||
| </Router>, | ||
| { | ||
| initialState: { | ||
| currentSelectionPlanState: { entity: { id: 5 } }, | ||
| currentSummitState: { currentSummit: { id: 1 } } | ||
| } | ||
| } | ||
| ); | ||
| await settle(); | ||
| expect(isPageRendered()).toBe(true); | ||
|
|
||
| act(() => { | ||
| history.push("/app/summits/1/selection-plans/8"); | ||
| }); | ||
| expect(isPageRendered()).toBe(false); | ||
| expect(getSelectionPlan).toHaveBeenCalledWith("8"); | ||
|
|
||
| // Fetch settles, but the store's entity.id is still "5" — must stay unrendered. | ||
| await settle(); | ||
| expect(isPageRendered()).toBe(false); | ||
| }); | ||
|
|
||
| it("stops rendering when navigating from an existing plan to /new until the store reflects the reset", async () => { | ||
| const history = createMemoryHistory({ | ||
| initialEntries: ["/app/summits/1/selection-plans/5"] | ||
| }); | ||
| renderWithRedux(<NewOrEditHarness history={history} />, { | ||
| initialState: { | ||
| currentSelectionPlanState: { entity: { id: 5 } }, | ||
| currentSummitState: { currentSummit: { id: 1 } } | ||
| } | ||
| }); | ||
| await settle(); | ||
| expect(isPageRendered()).toBe(true); | ||
|
|
||
| // Store still holds plan 5's entity (reset hasn't landed) — must not render. | ||
| act(() => { | ||
| history.push("/app/summits/1/selection-plans/new"); | ||
| }); | ||
| expect(isPageRendered()).toBe(false); | ||
| }); | ||
|
|
||
| it("renders on /new once the store reflects the reset (default) entity", async () => { | ||
| const history = createMemoryHistory({ | ||
| initialEntries: ["/app/summits/1/selection-plans/new"] | ||
| }); | ||
| renderWithRedux(<NewOrEditHarness history={history} />, { | ||
| initialState: { | ||
| currentSelectionPlanState: { entity: { id: 0 } }, | ||
| currentSummitState: { currentSummit: { id: 1 } } | ||
| } | ||
| }); | ||
| await settle(); | ||
| expect(isPageRendered()).toBe(true); | ||
| }); | ||
|
|
||
| it("does not render or throw when the fetch rejects", async () => { | ||
| getSelectionPlan.mockImplementation( | ||
| () => () => Promise.reject(new Error("fail")) | ||
| ); | ||
| renderAt("/app/summits/1/selection-plans/5", { id: 0 }); | ||
| await expect(settle()).resolves.not.toThrow(); | ||
| expect(isPageRendered()).toBe(false); | ||
| }); | ||
| }); |
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
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.
🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🤖 get_repo_knowledge executed:
get_repo_knowledge fntechgit/summit-admin /tmp/coderabbit-repo-knowledge/fntechgit-summit-admin-1d8c654c/architecture /tmp/coderabbit-repo-knowledge/fntechgit-summit-admin-1d8c654c/learningsLength of output: 46525
🏁 Script executed:
Repository: fntechgit/summit-admin
Length of output: 32276
🏁 Script executed:
Repository: fntechgit/summit-admin
Length of output: 50379
Prevent stale selection-plan responses from updating route state.
When navigation changes from plan A to plan B,
getSelectionPlandispatchesRECEIVE_SELECTION_PLANwithout a request identity, andselectionPlanReduceraccepts every response. If plan B completes first, a late plan A response can replacecurrentSelectionPlan. The effect then setshasLoadedtotrue, but the ID guard keeps the plan B route blank. Ignore stale responses at the action or reducer boundary, and add a deferred-request test for this navigation sequence.🤖 Prompt for AI Agents
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Handle rejected loads before leaving the route blank.
getRequestinvokes the error handler and then rejects. A rejection from either load action skipssetHasLoaded(true), so the guard at line 57 keeps returningnull. Catch the chain, store the error, and render an error or retry state.🤖 Prompt for AI Agents