|
37 | 37 | */ |
38 | 38 | import * as React from 'react'; |
39 | 39 | 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'; |
41 | 41 | import userEvent from '@testing-library/user-event'; |
42 | | - |
43 | 42 | import { CredentialsStorage } from '@app/Settings/CredentialsStorage'; |
44 | 43 |
|
45 | 44 | import { getFromLocalStorage, saveToLocalStorage } from '@app/utils/LocalStorage'; |
@@ -75,39 +74,39 @@ describe('<CredentialsStorage/>', () => { |
75 | 74 | expect(tree.toJSON()).toMatchSnapshot(); |
76 | 75 | }); |
77 | 76 |
|
78 | | - it('defaults to Session storage', async () => { |
| 77 | + it('defaults to Backend storage', async () => { |
79 | 78 | render(React.createElement(CredentialsStorage.content, null)); |
80 | 79 |
|
81 | 80 | expect(getFromLocalStorage).toHaveBeenCalledTimes(1); |
82 | 81 | expect(saveToLocalStorage).toHaveBeenCalledTimes(1); |
83 | | - expect(saveToLocalStorage).lastCalledWith(storageKey, sessionStorageValue); |
| 82 | + expect(saveToLocalStorage).lastCalledWith(storageKey, backendStorageValue); |
84 | 83 |
|
85 | | - expect(screen.getByText(sessionStorageValue)).toBeVisible(); |
86 | | - expect(screen.queryByText(backendStorageValue)).toBeFalsy(); |
| 84 | + expect(screen.getByText(backendStorageValue)).toBeVisible(); |
| 85 | + expect(screen.queryByText(sessionStorageValue)).toBeFalsy(); |
87 | 86 | }); |
88 | 87 |
|
89 | 88 | it('sets value to local storage when dropdown is clicked', async () => { |
90 | 89 | render(React.createElement(CredentialsStorage.content, null)); |
91 | 90 |
|
92 | 91 | expect(getFromLocalStorage).toHaveBeenCalledTimes(1); |
93 | 92 | expect(saveToLocalStorage).toHaveBeenCalledTimes(1); |
94 | | - expect(saveToLocalStorage).lastCalledWith(storageKey, sessionStorageValue); |
| 93 | + expect(saveToLocalStorage).lastCalledWith(storageKey, backendStorageValue); |
95 | 94 |
|
96 | 95 | userEvent.click(screen.getByRole('button')); |
97 | 96 |
|
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 |
99 | 98 | 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); |
102 | 101 |
|
103 | 102 | await waitFor(() => expect(ul).not.toBeVisible()); // expect selection menu to close after user clicks an option |
104 | 103 |
|
105 | 104 | // 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(); |
108 | 107 |
|
109 | 108 | expect(getFromLocalStorage).toHaveBeenCalledTimes(1); |
110 | 109 | expect(saveToLocalStorage).toHaveBeenCalledTimes(2); |
111 | | - expect(saveToLocalStorage).lastCalledWith(storageKey, backendStorageValue); |
| 110 | + expect(saveToLocalStorage).lastCalledWith(storageKey, sessionStorageValue); |
112 | 111 | }); |
113 | 112 | }); |
0 commit comments