| b69ab31 | | | 1 | /** |
| b69ab31 | | | 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| b69ab31 | | | 3 | * |
| b69ab31 | | | 4 | * This source code is licensed under the MIT license found in the |
| b69ab31 | | | 5 | * LICENSE file in the root directory of this source tree. |
| b69ab31 | | | 6 | */ |
| b69ab31 | | | 7 | |
| b69ab31 | | | 8 | import {act, render, screen} from '@testing-library/react'; |
| b69ab31 | | | 9 | import App from '../App'; |
| b69ab31 | | | 10 | import platform from '../platform'; |
| b69ab31 | | | 11 | import {CommitInfoTestUtils} from '../testQueries'; |
| b69ab31 | | | 12 | import { |
| b69ab31 | | | 13 | COMMIT, |
| b69ab31 | | | 14 | expectMessageSentToServer, |
| b69ab31 | | | 15 | simulateCommits, |
| b69ab31 | | | 16 | simulateRepoConnected, |
| b69ab31 | | | 17 | } from '../testUtils'; |
| b69ab31 | | | 18 | |
| b69ab31 | | | 19 | describe('persistAtomToLocalStorageEffect', () => { |
| b69ab31 | | | 20 | const getTemporary = jest.fn(); |
| b69ab31 | | | 21 | const setTemporary = jest.fn(); |
| b69ab31 | | | 22 | |
| b69ab31 | | | 23 | beforeEach(() => { |
| b69ab31 | | | 24 | platform.getPersistedState = getTemporary; |
| b69ab31 | | | 25 | platform.setPersistedState = setTemporary; |
| b69ab31 | | | 26 | getTemporary.mockReset(); |
| b69ab31 | | | 27 | setTemporary.mockReset(); |
| b69ab31 | | | 28 | |
| b69ab31 | | | 29 | getTemporary.mockImplementation(() => null); |
| b69ab31 | | | 30 | setTemporary.mockImplementation(() => null); |
| b69ab31 | | | 31 | |
| b69ab31 | | | 32 | render(<App />); |
| b69ab31 | | | 33 | |
| b69ab31 | | | 34 | act(() => { |
| b69ab31 | | | 35 | simulateRepoConnected(); |
| b69ab31 | | | 36 | expectMessageSentToServer({ |
| b69ab31 | | | 37 | type: 'subscribe', |
| b69ab31 | | | 38 | kind: 'smartlogCommits', |
| b69ab31 | | | 39 | subscriptionID: expect.anything(), |
| b69ab31 | | | 40 | }); |
| b69ab31 | | | 41 | simulateCommits({ |
| b69ab31 | | | 42 | value: [ |
| b69ab31 | | | 43 | COMMIT('1', 'some public base', '0', {phase: 'public'}), |
| b69ab31 | | | 44 | COMMIT('a', 'My Commit', '1'), |
| b69ab31 | | | 45 | COMMIT('b', 'Another Commit', 'a', {isDot: true}), |
| b69ab31 | | | 46 | ], |
| b69ab31 | | | 47 | }); |
| b69ab31 | | | 48 | }); |
| b69ab31 | | | 49 | }); |
| b69ab31 | | | 50 | |
| b69ab31 | | | 51 | it('saves state to local storage', () => { |
| b69ab31 | | | 52 | expect(screen.getByTestId('commit-info-view')).toBeInTheDocument(); |
| b69ab31 | | | 53 | |
| b69ab31 | | | 54 | act(() => { |
| b69ab31 | | | 55 | CommitInfoTestUtils.openCommitInfoSidebar(); // toggle |
| b69ab31 | | | 56 | }); |
| b69ab31 | | | 57 | |
| b69ab31 | | | 58 | expect(screen.queryByTestId('commit-info-view')).not.toBeInTheDocument(); |
| b69ab31 | | | 59 | |
| b69ab31 | | | 60 | expect(platform.setPersistedState).toHaveBeenCalledWith( |
| b69ab31 | | | 61 | 'isl.drawer-state', |
| b69ab31 | | | 62 | expect.objectContaining({ |
| b69ab31 | | | 63 | right: {collapsed: true, size: 500}, |
| b69ab31 | | | 64 | }), |
| b69ab31 | | | 65 | ); |
| b69ab31 | | | 66 | |
| b69ab31 | | | 67 | act(() => { |
| b69ab31 | | | 68 | CommitInfoTestUtils.openCommitInfoSidebar(); // toggle |
| b69ab31 | | | 69 | }); |
| b69ab31 | | | 70 | |
| b69ab31 | | | 71 | expect(platform.setPersistedState).toHaveBeenCalledWith( |
| b69ab31 | | | 72 | 'isl.drawer-state', |
| b69ab31 | | | 73 | expect.objectContaining({ |
| b69ab31 | | | 74 | right: {collapsed: false, size: 500}, |
| b69ab31 | | | 75 | }), |
| b69ab31 | | | 76 | ); |
| b69ab31 | | | 77 | }); |
| b69ab31 | | | 78 | |
| b69ab31 | | | 79 | it.skip('loads state on startup', () => { |
| b69ab31 | | | 80 | // mock seems to happen too late to capture the getPersistedState call. |
| b69ab31 | | | 81 | // but I verified that getPersistedState is called using console log. |
| b69ab31 | | | 82 | expect(platform.getPersistedState).toHaveBeenCalledWith('isl.drawer-state'); |
| b69ab31 | | | 83 | }); |
| b69ab31 | | | 84 | }); |