forked from swiftlang/swift-docc-render
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppStore.spec.js
91 lines (80 loc) · 3.04 KB
/
AppStore.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**
* This source file is part of the Swift.org open source project
*
* Copyright (c) 2023 Apple Inc. and the Swift project authors
* Licensed under Apache License v2.0 with Runtime Library Exception
*
* See https://swift.org/LICENSE.txt for license information
* See https://swift.org/CONTRIBUTORS.txt for Swift project authors
*/
import AppStore from 'docc-render/stores/AppStore';
import ColorScheme from 'docc-render/constants/ColorScheme';
import ImageLoadingStrategy from 'docc-render/constants/ImageLoadingStrategy';
import Settings from 'docc-render/utils/settings';
describe('AppStore', () => {
it('has a default state', () => {
expect(AppStore.state).toEqual({
imageLoadingStrategy: ImageLoadingStrategy.lazy,
preferredColorScheme: ColorScheme.light,
supportsAutoColorScheme: false,
systemColorScheme: ColorScheme.light,
preferredLocale: null,
availableLocales: [],
});
});
it('has correct state in IDE mode', () => {
const originalTarget = process.env.VUE_APP_TARGET;
process.env.VUE_APP_TARGET = 'ide';
AppStore.reset();
expect(AppStore.state).toEqual({
imageLoadingStrategy: ImageLoadingStrategy.eager,
preferredColorScheme: ColorScheme.light,
supportsAutoColorScheme: false,
systemColorScheme: ColorScheme.light,
preferredLocale: null,
availableLocales: [],
});
// restore target
process.env.VUE_APP_TARGET = originalTarget;
});
describe('setImageLoadingStrategy', () => {
it('sets the `imageLoadingStrategy` state', () => {
AppStore.setImageLoadingStrategy(ImageLoadingStrategy.eager);
expect(AppStore.state.imageLoadingStrategy).toBe(ImageLoadingStrategy.eager);
});
});
describe('setPreferredColorScheme', () => {
it('sets the `preferredColorScheme` state', () => {
AppStore.setPreferredColorScheme(ColorScheme.auto);
expect(AppStore.state.preferredColorScheme).toBe(ColorScheme.auto);
expect(Settings.preferredColorScheme).toBe(ColorScheme.auto);
});
});
describe('setSystemColorScheme', () => {
it('sets the `systemColorScheme` state', () => {
AppStore.setSystemColorScheme(ColorScheme.dark);
expect(AppStore.state.systemColorScheme).toBe(ColorScheme.dark);
});
});
describe('syncPreferredColorScheme', () => {
it('sets the `syncPreferredColorScheme` state', () => {
AppStore.syncPreferredColorScheme();
expect(AppStore.state.preferredColorScheme).toBe(Settings.preferredColorScheme);
});
});
it('resets the state', () => {
AppStore.setImageLoadingStrategy(ImageLoadingStrategy.eager);
AppStore.setPreferredColorScheme(ColorScheme.auto);
AppStore.setSystemColorScheme(ColorScheme.dark);
AppStore.syncPreferredColorScheme();
AppStore.reset();
expect(AppStore.state).toEqual({
imageLoadingStrategy: ImageLoadingStrategy.lazy,
preferredColorScheme: ColorScheme.auto,
supportsAutoColorScheme: false,
systemColorScheme: ColorScheme.light,
preferredLocale: null,
availableLocales: [],
});
});
});