Skip to content

Commit e5f2a05

Browse files
mergify[bot]tthvo
andauthored
fix(credentials): set backend storage as default (backport #672) (#674)
* fix(credentials): set backend storage as default (#672) (cherry picked from commit 7ba910e) # Conflicts: # src/test/Settings/CredentialsStorage.test.tsx * resolve conflict Co-authored-by: Thuan Vo <[email protected]>
1 parent 6e84a1c commit e5f2a05

File tree

4 files changed

+18
-20
lines changed

4 files changed

+18
-20
lines changed

src/app/Settings/CredentialsStorage.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import * as React from 'react';
4040
import { Link } from 'react-router-dom';
4141
import { Select, SelectOption, SelectVariant, Text } from '@patternfly/react-core';
42-
4342
import { UserSetting } from './Settings';
4443
import { getFromLocalStorage, saveToLocalStorage } from '@app/utils/LocalStorage';
4544

@@ -69,12 +68,12 @@ const getLocation = (key: string): Location => {
6968
return l;
7069
}
7170
}
72-
return Locations.BROWSER_SESSION;
71+
return Locations.BACKEND;
7372
};
7473

7574
const Component = () => {
7675
const [isExpanded, setExpanded] = React.useState(false);
77-
const [selection, setSelection] = React.useState(Locations.BROWSER_SESSION.key);
76+
const [selection, setSelection] = React.useState(Locations.BACKEND.key);
7877

7978
const handleSelect = React.useCallback(
8079
(_, selection) => {
@@ -87,7 +86,7 @@ const Component = () => {
8786
);
8887

8988
React.useEffect(() => {
90-
handleSelect(undefined, getFromLocalStorage('JMX_CREDENTIAL_LOCATION', Locations.BROWSER_SESSION.key));
89+
handleSelect(undefined, getFromLocalStorage('JMX_CREDENTIAL_LOCATION', Locations.BACKEND.key));
9190
}, [handleSelect, getFromLocalStorage]);
9291

9392
return (

src/app/Shared/Services/JmxCredentials.service.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class JmxCredentials {
5252
constructor(private readonly api: () => ApiService) {}
5353

5454
setCredential(targetId: string, username: string, password: string): Observable<boolean> {
55-
let location = getFromLocalStorage('JMX_CREDENTIAL_LOCATION', Locations.BROWSER_SESSION.key);
55+
let location = getFromLocalStorage('JMX_CREDENTIAL_LOCATION', Locations.BACKEND.key);
5656
switch (location) {
5757
case Locations.BACKEND.key:
5858
return this.api().postCredentials(`target.connectUrl == "${targetId}"`, username, password);
@@ -66,7 +66,7 @@ export class JmxCredentials {
6666
}
6767

6868
getCredential(targetId: string): Observable<Credential | undefined> {
69-
let location = getFromLocalStorage('JMX_CREDENTIAL_LOCATION', Locations.BROWSER_SESSION.key);
69+
let location = getFromLocalStorage('JMX_CREDENTIAL_LOCATION', Locations.BACKEND.key);
7070
switch (location) {
7171
case Locations.BACKEND.key:
7272
// if this is stored on the backend then Cryostat should be using those and not prompting us to request from the user

src/test/Settings/CredentialsStorage.test.tsx

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@
3737
*/
3838
import * as React from 'react';
3939
import renderer, { act } from 'react-test-renderer';
40-
import { render, cleanup, screen, waitFor, getByText, within } from '@testing-library/react';
40+
import { render, cleanup, screen, waitFor, within } from '@testing-library/react';
4141
import userEvent from '@testing-library/user-event';
42-
4342
import { CredentialsStorage } from '@app/Settings/CredentialsStorage';
4443

4544
import { getFromLocalStorage, saveToLocalStorage } from '@app/utils/LocalStorage';
@@ -75,39 +74,39 @@ describe('<CredentialsStorage/>', () => {
7574
expect(tree.toJSON()).toMatchSnapshot();
7675
});
7776

78-
it('defaults to Session storage', async () => {
77+
it('defaults to Backend storage', async () => {
7978
render(React.createElement(CredentialsStorage.content, null));
8079

8180
expect(getFromLocalStorage).toHaveBeenCalledTimes(1);
8281
expect(saveToLocalStorage).toHaveBeenCalledTimes(1);
83-
expect(saveToLocalStorage).lastCalledWith(storageKey, sessionStorageValue);
82+
expect(saveToLocalStorage).lastCalledWith(storageKey, backendStorageValue);
8483

85-
expect(screen.getByText(sessionStorageValue)).toBeVisible();
86-
expect(screen.queryByText(backendStorageValue)).toBeFalsy();
84+
expect(screen.getByText(backendStorageValue)).toBeVisible();
85+
expect(screen.queryByText(sessionStorageValue)).toBeFalsy();
8786
});
8887

8988
it('sets value to local storage when dropdown is clicked', async () => {
9089
render(React.createElement(CredentialsStorage.content, null));
9190

9291
expect(getFromLocalStorage).toHaveBeenCalledTimes(1);
9392
expect(saveToLocalStorage).toHaveBeenCalledTimes(1);
94-
expect(saveToLocalStorage).lastCalledWith(storageKey, sessionStorageValue);
93+
expect(saveToLocalStorage).lastCalledWith(storageKey, backendStorageValue);
9594

9695
userEvent.click(screen.getByRole('button'));
9796

98-
// as in the other test, the default is Session storage. click the dropdown and select Backend to change selection
97+
// the default is Backend storage. Click the dropdown and select Session (Browser Memory) to change selection
9998
const ul = await screen.findByRole('listbox');
100-
const backend = within(ul).getByText(backendStorageValue);
101-
userEvent.click(backend);
99+
const browserSession = within(ul).getByText(sessionStorageValue);
100+
userEvent.click(browserSession);
102101

103102
await waitFor(() => expect(ul).not.toBeVisible()); // expect selection menu to close after user clicks an option
104103

105104
// expect the selection to be visible, the other not
106-
expect(screen.getByText(backendStorageValue)).toBeVisible();
107-
expect(screen.queryByText(sessionStorageValue)).toBeFalsy();
105+
expect(screen.getByText(sessionStorageValue)).toBeVisible();
106+
expect(screen.queryByText(backendStorageValue)).toBeFalsy();
108107

109108
expect(getFromLocalStorage).toHaveBeenCalledTimes(1);
110109
expect(saveToLocalStorage).toHaveBeenCalledTimes(2);
111-
expect(saveToLocalStorage).lastCalledWith(storageKey, backendStorageValue);
110+
expect(saveToLocalStorage).lastCalledWith(storageKey, sessionStorageValue);
112111
});
113112
});

src/test/Settings/__snapshots__/CredentialsStorage.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ exports[`<CredentialsStorage/> renders correctly 1`] = `
2525
<span
2626
className="pf-c-select__toggle-text"
2727
>
28-
Session (Browser Memory)
28+
Backend
2929
</span>
3030
</div>
3131
<span

0 commit comments

Comments
 (0)