-
Notifications
You must be signed in to change notification settings - Fork 1
feat: allow to read event_ids from hash url to render a custom schedule #209
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
9 commits
Select commit
Hold shift + click to select a range
34c3fd9
feat: allow to read event_ids from hash url to render a custom events…
tomrndom e347d79
fix: fix issue with filter params, validation for SET_CUSTOM_EVENT_ID…
tomrndom 28ecd25
fix: mock getState on shareLinkHash test file
tomrndom 39f3b8e
fix: add conditionals on scroll at schedule page, add try/catch for d…
tomrndom 4f95af1
fix: fix typo
tomrndom 37674ca
fix: add test for schedule page, add sentry capture message on catche…
tomrndom 0b17d50
fix: remove test file
tomrndom 1c56346
fix: add simple unit test file for schedule page
tomrndom 8ee1e0f
fix: adjust test mocks to pass CI build without json files
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,46 @@ | ||
| import { | ||
| updateFiltersFromHash, | ||
| updateCustomEventIdsFromHash, | ||
| } from '../schedule-actions'; | ||
|
|
||
| const setHash = (hash) => { | ||
| window.location.hash = hash; | ||
| }; | ||
|
|
||
| afterEach(() => { | ||
| setHash(''); | ||
| }); | ||
|
|
||
| it('keeps hash-applied facet filters across the follow-up pass', async () => { | ||
| window.location.hash = '#event_ids=1,2&track=5'; | ||
| const dispatch1 = jest.fn(); | ||
| const filters = { track: { label: 'Track', values: [], options: ['5', '6'] } }; | ||
|
|
||
| await updateFiltersFromHash('schedKey', filters, null)(dispatch1); | ||
|
|
||
| // pass 1 applies the filter and rewrites the hash keeping event_ids | ||
| expect(dispatch1.mock.calls[0][0].payload.filters.track.values).toEqual([5]); | ||
| expect(window.location.hash).toBe('#event_ids=1,2'); | ||
|
|
||
| // the hash change re-runs the [key, location.hash] effect (pass 2), | ||
| // now with the state filters holding the applied values | ||
| const dispatch2 = jest.fn(); | ||
| const filtersAfterPass1 = { track: { label: 'Track', values: [5], options: ['5', '6'] } }; | ||
|
|
||
| await updateFiltersFromHash('schedKey', filtersAfterPass1, null)(dispatch2); | ||
|
|
||
| // desired: no filter params left in the hash -> keep state untouched | ||
| expect(dispatch2).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('does not dispatch when the hash has no event_ids and state already holds none', () => { | ||
| window.location.hash = '#track=5'; | ||
| const dispatch = jest.fn(); | ||
| const getState = () => ({ | ||
| allSchedulesState: { schedules: [{ key: 'schedKey', customEventIds: [] }] } | ||
| }); | ||
|
|
||
| updateCustomEventIdsFromHash('schedKey')(dispatch, getState); | ||
|
|
||
| expect(dispatch).not.toHaveBeenCalled(); | ||
| }); |
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,113 @@ | ||
| import { | ||
| updateCustomEventIdsFromHash, | ||
| updateFiltersFromHash, | ||
| getShareLink, | ||
| SET_CUSTOM_EVENT_IDS, | ||
| } from '../schedule-actions'; | ||
|
|
||
| const setHash = (hash) => { | ||
| window.location.hash = hash; | ||
| }; | ||
|
|
||
| // customEventIds deliberately doesn't match any value computed below, so the | ||
| // "unchanged" short-circuit in updateCustomEventIdsFromHash never suppresses dispatch here | ||
| const getState = () => ({ | ||
| allSchedulesState: { schedules: [{ key: 'schedKey', customEventIds: [999] }] } | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| setHash(''); | ||
| }); | ||
|
|
||
| describe('updateCustomEventIdsFromHash', () => { | ||
| it('parses a numeric event_ids list from the hash', () => { | ||
| setHash('#event_ids=1,2,3'); | ||
| const dispatch = jest.fn(); | ||
|
|
||
| updateCustomEventIdsFromHash('schedKey')(dispatch, getState); | ||
|
|
||
| expect(dispatch).toHaveBeenCalledWith({ | ||
| type: SET_CUSTOM_EVENT_IDS, | ||
| payload: { customEventIds: [1, 2, 3], key: 'schedKey' }, | ||
| }); | ||
| }); | ||
|
|
||
| it('drops unknown/non-numeric ids without throwing', () => { | ||
| setHash('#event_ids=1,abc,3'); | ||
| const dispatch = jest.fn(); | ||
|
|
||
| expect(() => updateCustomEventIdsFromHash('schedKey')(dispatch, getState)).not.toThrow(); | ||
| expect(dispatch).toHaveBeenCalledWith({ | ||
| type: SET_CUSTOM_EVENT_IDS, | ||
| payload: { customEventIds: [1, 3], key: 'schedKey' }, | ||
| }); | ||
| }); | ||
|
|
||
| it('dispatches an empty list when event_ids is absent from the hash', () => { | ||
| setHash('#track=5'); | ||
| const dispatch = jest.fn(); | ||
|
|
||
| updateCustomEventIdsFromHash('schedKey')(dispatch, getState); | ||
|
|
||
| expect(dispatch).toHaveBeenCalledWith({ | ||
| type: SET_CUSTOM_EVENT_IDS, | ||
| payload: { customEventIds: [], key: 'schedKey' }, | ||
| }); | ||
| }); | ||
|
|
||
| it('is not affected by the whole-fragment lowercasing of the hash param key', () => { | ||
| setHash('#EVENT_IDS=1,2'); | ||
| const dispatch = jest.fn(); | ||
|
|
||
| updateCustomEventIdsFromHash('schedKey')(dispatch, getState); | ||
|
|
||
| expect(dispatch).toHaveBeenCalledWith({ | ||
| type: SET_CUSTOM_EVENT_IDS, | ||
| payload: { customEventIds: [1, 2], key: 'schedKey' }, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('updateFiltersFromHash - event_ids isolation (mitigation for verified points 7 & 8)', () => { | ||
| it('never includes event_ids as a key of the dispatched filters object', () => { | ||
| setHash('#event_ids=10,20&track=5'); | ||
| const dispatch = jest.fn(); | ||
| const filters = { | ||
| track: { label: 'Track', values: [], options: ['5', '6'] }, | ||
| }; | ||
|
|
||
| updateFiltersFromHash('schedKey', filters, null)(dispatch); | ||
|
|
||
| expect(dispatch).toHaveBeenCalled(); | ||
| const dispatchedFilters = dispatch.mock.calls[0][0].payload.filters; | ||
| expect(Object.keys(dispatchedFilters)).not.toContain('event_ids'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getShareLink - event_ids passthrough (regression, verified point 5)', () => { | ||
| it('keeps event_ids in the link when an active filter exists', () => { | ||
| setHash('#event_ids=10,20&track=5'); | ||
| const filters = { track: { values: ['5'], options: ['5', '6'] } }; | ||
|
|
||
| const link = getShareLink(filters, null); | ||
|
|
||
| expect(link).toContain('event_ids=10,20'); | ||
| }); | ||
|
|
||
| it('keeps event_ids in the link when all filters are empty', () => { | ||
| setHash('#event_ids=10,20'); | ||
| const filters = { track: { values: [], options: ['5', '6'] } }; | ||
|
|
||
| const link = getShareLink(filters, null); | ||
|
|
||
| expect(link).toContain('event_ids=10,20'); | ||
| }); | ||
|
|
||
| it('keeps event_ids in the link when view is null and no filters are passed', () => { | ||
| setHash('#event_ids=10,20'); | ||
|
|
||
| const link = getShareLink(null, null); | ||
|
|
||
| expect(link).toContain('event_ids=10,20'); | ||
| }); | ||
| }); |
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.
Uh oh!
There was an error while loading. Please reload this page.