diff options
Diffstat (limited to 'packages/shared/src/stores/__tests__/SharedStoreBase.test.ts')
-rw-r--r-- | packages/shared/src/stores/__tests__/SharedStoreBase.test.ts | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/packages/shared/src/stores/__tests__/SharedStoreBase.test.ts b/packages/shared/src/stores/__tests__/SharedStoreBase.test.ts new file mode 100644 index 0000000..64f5c6b --- /dev/null +++ b/packages/shared/src/stores/__tests__/SharedStoreBase.test.ts | |||
@@ -0,0 +1,76 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2022 Kristóf Marussy <kristof@marussy.com> | ||
3 | * | ||
4 | * This file is part of Sophie. | ||
5 | * | ||
6 | * Sophie is free software: you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU Affero General Public License as | ||
8 | * published by the Free Software Foundation, version 3. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU Affero General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU Affero General Public License | ||
16 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
17 | * | ||
18 | * SPDX-License-Identifier: AGPL-3.0-only | ||
19 | */ | ||
20 | |||
21 | import { unprotect } from 'mobx-state-tree'; | ||
22 | |||
23 | import SharedStoreBase from '../SharedStoreBase.js'; | ||
24 | |||
25 | import { testProfile, testService } from './__fixtures__/serviceFixtures.js'; | ||
26 | |||
27 | describe.each([true, false])( | ||
28 | 'when showLocationBar is %j', | ||
29 | (showLocationBar) => { | ||
30 | test('hides the location bar if there is no selected service', () => { | ||
31 | const sharedStore = SharedStoreBase.create({ | ||
32 | settings: { showLocationBar }, | ||
33 | }); | ||
34 | |||
35 | expect(sharedStore.alwaysHideLocationBar).toBe(true); | ||
36 | expect(sharedStore.alwaysShowLocationBar).toBe(false); | ||
37 | expect(sharedStore.locationBarVisible).toBe(false); | ||
38 | expect(sharedStore.canToggleLocationBar).toBe(false); | ||
39 | }); | ||
40 | |||
41 | describe('and there is a selected service', () => { | ||
42 | let sharedStore: SharedStoreBase; | ||
43 | |||
44 | beforeEach(() => { | ||
45 | sharedStore = SharedStoreBase.create({ | ||
46 | settings: { | ||
47 | selectedService: testService.id, | ||
48 | showLocationBar, | ||
49 | }, | ||
50 | profilesById: { testProfile }, | ||
51 | servicesById: { testService }, | ||
52 | }); | ||
53 | }); | ||
54 | |||
55 | test('shows the location bar if requested by the user', () => { | ||
56 | expect(sharedStore.alwaysHideLocationBar).toBe(false); | ||
57 | expect(sharedStore.alwaysShowLocationBar).toBe(false); | ||
58 | expect(sharedStore.locationBarVisible).toBe(showLocationBar); | ||
59 | expect(sharedStore.canToggleLocationBar).toBe(true); | ||
60 | }); | ||
61 | |||
62 | test('show the location bar if forced by the service', () => { | ||
63 | unprotect(sharedStore); | ||
64 | const service = sharedStore.settings.selectedService!; | ||
65 | Object.defineProperty(service, 'alwaysShowLocationBar', { | ||
66 | value: true, | ||
67 | }); | ||
68 | |||
69 | expect(sharedStore.alwaysHideLocationBar).toBe(false); | ||
70 | expect(sharedStore.alwaysShowLocationBar).toBe(true); | ||
71 | expect(sharedStore.locationBarVisible).toBe(true); | ||
72 | expect(sharedStore.canToggleLocationBar).toBe(false); | ||
73 | }); | ||
74 | }); | ||
75 | }, | ||
76 | ); | ||