-
Notifications
You must be signed in to change notification settings - Fork 4
fix: bug in speakers count column in activity list #815
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
base: master
Are you sure you want to change the base?
Changes from all commits
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,116 @@ | ||
| import configureStore from "redux-mock-store"; | ||
| import thunk from "redux-thunk"; | ||
| import flushPromises from "flush-promises"; | ||
| import { getRequest } from "openstack-uicore-foundation/lib/utils/actions"; | ||
| import { getEvents } from "../event-actions"; | ||
| import * as methods from "../../utils/methods"; | ||
|
|
||
| jest.mock("openstack-uicore-foundation/lib/utils/actions", () => ({ | ||
| __esModule: true, | ||
| ...jest.requireActual("openstack-uicore-foundation/lib/utils/actions"), | ||
| getRequest: jest.fn() | ||
| })); | ||
|
|
||
| describe("Event Actions", () => { | ||
| const middlewares = [thunk]; | ||
| const mockStore = configureStore(middlewares); | ||
|
|
||
| let capturedParams = null; | ||
|
|
||
| beforeEach(() => { | ||
| jest.spyOn(methods, "getAccessTokenSafely").mockResolvedValue("TOKEN"); | ||
| getRequest.mockClear(); | ||
|
|
||
| getRequest.mockImplementation( | ||
| (requestActionCreator, receiveActionCreator) => | ||
| (params = {}) => | ||
| (dispatch) => { | ||
| capturedParams = params; | ||
|
|
||
| if ( | ||
| requestActionCreator && | ||
| typeof requestActionCreator === "function" | ||
| ) { | ||
| dispatch(requestActionCreator({})); | ||
| } | ||
|
|
||
| return new Promise((resolve) => { | ||
| if (typeof receiveActionCreator === "function") { | ||
| dispatch(receiveActionCreator({ response: {} })); | ||
| } else { | ||
| dispatch(receiveActionCreator); | ||
| } | ||
|
|
||
| resolve({ response: {} }); | ||
| }); | ||
| } | ||
| ); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| jest.restoreAllMocks(); | ||
| capturedParams = null; | ||
| }); | ||
|
|
||
| test("builds speakers_count between filter using [] syntax", async () => { | ||
| const store = mockStore({ | ||
| currentSummitState: { | ||
| currentSummit: { | ||
| id: 1, | ||
| time_zone: { name: "UTC" } | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| store.dispatch( | ||
| getEvents(null, 1, 10, "id", 1, { speakers_count_filter: [1, 3] }, []) | ||
| ); | ||
|
|
||
| await flushPromises(); | ||
|
|
||
| expect(getRequest).toHaveBeenCalledTimes(1); | ||
| expect(capturedParams).toBeTruthy(); | ||
| expect(capturedParams["filter[]"]).toContain("speakers_count[]1&&3"); | ||
| expect(capturedParams["filter[]"]).not.toContain("speakers_count[]]1&&3"); | ||
| }); | ||
|
|
||
| test("requests type.use_speakers in fields for event list", async () => { | ||
| const store = mockStore({ | ||
| currentSummitState: { | ||
| currentSummit: { | ||
| id: 1, | ||
| time_zone: { name: "UTC" } | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| store.dispatch(getEvents()); | ||
|
|
||
| await flushPromises(); | ||
|
|
||
| expect(getRequest).toHaveBeenCalledTimes(1); | ||
| expect(capturedParams).toBeTruthy(); | ||
| expect(capturedParams.fields).toContain("type.use_speakers"); | ||
| }); | ||
|
|
||
| test("builds speakers_count operator filter when value is not an array", async () => { | ||
| const store = mockStore({ | ||
| currentSummitState: { | ||
| currentSummit: { | ||
| id: 1, | ||
| time_zone: { name: "UTC" } | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| store.dispatch( | ||
| getEvents(null, 1, 10, "id", 1, { speakers_count_filter: ">=2" }, []) | ||
| ); | ||
|
|
||
| await flushPromises(); | ||
|
|
||
| expect(getRequest).toHaveBeenCalledTimes(1); | ||
| expect(capturedParams).toBeTruthy(); | ||
| expect(capturedParams["filter[]"]).toContain("speakers_count>=2"); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,7 +52,8 @@ import { | |
| EXPORT_PAGE_SIZE_200, | ||
| FIVE_PER_PAGE, | ||
| HOUR_AND_HALF, | ||
| SECONDS_TO_MINUTES | ||
| SECONDS_TO_MINUTES, | ||
| TWO | ||
| } from "../utils/constants"; | ||
| import { getIdValue } from "../utils/summitUtils"; | ||
|
|
||
|
|
@@ -258,10 +259,13 @@ const parseFilters = (filters, term = null) => { | |
| } | ||
|
|
||
| if (filters.speakers_count_filter) { | ||
| if (Array.isArray(filters.speakers_count_filter)) { | ||
| if ( | ||
| Array.isArray(filters.speakers_count_filter) && | ||
| filters.speakers_count_filter.length === TWO | ||
| ) { | ||
| // between | ||
| filter.push( | ||
| `speakers_count[]]${filters.speakers_count_filter[0]}&&${filters.speakers_count_filter[1]}` | ||
| `speakers_count[]${filters.speakers_count_filter[0]}&&${filters.speakers_count_filter[1]}` | ||
| ); | ||
| } else { | ||
| filter.push(`speakers_count${filters.speakers_count_filter}`); | ||
|
|
@@ -565,7 +569,7 @@ export const getEvents = | |
| relations: | ||
| "none,speakers.none,selection_plan.none,track.none,type.none,created_by.none,location.none,media_uploads.media_upload_type.none", | ||
| fields: | ||
| "id,created,last_edited,title,start_date,end_date,summit_id,duration,class_name,is_published,level,published_date,meeting_url,status,progress,selection_status,streaming_url,streaming_type,etherpad_link,location.id,location.name,speakers.id,speakers.first_name,speakers.last_name,speakers.company,track.name,track.id,created_by.first_name,created_by.last_name,created_by.email,created_by.company,selection_plan.name,selection_plan.id,media_uploads.id,media_uploads.presentation_id,media_uploads.created,media_uploads.class_name,media_uploads.display_on_site,media_uploads.media_upload_type.name,media_uploads.media_upload_type.id,type.id,type.name,sponsors.id,sponsors.name,allow_feedback,to_record,review_status", | ||
| "id,created,last_edited,title,start_date,end_date,summit_id,duration,class_name,is_published,level,published_date,meeting_url,status,progress,selection_status,streaming_url,streaming_type,etherpad_link,location.id,location.name,speakers.id,speakers.first_name,speakers.last_name,speakers.company,track.name,track.id,created_by.first_name,created_by.last_name,created_by.email,created_by.company,selection_plan.name,selection_plan.id,media_uploads.id,media_uploads.presentation_id,media_uploads.created,media_uploads.class_name,media_uploads.display_on_site,media_uploads.media_upload_type.name,media_uploads.media_upload_type.id,type.id,type.name,type.use_speakers,sponsors.id,sponsors.name,allow_feedback,to_record,review_status", | ||
|
Comment on lines
571
to
+572
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. Request the other
Suggested patch- "id,created,last_edited,title,start_date,end_date,summit_id,duration,class_name,is_published,level,published_date,meeting_url,status,progress,selection_status,streaming_url,streaming_type,etherpad_link,location.id,location.name,speakers.id,speakers.first_name,speakers.last_name,speakers.company,track.name,track.id,created_by.first_name,created_by.last_name,created_by.email,created_by.company,selection_plan.name,selection_plan.id,media_uploads.id,media_uploads.presentation_id,media_uploads.created,media_uploads.class_name,media_uploads.display_on_site,media_uploads.media_upload_type.name,media_uploads.media_upload_type.id,type.id,type.name,type.use_speakers,sponsors.id,sponsors.name,allow_feedback,to_record,review_status",
+ "id,created,last_edited,title,start_date,end_date,summit_id,duration,class_name,is_published,level,published_date,meeting_url,status,progress,selection_status,streaming_url,streaming_type,etherpad_link,location.id,location.name,speakers.id,speakers.first_name,speakers.last_name,speakers.company,track.name,track.id,created_by.first_name,created_by.last_name,created_by.email,created_by.company,selection_plan.name,selection_plan.id,media_uploads.id,media_uploads.presentation_id,media_uploads.created,media_uploads.class_name,media_uploads.display_on_site,media_uploads.media_upload_type.name,media_uploads.media_upload_type.id,type.id,type.name,type.use_speakers,type.allows_location,type.allows_attendee_vote,type.allows_publishing_dates,sponsors.id,sponsors.name,allow_feedback,to_record,review_status",🤖 Prompt for AI Agents |
||
| page, | ||
| per_page: perPage, | ||
| access_token: accessToken | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import { formatEventData } from "../summitUtils"; | ||
|
|
||
| describe("summitUtils.formatEventData", () => { | ||
| const summit = { | ||
| time_zone: { name: "UTC" }, | ||
| time_zone_id: "UTC" | ||
| }; | ||
|
|
||
| test("returns speakers_count based on speakers length when type.use_speakers is true", () => { | ||
| const event = { | ||
| id: 10, | ||
| summit_id: 1, | ||
| title: "Test Event", | ||
| is_published: false, | ||
| type: { | ||
| use_speakers: true, | ||
| allows_location: false, | ||
| allows_attendee_vote: false, | ||
| allows_publishing_dates: false | ||
| }, | ||
| speakers: [ | ||
| { first_name: "Jane", last_name: "Doe", company: "ACME" }, | ||
| { first_name: "John", last_name: "Smith", company: "Globex" } | ||
| ], | ||
| tags: [], | ||
| sponsors: [] | ||
| }; | ||
|
|
||
| const result = formatEventData(event, summit); | ||
|
|
||
| expect(result.speakers_count).toBe(2); | ||
| }); | ||
|
|
||
| test("returns \"0\" when type.use_speakers is true and speakers list is empty", () => { | ||
| const event = { | ||
| id: 12, | ||
| summit_id: 1, | ||
| title: "No Speakers Yet", | ||
| is_published: false, | ||
| type: { | ||
| use_speakers: true, | ||
| allows_location: false, | ||
| allows_attendee_vote: false, | ||
| allows_publishing_dates: false | ||
| }, | ||
| speakers: [], | ||
| tags: [], | ||
| sponsors: [] | ||
| }; | ||
|
|
||
| const result = formatEventData(event, summit); | ||
|
|
||
| expect(result.speakers_count).toBe("0"); | ||
| }); | ||
|
|
||
| test("returns N/A and does not throw when event type is missing", () => { | ||
| const event = { | ||
| id: 11, | ||
| summit_id: 1, | ||
| title: "Type-less Event", | ||
| is_published: false, | ||
| speakers: [], | ||
| tags: [], | ||
| sponsors: [] | ||
| }; | ||
|
|
||
| let result; | ||
| expect(() => { | ||
| result = formatEventData(event, summit); | ||
| }).not.toThrow(); | ||
| expect(result.speakers_count).toBe("N/A"); | ||
| }); | ||
| }); |
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.
I see no validation for the array having 2 elements.