forked from tensorflow/tensorboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
feature_flag_effects_test.ts
138 lines (119 loc) · 4.55 KB
/
feature_flag_effects_test.ts
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
import {TestBed} from '@angular/core/testing';
import {provideMockActions} from '@ngrx/effects/testing';
import {Action, Store} from '@ngrx/store';
import {MockStore, provideMockStore} from '@ngrx/store/testing';
import {ReplaySubject} from 'rxjs';
import {
TBFeatureFlagTestingModule,
TestingTBFeatureFlagDataSource,
} from '../../webapp_data_source/tb_feature_flag_testing';
import {partialFeatureFlagsLoaded} from '../actions/feature_flag_actions';
import {ForceSvgDataSource} from '../force_svg_data_source';
import {ForceSvgDataSourceModule} from '../force_svg_data_source_module';
import {getIsAutoDarkModeAllowed} from '../store/feature_flag_selectors';
import {State} from '../store/feature_flag_types';
import {buildFeatureFlag} from '../testing';
import {FeatureFlags} from '../types';
import {FeatureFlagEffects} from './feature_flag_effects';
describe('feature_flag_effects', () => {
let actions: ReplaySubject<Action>;
let store: MockStore<State>;
let dataSource: TestingTBFeatureFlagDataSource;
let forceSvgDataSource: ForceSvgDataSource;
let effects: FeatureFlagEffects;
beforeEach(async () => {
actions = new ReplaySubject<Action>(1);
await TestBed.configureTestingModule({
imports: [TBFeatureFlagTestingModule, ForceSvgDataSourceModule],
providers: [
provideMockActions(actions),
FeatureFlagEffects,
provideMockStore(),
],
}).compileComponents();
effects = TestBed.inject(FeatureFlagEffects);
store = TestBed.inject<Store<State>>(Store) as MockStore<State>;
dataSource = TestBed.inject(TestingTBFeatureFlagDataSource);
forceSvgDataSource = TestBed.inject(ForceSvgDataSource);
store.overrideSelector(getIsAutoDarkModeAllowed, false);
});
describe('getFeatureFlags$', () => {
let recordedActions: Action[];
beforeEach(() => {
recordedActions = [];
effects.getFeatureFlags$.subscribe((action) => {
recordedActions.push(action);
});
});
it('loads features from the data source on init', () => {
spyOn(dataSource, 'getFeatures').and.returnValue(
buildFeatureFlag({
enabledExperimentalPlugins: ['foo', 'bar'],
inColab: false,
})
);
actions.next(effects.ngrxOnInitEffects());
expect(recordedActions).toEqual([
partialFeatureFlagsLoaded({
features: buildFeatureFlag({
enabledExperimentalPlugins: ['foo', 'bar'],
inColab: false,
}),
}),
]);
});
it('calls updateForceSvgFlag when getFeatures returns a value for forceSvg', () => {
spyOn(dataSource, 'getFeatures').and.returnValue(
buildFeatureFlag({
forceSvg: true,
})
);
let updateSpy = spyOn(
forceSvgDataSource,
'updateForceSvgFlag'
).and.stub();
actions.next(effects.ngrxOnInitEffects());
expect(recordedActions).toEqual([
partialFeatureFlagsLoaded({
features: buildFeatureFlag({
forceSvg: true,
}),
}),
]);
expect(updateSpy).toHaveBeenCalledOnceWith(true);
});
it('gets forceSVG flag from ForceSvgDataSource when getFeatures returns no value for forceSvg', () => {
let featureFlags: Partial<FeatureFlags> = buildFeatureFlag();
delete featureFlags.forceSvg;
spyOn(dataSource, 'getFeatures').and.returnValue(featureFlags);
let updateSpy = spyOn(
forceSvgDataSource,
'updateForceSvgFlag'
).and.stub();
let getSpy = spyOn(forceSvgDataSource, 'getForceSvgFlag').and.returnValue(
true
);
actions.next(effects.ngrxOnInitEffects());
expect(recordedActions).toEqual([
partialFeatureFlagsLoaded({
features: buildFeatureFlag({
forceSvg: true,
}),
}),
]);
expect(getSpy).toHaveBeenCalledOnceWith();
expect(updateSpy).toHaveBeenCalledTimes(0);
});
});
});