Skip to content

Commit e166112

Browse files
authored
Update the utils used to mock the redux state for testing (#6361)
## Motivation for features / changes I'm working on a change downstream that involves using a huge chunk of the state and this will make it much easier to test. ## Technical description of changes Some of the mocks were just wrong before. None of the pieces of state supported being overridden. ## Screenshots of UI changes (or N/A) N/A
1 parent 7474a8d commit e166112

File tree

6 files changed

+94
-15
lines changed

6 files changed

+94
-15
lines changed

tensorboard/data/server/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ _checked_in_file_descriptor_set = "descriptor.bin"
2929
rust_library(
3030
name = "rustboard_core",
3131
srcs = [
32-
"lib.rs",
3332
"blob_key.rs",
3433
"cli.rs",
3534
"cli/dynamic_logdir.rs",
@@ -42,6 +41,7 @@ rust_library(
4241
"gcs/auth.rs",
4342
"gcs/client.rs",
4443
"gcs/logdir.rs",
44+
"lib.rs",
4545
"logdir.rs",
4646
"masked_crc.rs",
4747
"reservoir.rs",

tensorboard/webapp/notification_center/_redux/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ tf_ts_library(
5555
srcs = [
5656
"testing.ts",
5757
],
58+
visibility = ["//tensorboard/webapp/testing:__subpackages__"],
5859
deps = [
5960
":types",
6061
],

tensorboard/webapp/runs/views/runs_selector/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ tf_ng_module(
1616
"//tensorboard/webapp:selectors",
1717
"//tensorboard/webapp/runs/store:types",
1818
"//tensorboard/webapp/runs/views/runs_table",
19+
"//tensorboard/webapp/runs/views/runs_table:types",
1920
"@npm//@angular/common",
2021
"@npm//@angular/core",
2122
"@npm//@ngrx/store",
@@ -38,6 +39,7 @@ tf_ts_library(
3839
"//tensorboard/webapp/angular:expect_ngrx_store_testing",
3940
"//tensorboard/webapp/runs/store:testing",
4041
"//tensorboard/webapp/runs/views/runs_table",
42+
"//tensorboard/webapp/runs/views/runs_table:types",
4143
"//tensorboard/webapp/testing:utils",
4244
"@npm//@angular/core",
4345
"@npm//@angular/platform-browser",

tensorboard/webapp/runs/views/runs_table/BUILD

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ tf_sass_binary(
3131
deps = ["//tensorboard/webapp/theme"],
3232
)
3333

34+
tf_ts_library(
35+
name = "types",
36+
srcs = [
37+
"types.ts",
38+
],
39+
deps = [
40+
"//tensorboard/webapp/experiments:types",
41+
"//tensorboard/webapp/runs/data_source",
42+
"//tensorboard/webapp/runs/store:types",
43+
],
44+
)
45+
3446
tf_ng_module(
3547
name = "runs_table",
3648
srcs = [
@@ -41,7 +53,6 @@ tf_ng_module(
4153
"runs_table_component.ts",
4254
"runs_table_container.ts",
4355
"runs_table_module.ts",
44-
"types.ts",
4556
],
4657
assets = [
4758
":regex_edit_dialog_styles",
@@ -52,6 +63,7 @@ tf_ng_module(
5263
"runs_group_menu_button_component.ng.html",
5364
],
5465
deps = [
66+
":types",
5567
"//tensorboard/webapp:app_state",
5668
"//tensorboard/webapp:selectors",
5769
"//tensorboard/webapp/alert",
@@ -103,6 +115,7 @@ tf_ts_library(
103115
],
104116
deps = [
105117
":runs_table",
118+
":types",
106119
"//tensorboard/webapp:app_state",
107120
"//tensorboard/webapp:selectors",
108121
"//tensorboard/webapp/alert/actions",

tensorboard/webapp/testing/BUILD

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,24 @@ tf_ts_library(
6767
],
6868
deps = [
6969
"//tensorboard/plugins/debugger_v2/tf_debugger_v2_plugin/testing",
70+
"//tensorboard/webapp:app_state",
7071
"//tensorboard/webapp/alert/store:testing",
7172
"//tensorboard/webapp/angular:expect_ngrx_store_testing",
73+
"//tensorboard/webapp/app_routing/store:testing",
74+
"//tensorboard/webapp/app_routing/store:types",
7275
"//tensorboard/webapp/core/testing",
76+
"//tensorboard/webapp/experiments/store:testing",
77+
"//tensorboard/webapp/experiments/store:types",
7378
"//tensorboard/webapp/feature_flag/store:testing",
79+
"//tensorboard/webapp/feature_flag/store:types",
80+
"//tensorboard/webapp/hparams/_redux:testing",
7481
"//tensorboard/webapp/metrics:test_lib",
82+
"//tensorboard/webapp/metrics/store",
83+
"//tensorboard/webapp/notification_center/_redux:testing",
84+
"//tensorboard/webapp/notification_center/_redux:types",
7585
"//tensorboard/webapp/persistent_settings/_redux:testing",
86+
"//tensorboard/webapp/runs/store:testing",
87+
"//tensorboard/webapp/runs/store:types",
7688
"//tensorboard/webapp/settings:testing",
7789
"@npm//@ngrx/store",
7890
],

tensorboard/webapp/testing/utils.ts

Lines changed: 64 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,78 @@ import {
1818
buildAlertState,
1919
buildStateFromAlertState,
2020
} from '../alert/store/testing';
21+
import {APP_ROUTING_FEATURE_KEY} from '../app_routing/store/app_routing_types';
22+
import {
23+
buildAppRoutingState,
24+
buildStateFromAppRoutingState,
25+
} from '../app_routing/store/testing';
26+
import {State} from '../app_state';
2127
import {createState as createCoreState} from '../core/testing';
22-
import {buildFeatureFlagState} from '../feature_flag/store/testing';
28+
import {EXPERIMENTS_FEATURE_KEY} from '../experiments/store/experiments_types';
29+
import {
30+
buildExperimentState,
31+
buildStateFromExperimentsState,
32+
} from '../experiments/store/testing';
33+
import {FEATURE_FLAG_FEATURE_KEY} from '../feature_flag/store/feature_flag_types';
34+
import {
35+
buildFeatureFlagState,
36+
buildState as buildStateFromFeatureFlagsState,
37+
} from '../feature_flag/store/testing';
38+
import {
39+
buildHparamsState,
40+
buildStateFromHparamsState,
41+
} from '../hparams/_redux/testing';
42+
import {METRICS_FEATURE_KEY} from '../metrics/store';
2343
import {appStateFromMetricsState, buildMetricsState} from '../metrics/testing';
44+
import {NOTIFICATION_FEATURE_KEY} from '../notification_center/_redux/notification_center_types';
45+
import {
46+
buildNotificationState,
47+
buildStateFromNotificationState,
48+
} from '../notification_center/_redux/testing';
2449
import {
2550
buildPersistentSettingsState,
2651
buildStateFromPersistentSettingsState,
2752
} from '../persistent_settings/_redux/testing';
28-
import {createSettingsState} from '../settings/testing';
53+
import {RUNS_FEATURE_KEY} from '../runs/store/runs_types';
54+
import {buildRunsState, buildStateFromRunsState} from '../runs/store/testing';
55+
import {
56+
createState as createSettings,
57+
createSettingsState,
58+
} from '../settings/testing';
59+
60+
export function buildMockState(overrides: Partial<State> = {}): State {
61+
return {
62+
...createDebuggerState(),
63+
...buildFeatureFlagState(overrides[FEATURE_FLAG_FEATURE_KEY]),
64+
...buildStateFromAlertState(buildAlertState({})),
65+
...buildStateFromPersistentSettingsState(buildPersistentSettingsState({})),
66+
...createCoreState(),
67+
...appStateFromMetricsState(
68+
buildMetricsState(overrides[METRICS_FEATURE_KEY])
69+
),
70+
...createSettings(createSettingsState()),
71+
...buildStateFromRunsState(
72+
buildRunsState(
73+
overrides[RUNS_FEATURE_KEY]?.data,
74+
overrides[RUNS_FEATURE_KEY]?.ui
75+
)
76+
),
77+
...buildStateFromExperimentsState(
78+
buildExperimentState(overrides[EXPERIMENTS_FEATURE_KEY]?.data)
79+
),
80+
...buildStateFromAppRoutingState(
81+
buildAppRoutingState(overrides[APP_ROUTING_FEATURE_KEY])
82+
),
83+
...buildStateFromFeatureFlagsState(buildFeatureFlagState()),
84+
...buildStateFromHparamsState(buildHparamsState()),
85+
...buildStateFromNotificationState(
86+
buildNotificationState(overrides[NOTIFICATION_FEATURE_KEY] || {})
87+
),
88+
};
89+
}
2990

3091
export function provideMockTbStore() {
3192
return provideMockStore({
32-
initialState: {
33-
...createDebuggerState(),
34-
...buildFeatureFlagState(),
35-
...buildStateFromAlertState(buildAlertState({})),
36-
...buildStateFromPersistentSettingsState(
37-
buildPersistentSettingsState({})
38-
),
39-
...createCoreState(),
40-
...appStateFromMetricsState(buildMetricsState()),
41-
...createSettingsState(),
42-
},
93+
initialState: buildMockState(),
4394
});
4495
}

0 commit comments

Comments
 (0)