Skip to content

Commit

Permalink
Update the utils used to mock the redux state for testing (#6361)
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
rileyajones committed May 3, 2023
1 parent 7474a8d commit e166112
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 15 deletions.
2 changes: 1 addition & 1 deletion tensorboard/data/server/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ _checked_in_file_descriptor_set = "descriptor.bin"
rust_library(
name = "rustboard_core",
srcs = [
"lib.rs",
"blob_key.rs",
"cli.rs",
"cli/dynamic_logdir.rs",
Expand All @@ -42,6 +41,7 @@ rust_library(
"gcs/auth.rs",
"gcs/client.rs",
"gcs/logdir.rs",
"lib.rs",
"logdir.rs",
"masked_crc.rs",
"reservoir.rs",
Expand Down
1 change: 1 addition & 0 deletions tensorboard/webapp/notification_center/_redux/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ tf_ts_library(
srcs = [
"testing.ts",
],
visibility = ["//tensorboard/webapp/testing:__subpackages__"],
deps = [
":types",
],
Expand Down
2 changes: 2 additions & 0 deletions tensorboard/webapp/runs/views/runs_selector/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ tf_ng_module(
"//tensorboard/webapp:selectors",
"//tensorboard/webapp/runs/store:types",
"//tensorboard/webapp/runs/views/runs_table",
"//tensorboard/webapp/runs/views/runs_table:types",
"@npm//@angular/common",
"@npm//@angular/core",
"@npm//@ngrx/store",
Expand All @@ -38,6 +39,7 @@ tf_ts_library(
"//tensorboard/webapp/angular:expect_ngrx_store_testing",
"//tensorboard/webapp/runs/store:testing",
"//tensorboard/webapp/runs/views/runs_table",
"//tensorboard/webapp/runs/views/runs_table:types",
"//tensorboard/webapp/testing:utils",
"@npm//@angular/core",
"@npm//@angular/platform-browser",
Expand Down
15 changes: 14 additions & 1 deletion tensorboard/webapp/runs/views/runs_table/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ tf_sass_binary(
deps = ["//tensorboard/webapp/theme"],
)

tf_ts_library(
name = "types",
srcs = [
"types.ts",
],
deps = [
"//tensorboard/webapp/experiments:types",
"//tensorboard/webapp/runs/data_source",
"//tensorboard/webapp/runs/store:types",
],
)

tf_ng_module(
name = "runs_table",
srcs = [
Expand All @@ -41,7 +53,6 @@ tf_ng_module(
"runs_table_component.ts",
"runs_table_container.ts",
"runs_table_module.ts",
"types.ts",
],
assets = [
":regex_edit_dialog_styles",
Expand All @@ -52,6 +63,7 @@ tf_ng_module(
"runs_group_menu_button_component.ng.html",
],
deps = [
":types",
"//tensorboard/webapp:app_state",
"//tensorboard/webapp:selectors",
"//tensorboard/webapp/alert",
Expand Down Expand Up @@ -103,6 +115,7 @@ tf_ts_library(
],
deps = [
":runs_table",
":types",
"//tensorboard/webapp:app_state",
"//tensorboard/webapp:selectors",
"//tensorboard/webapp/alert/actions",
Expand Down
12 changes: 12 additions & 0 deletions tensorboard/webapp/testing/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,24 @@ tf_ts_library(
],
deps = [
"//tensorboard/plugins/debugger_v2/tf_debugger_v2_plugin/testing",
"//tensorboard/webapp:app_state",
"//tensorboard/webapp/alert/store:testing",
"//tensorboard/webapp/angular:expect_ngrx_store_testing",
"//tensorboard/webapp/app_routing/store:testing",
"//tensorboard/webapp/app_routing/store:types",
"//tensorboard/webapp/core/testing",
"//tensorboard/webapp/experiments/store:testing",
"//tensorboard/webapp/experiments/store:types",
"//tensorboard/webapp/feature_flag/store:testing",
"//tensorboard/webapp/feature_flag/store:types",
"//tensorboard/webapp/hparams/_redux:testing",
"//tensorboard/webapp/metrics:test_lib",
"//tensorboard/webapp/metrics/store",
"//tensorboard/webapp/notification_center/_redux:testing",
"//tensorboard/webapp/notification_center/_redux:types",
"//tensorboard/webapp/persistent_settings/_redux:testing",
"//tensorboard/webapp/runs/store:testing",
"//tensorboard/webapp/runs/store:types",
"//tensorboard/webapp/settings:testing",
"@npm//@ngrx/store",
],
Expand Down
77 changes: 64 additions & 13 deletions tensorboard/webapp/testing/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,78 @@ import {
buildAlertState,
buildStateFromAlertState,
} from '../alert/store/testing';
import {APP_ROUTING_FEATURE_KEY} from '../app_routing/store/app_routing_types';
import {
buildAppRoutingState,
buildStateFromAppRoutingState,
} from '../app_routing/store/testing';
import {State} from '../app_state';
import {createState as createCoreState} from '../core/testing';
import {buildFeatureFlagState} from '../feature_flag/store/testing';
import {EXPERIMENTS_FEATURE_KEY} from '../experiments/store/experiments_types';
import {
buildExperimentState,
buildStateFromExperimentsState,
} from '../experiments/store/testing';
import {FEATURE_FLAG_FEATURE_KEY} from '../feature_flag/store/feature_flag_types';
import {
buildFeatureFlagState,
buildState as buildStateFromFeatureFlagsState,
} from '../feature_flag/store/testing';
import {
buildHparamsState,
buildStateFromHparamsState,
} from '../hparams/_redux/testing';
import {METRICS_FEATURE_KEY} from '../metrics/store';
import {appStateFromMetricsState, buildMetricsState} from '../metrics/testing';
import {NOTIFICATION_FEATURE_KEY} from '../notification_center/_redux/notification_center_types';
import {
buildNotificationState,
buildStateFromNotificationState,
} from '../notification_center/_redux/testing';
import {
buildPersistentSettingsState,
buildStateFromPersistentSettingsState,
} from '../persistent_settings/_redux/testing';
import {createSettingsState} from '../settings/testing';
import {RUNS_FEATURE_KEY} from '../runs/store/runs_types';
import {buildRunsState, buildStateFromRunsState} from '../runs/store/testing';
import {
createState as createSettings,
createSettingsState,
} from '../settings/testing';

export function buildMockState(overrides: Partial<State> = {}): State {
return {
...createDebuggerState(),
...buildFeatureFlagState(overrides[FEATURE_FLAG_FEATURE_KEY]),
...buildStateFromAlertState(buildAlertState({})),
...buildStateFromPersistentSettingsState(buildPersistentSettingsState({})),
...createCoreState(),
...appStateFromMetricsState(
buildMetricsState(overrides[METRICS_FEATURE_KEY])
),
...createSettings(createSettingsState()),
...buildStateFromRunsState(
buildRunsState(
overrides[RUNS_FEATURE_KEY]?.data,
overrides[RUNS_FEATURE_KEY]?.ui
)
),
...buildStateFromExperimentsState(
buildExperimentState(overrides[EXPERIMENTS_FEATURE_KEY]?.data)
),
...buildStateFromAppRoutingState(
buildAppRoutingState(overrides[APP_ROUTING_FEATURE_KEY])
),
...buildStateFromFeatureFlagsState(buildFeatureFlagState()),
...buildStateFromHparamsState(buildHparamsState()),
...buildStateFromNotificationState(
buildNotificationState(overrides[NOTIFICATION_FEATURE_KEY] || {})
),
};
}

export function provideMockTbStore() {
return provideMockStore({
initialState: {
...createDebuggerState(),
...buildFeatureFlagState(),
...buildStateFromAlertState(buildAlertState({})),
...buildStateFromPersistentSettingsState(
buildPersistentSettingsState({})
),
...createCoreState(),
...appStateFromMetricsState(buildMetricsState()),
...createSettingsState(),
},
initialState: buildMockState(),
});
}

0 comments on commit e166112

Please sign in to comment.