1
+ import { saveToLocalStorage , storeBuilder } from "../store/store" ;
2
+ import {
3
+ removeCustomAggregator ,
4
+ selectAggregator ,
5
+ settingsSlice ,
6
+ setUpdateInterval ,
7
+ toggleAutoUpdate
8
+ } from "../store/settingsSlice" ;
9
+ import default_available_aggregators from "../aggregators-list" ;
10
+ import { initStore } from "./helpers" ;
11
+
12
+ describe ( 'Store Initialization' , ( ) => {
13
+ it ( 'init with settings initialState without local storage' , ( ) => {
14
+ const store = initStore ( ) ;
15
+
16
+ expect ( store . getState ( ) . settings ) . toEqual ( settingsSlice . getInitialState ( ) ) ;
17
+ } ) ;
18
+
19
+ it ( 'init with local storage saved state' , ( ) => {
20
+ let aggregators = [ ...default_available_aggregators , "https://aggregator.test" ] ;
21
+ let expected = {
22
+ settings : {
23
+ ...settingsSlice . getInitialState ( ) ,
24
+ selectedAggregator : aggregators . at ( aggregators . length - 1 ) ,
25
+ availableAggregators : aggregators ,
26
+ updateInterval : 12345 ,
27
+ }
28
+ } ;
29
+ saveToLocalStorage ( expected ) ;
30
+ const store = storeBuilder ( ) ;
31
+
32
+ expect ( store . getState ( ) ) . toEqual ( expected ) ;
33
+ } ) ;
34
+
35
+ it ( 'Can toggle autoUpdate' , ( ) => {
36
+ const store = initStore ( ) ;
37
+
38
+ store . dispatch ( toggleAutoUpdate ( ) ) ;
39
+ expect ( store . getState ( ) . settings . autoUpdate ) . toEqual ( false ) ;
40
+
41
+ store . dispatch ( toggleAutoUpdate ( ) ) ;
42
+ expect ( store . getState ( ) . settings . autoUpdate ) . toEqual ( true ) ;
43
+ } ) ;
44
+
45
+ it ( 'Can change updateInterval' , ( ) => {
46
+ const store = initStore ( ) ;
47
+ const expected = 124325 ;
48
+
49
+ store . dispatch ( setUpdateInterval ( expected ) ) ;
50
+ expect ( store . getState ( ) . settings . updateInterval ) . toEqual ( expected ) ;
51
+ } ) ;
52
+
53
+ it ( 'Can change selectedAggregator' , ( ) => {
54
+ const store = initStore ( ) ;
55
+ const expected = default_available_aggregators [ 2 ] ;
56
+
57
+ store . dispatch ( selectAggregator ( expected ) ) ;
58
+ expect ( store . getState ( ) . settings . selectedAggregator ) . toEqual ( expected ) ;
59
+ } ) ;
60
+
61
+ it ( 'Add a custom aggregator when selectAggregator is called with an unknown aggregator' , ( ) => {
62
+ const store = initStore ( ) ;
63
+ const expected = "http://aggregator.test" ;
64
+
65
+ store . dispatch ( selectAggregator ( expected ) ) ;
66
+ expect ( store . getState ( ) . settings . selectedAggregator ) . toEqual ( expected ) ;
67
+ expect ( store . getState ( ) . settings . availableAggregators ) . toContain ( expected ) ;
68
+ } ) ;
69
+
70
+ it ( 'Can\'t remove a default aggregator' , ( ) => {
71
+ const store = initStore ( ) ;
72
+
73
+ store . dispatch ( removeCustomAggregator ( default_available_aggregators [ 0 ] ) ) ;
74
+ expect ( store . getState ( ) . settings . availableAggregators ) . toContain ( default_available_aggregators [ 0 ] ) ;
75
+ } ) ;
76
+
77
+ it ( 'Can remove a custom aggregator' , ( ) => {
78
+ const customAggregator = "http://aggregator.test" ;
79
+ const store = initStore ( {
80
+ settings : {
81
+ ...settingsSlice . getInitialState ( ) ,
82
+ selectedAggregator : customAggregator ,
83
+ availableAggregators : [ ...default_available_aggregators , customAggregator ] ,
84
+ }
85
+ } ) ;
86
+
87
+ store . dispatch ( removeCustomAggregator ( customAggregator ) ) ;
88
+ expect ( store . getState ( ) . settings . availableAggregators ) . not . toContain ( customAggregator ) ;
89
+ } ) ;
90
+ } ) ;
0 commit comments