Repository navigation
Feat: migrate to mui email flow events #1072
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6eb71b1
chore: migrate edit page
santipalenque 30313a2
chore: apply some FE rules
santipalenque 0292480
chore: improve look and feel
santipalenque 914c8e6
chore: pr review
santipalenque eb18ee6
chore: pr review
santipalenque 17d7bd9
chore: deep review
santipalenque e454107
chore: pr review
santipalenque 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
155 changes: 155 additions & 0 deletions
155
src/actions/__tests__/email-flows-events-actions.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,155 @@ | ||
| /** | ||
| * @jest-environment jsdom | ||
| */ | ||
| import configureStore from "redux-mock-store"; | ||
| import thunk from "redux-thunk"; | ||
| import { getRequest } from "openstack-uicore-foundation/lib/utils/actions"; | ||
| import { | ||
| getEmailFlowEvents, | ||
| getEmailFlowEvent | ||
| } from "../email-flows-events-actions"; | ||
| import * as methods from "../../utils/methods"; | ||
| import { createMockSummit } from "../../utils/test-utils"; | ||
|
|
||
| jest.mock("openstack-uicore-foundation/lib/utils/actions", () => ({ | ||
| __esModule: true, | ||
| ...jest.requireActual("openstack-uicore-foundation/lib/utils/actions"), | ||
| getRequest: jest.fn() | ||
| })); | ||
|
|
||
| describe("getEmailFlowEvents", () => { | ||
| const mockStore = configureStore([thunk]); | ||
|
|
||
| beforeEach(() => { | ||
| jest.spyOn(methods, "getAccessTokenSafely").mockResolvedValue("TOKEN"); | ||
| getRequest.mockImplementation(() => () => () => Promise.resolve({})); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| jest.restoreAllMocks(); | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it("forwards perPage in the request-action payload so redux keeps the page size", async () => { | ||
| const store = mockStore({ | ||
| currentSummitState: { currentSummit: createMockSummit() } | ||
| }); | ||
|
|
||
| await getEmailFlowEvents( | ||
| "welcome", | ||
| 1, | ||
| 50, | ||
| "flow_name", | ||
| -1 | ||
| )(store.dispatch, store.getState); | ||
|
|
||
| const [, , , , requestPayload] = getRequest.mock.calls[0]; | ||
| expect(requestPayload).toEqual({ | ||
| order: "flow_name", | ||
| orderDir: -1, | ||
| term: "welcome", | ||
| perPage: 50 | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| // getRequest only aborts an identical URL, so a second call with different | ||
| // params races the first. The per-thunk sequence must both skip the superseded | ||
| // call's request and drop any dispatch it still tries to make. | ||
| describe("stale-response guards", () => { | ||
| const mockStore = configureStore([thunk]); | ||
| const storeState = { | ||
| currentSummitState: { currentSummit: createMockSummit() } | ||
| }; | ||
|
|
||
| beforeEach(() => { | ||
| jest.spyOn(methods, "getAccessTokenSafely").mockResolvedValue("TOKEN"); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| jest.restoreAllMocks(); | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it("getEmailFlowEvents issues only the newest of two concurrent calls", async () => { | ||
| const store = mockStore(storeState); | ||
| getRequest.mockImplementation(() => () => () => Promise.resolve({})); | ||
|
|
||
| await Promise.all([ | ||
| getEmailFlowEvents( | ||
| "a", | ||
| 1, | ||
| 10, | ||
| "flow_name", | ||
| 1 | ||
| )(store.dispatch, store.getState), | ||
| getEmailFlowEvents( | ||
| "b", | ||
| 2, | ||
| 50, | ||
| "flow_name", | ||
| -1 | ||
| )(store.dispatch, store.getState) | ||
| ]); | ||
|
|
||
| expect(getRequest).toHaveBeenCalledTimes(1); | ||
| expect(getRequest.mock.calls[0][4]).toEqual({ | ||
| order: "flow_name", | ||
| orderDir: -1, | ||
| term: "b", | ||
| perPage: 50 | ||
| }); | ||
| }); | ||
|
|
||
| it("getEmailFlowEvents drops a superseded call's late dispatch", async () => { | ||
| const dispatched = []; | ||
| const store = mockStore(storeState); | ||
| store.dispatch = jest.fn((action) => { | ||
| if (action && action.type) dispatched.push(action.type); | ||
| return action; | ||
| }); | ||
|
|
||
| const guards = []; | ||
| getRequest.mockImplementation(() => () => (guardedDispatch) => { | ||
| guards.push(guardedDispatch); | ||
| return Promise.resolve({}); | ||
| }); | ||
|
|
||
| // first call completes and hands us its guarded dispatch | ||
| await getEmailFlowEvents( | ||
| "a", | ||
| 1, | ||
| 10, | ||
| "flow_name", | ||
| 1 | ||
| )(store.dispatch, store.getState); | ||
| // a newer call then supersedes it | ||
| await getEmailFlowEvents( | ||
| "b", | ||
| 2, | ||
| 50, | ||
| "flow_name", | ||
| -1 | ||
| )(store.dispatch, store.getState); | ||
|
|
||
| dispatched.length = 0; | ||
| guards[0]({ type: "STALE_RECEIVE" }); | ||
| guards[1]({ type: "FRESH_RECEIVE" }); | ||
|
|
||
| expect(dispatched).not.toContain("STALE_RECEIVE"); | ||
| expect(dispatched).toContain("FRESH_RECEIVE"); | ||
| }); | ||
|
|
||
| it("getEmailFlowEvent issues only the newest of two concurrent calls", async () => { | ||
| const store = mockStore(storeState); | ||
| getRequest.mockImplementation(() => () => () => Promise.resolve({})); | ||
|
|
||
| await Promise.all([ | ||
| getEmailFlowEvent(1)(store.dispatch, store.getState), | ||
| getEmailFlowEvent(2)(store.dispatch, store.getState) | ||
| ]); | ||
|
|
||
| expect(getRequest).toHaveBeenCalledTimes(1); | ||
| expect(getRequest.mock.calls[0][2]).toContain("/email-flows-events/2"); | ||
| }); | ||
| }); |
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.
Uh oh!
There was an error while loading. Please reload this page.