-
Notifications
You must be signed in to change notification settings - Fork 21
fix(admin-ui): incorrect cancel button behaviour in the Application S… #2389
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
15 commits
Select commit
Hold shift + click to select a range
fa3ebf3
fix(admin-ui): incorrect cancel button behaviour in the Application S…
faisalsiddique4400 f6f22cd
Improved code for the Setting page with better approach
faisalsiddique4400 4b26065
Improved code for the Setting page with better approach
faisalsiddique4400 9ffe88d
Update the code of the config api url badge as before
faisalsiddique4400 9e8040a
Merge branch 'main' of github-faisal:GluuFederation/flex into admin-u…
faisalsiddique4400 b54fd1a
Merge branch 'main' into admin-ui-issue-2388
faisalsiddique4400 334bfb4
Merge branch 'admin-ui-issue-2388' of github-faisal:GluuFederation/fl…
faisalsiddique4400 3a8462c
Merge branch 'main' into admin-ui-issue-2388
faisalsiddique4400 b6eccb0
Merge branch 'admin-ui-issue-2388' of github-faisal:GluuFederation/fl…
faisalsiddique4400 2daffc8
code rabbit suggestions
faisalsiddique4400 e8498f3
code rabbit suggestions
faisalsiddique4400 0e66049
code rabbit suggestions
faisalsiddique4400 114285b
code rabbit suggestions
faisalsiddique4400 2696021
code rabbit suggestions
faisalsiddique4400 9f94208
tests added
faisalsiddique4400 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,249 @@ | ||
| import { expectSaga } from 'redux-saga-test-plan' | ||
| import * as matchers from 'redux-saga-test-plan/matchers' | ||
| import { throwError } from 'redux-saga-test-plan/providers' | ||
| import { getOAuth2ConfigResponse, putConfigWorkerResponse } from '../../features/authSlice' | ||
| import { updateToast } from '../../features/toastSlice' | ||
| import { putServerConfiguration } from '../../api/backend-api' | ||
| import * as AuthSaga from '../AuthSaga' | ||
|
|
||
| const { putConfigWorker } = AuthSaga | ||
|
|
||
| describe('AuthSaga - putConfigWorker', () => { | ||
| const mockToken = 'mock-access-token' | ||
| const mockConfig = { | ||
| sessionTimeoutInMins: 30, | ||
| acrValues: 'simple_password_auth', | ||
| cedarlingLogType: 'OFF', | ||
| additionalParameters: [], | ||
| } | ||
| const mockResponse = { | ||
| ...mockConfig, | ||
| postLogoutRedirectUri: 'https://example.com/logout', | ||
| } | ||
|
|
||
| const mockState = { | ||
| authReducer: { | ||
| token: { | ||
| access_token: mockToken, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| describe('when cedarlingLogType changes', () => { | ||
| // eslint-disable-next-line jest/expect-expect | ||
| it('should dispatch updateToast with custom message on success', () => { | ||
| const customToastMessage = 'Please relogin to view cedarling changes' | ||
| const action = { | ||
| type: 'auth/putConfigWorker', | ||
| payload: { | ||
| ...mockConfig, | ||
| _meta: { | ||
| cedarlingLogTypeChanged: true, | ||
| toastMessage: customToastMessage, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| return expectSaga(putConfigWorker, action) | ||
| .withState(mockState) | ||
| .provide([[matchers.call.fn(putServerConfiguration), mockResponse]]) | ||
| .put(getOAuth2ConfigResponse({ config: mockResponse })) | ||
| .put(updateToast(true, 'success', customToastMessage)) | ||
| .put(putConfigWorkerResponse()) | ||
| .run() | ||
| }) | ||
|
|
||
| // eslint-disable-next-line jest/expect-expect | ||
| it('should not dispatch custom toast message on error', () => { | ||
| const customToastMessage = 'Please relogin to view cedarling changes' | ||
| const mockError = new Error('Network error') | ||
| const action = { | ||
| type: 'auth/putConfigWorker', | ||
| payload: { | ||
| ...mockConfig, | ||
| _meta: { | ||
| cedarlingLogTypeChanged: true, | ||
| toastMessage: customToastMessage, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| return expectSaga(putConfigWorker, action) | ||
| .withState(mockState) | ||
| .provide([[matchers.call.fn(putServerConfiguration), throwError(mockError)]]) | ||
| .not.put(updateToast(true, 'success', customToastMessage)) | ||
| .put(updateToast(true, 'error')) | ||
| .put(putConfigWorkerResponse()) | ||
| .run() | ||
| }) | ||
| }) | ||
|
|
||
| describe('when cedarlingLogType does not change', () => { | ||
| // eslint-disable-next-line jest/expect-expect | ||
| it('should dispatch generic success toast when no metadata provided', () => { | ||
| const action = { | ||
| type: 'auth/putConfigWorker', | ||
| payload: mockConfig, | ||
| } | ||
|
|
||
| return expectSaga(putConfigWorker, action) | ||
| .withState(mockState) | ||
| .provide([[matchers.call.fn(putServerConfiguration), mockResponse]]) | ||
| .put(getOAuth2ConfigResponse({ config: mockResponse })) | ||
| .put(updateToast(true, 'success')) | ||
| .put(putConfigWorkerResponse()) | ||
| .run() | ||
| }) | ||
|
|
||
| // eslint-disable-next-line jest/expect-expect | ||
| it('should dispatch generic success toast when cedarlingLogTypeChanged is false', () => { | ||
| const action = { | ||
| type: 'auth/putConfigWorker', | ||
| payload: { | ||
| ...mockConfig, | ||
| _meta: { | ||
| cedarlingLogTypeChanged: false, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| return expectSaga(putConfigWorker, action) | ||
| .withState(mockState) | ||
| .provide([[matchers.call.fn(putServerConfiguration), mockResponse]]) | ||
| .put(getOAuth2ConfigResponse({ config: mockResponse })) | ||
| .put(updateToast(true, 'success')) | ||
| .put(putConfigWorkerResponse()) | ||
| .run() | ||
| }) | ||
|
|
||
| // eslint-disable-next-line jest/expect-expect | ||
| it('should dispatch generic success toast when toastMessage is undefined', () => { | ||
| const action = { | ||
| type: 'auth/putConfigWorker', | ||
| payload: { | ||
| ...mockConfig, | ||
| _meta: { | ||
| cedarlingLogTypeChanged: true, | ||
| toastMessage: undefined, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| return expectSaga(putConfigWorker, action) | ||
| .withState(mockState) | ||
| .provide([[matchers.call.fn(putServerConfiguration), mockResponse]]) | ||
| .put(getOAuth2ConfigResponse({ config: mockResponse })) | ||
| .put(updateToast(true, 'success')) | ||
| .put(putConfigWorkerResponse()) | ||
| .run() | ||
| }) | ||
| }) | ||
|
|
||
| describe('error handling', () => { | ||
| // eslint-disable-next-line jest/expect-expect | ||
| it('should dispatch error toast on failure', () => { | ||
| const mockError = new Error('API Error') | ||
| const action = { | ||
| type: 'auth/putConfigWorker', | ||
| payload: mockConfig, | ||
| } | ||
|
|
||
| return expectSaga(putConfigWorker, action) | ||
| .withState(mockState) | ||
| .provide([[matchers.call.fn(putServerConfiguration), throwError(mockError)]]) | ||
| .not.put(getOAuth2ConfigResponse({ config: mockResponse })) | ||
| .put(updateToast(true, 'error')) | ||
| .put(putConfigWorkerResponse()) | ||
| .run() | ||
| }) | ||
| }) | ||
|
|
||
| describe('metadata extraction', () => { | ||
| // eslint-disable-next-line jest/expect-expect | ||
| it('should not send _meta to the API', () => { | ||
| const action = { | ||
| type: 'auth/putConfigWorker', | ||
| payload: { | ||
| ...mockConfig, | ||
| _meta: { | ||
| cedarlingLogTypeChanged: true, | ||
| toastMessage: 'Test message', | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| return expectSaga(putConfigWorker, action) | ||
| .withState(mockState) | ||
| .provide([[matchers.call.fn(putServerConfiguration), mockResponse]]) | ||
| .call(putServerConfiguration, { | ||
| token: mockToken, | ||
| props: mockConfig, // Should NOT include _meta | ||
| }) | ||
| .run() | ||
| }) | ||
|
|
||
| // eslint-disable-next-line jest/expect-expect | ||
| it('should handle payload without _meta correctly', () => { | ||
| const action = { | ||
| type: 'auth/putConfigWorker', | ||
| payload: mockConfig, | ||
| } | ||
|
|
||
| return expectSaga(putConfigWorker, action) | ||
| .withState(mockState) | ||
| .provide([[matchers.call.fn(putServerConfiguration), mockResponse]]) | ||
| .call(putServerConfiguration, { | ||
| token: mockToken, | ||
| props: mockConfig, | ||
| }) | ||
| .put(getOAuth2ConfigResponse({ config: mockResponse })) | ||
| .put(updateToast(true, 'success')) | ||
| .run() | ||
| }) | ||
| }) | ||
|
|
||
| describe('response handling', () => { | ||
| // eslint-disable-next-line jest/expect-expect | ||
| it('should handle successful response with config update', () => { | ||
| const action = { | ||
| type: 'auth/putConfigWorker', | ||
| payload: mockConfig, | ||
| } | ||
|
|
||
| return expectSaga(putConfigWorker, action) | ||
| .withState(mockState) | ||
| .provide([[matchers.call.fn(putServerConfiguration), mockResponse]]) | ||
| .put(getOAuth2ConfigResponse({ config: mockResponse })) | ||
| .run() | ||
| }) | ||
|
|
||
| // eslint-disable-next-line jest/expect-expect | ||
| it('should always call putConfigWorkerResponse in finally block', () => { | ||
| const action = { | ||
| type: 'auth/putConfigWorker', | ||
| payload: mockConfig, | ||
| } | ||
|
|
||
| return expectSaga(putConfigWorker, action) | ||
| .withState(mockState) | ||
| .provide([[matchers.call.fn(putServerConfiguration), mockResponse]]) | ||
| .put(putConfigWorkerResponse()) | ||
| .run() | ||
| }) | ||
|
|
||
| // eslint-disable-next-line jest/expect-expect | ||
| it('should call putConfigWorkerResponse even on error', () => { | ||
| const mockError = new Error('API Error') | ||
| const action = { | ||
| type: 'auth/putConfigWorker', | ||
| payload: mockConfig, | ||
| } | ||
|
|
||
| return expectSaga(putConfigWorker, action) | ||
| .withState(mockState) | ||
| .provide([[matchers.call.fn(putServerConfiguration), throwError(mockError)]]) | ||
| .put(putConfigWorkerResponse()) | ||
| .run() | ||
| }) | ||
| }) | ||
| }) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| export const getPagingSize = (defaultSize: number = 10): number => { | ||
| // Guard against SSR/test environments where localStorage is unavailable | ||
| if (typeof window === 'undefined' || !window.localStorage) { | ||
| return defaultSize | ||
| } | ||
|
|
||
| try { | ||
| const stored = localStorage.getItem('gluu.pagingSize') | ||
|
|
||
| if (!stored) return defaultSize | ||
|
|
||
| const parsed = parseInt(stored, 10) | ||
| // Only return if it's a valid positive integer (>0) | ||
| if (!isNaN(parsed) && parsed > 0) { | ||
| return parsed | ||
| } | ||
|
|
||
| return defaultSize | ||
| } catch (error) { | ||
| // Silently handle localStorage errors (quota exceeded, privacy mode, etc.) | ||
| console.warn('Failed to read paging size from localStorage:', error) | ||
| return defaultSize | ||
| } | ||
| } | ||
|
|
||
| export const savePagingSize = (size: number): void => { | ||
| // Validate and coerce input to a positive integer | ||
| const validSize = Math.floor(size) | ||
| if (validSize <= 0) { | ||
| console.warn('Invalid paging size:', size, '- must be a positive integer') | ||
| return | ||
| } | ||
|
|
||
| // Guard against SSR/test environments where localStorage is unavailable | ||
| if (typeof window === 'undefined' || !window.localStorage) { | ||
| return | ||
| } | ||
|
|
||
| try { | ||
| localStorage.setItem('gluu.pagingSize', String(validSize)) | ||
| } catch (error) { | ||
| // Silently handle localStorage errors (quota exceeded, privacy mode, etc.) | ||
| console.warn('Failed to save paging size to localStorage:', error) | ||
| } | ||
| } |
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.