Skip to content

Commit 4023658

Browse files
authored
[Global pins] Correct the incorrect name change and add test cases (#6840)
## Motivation for features / changes This PR fixes the renaming in #6831 and adds test cases to make the test robust. ## Technical description of changes * Tried to rename `disableSavingPins` to `removeSavedPinsOnDisable`, but #6831 accidentally changed `removeAllPins` to `removeSavedPinsOnDisable`. ## Screenshots of UI changes (or N/A) ## Detailed steps to verify changes work correctly (as executed by you) * Added test cases + cl TAP presubmit passes ## Alternate designs / implementations considered (or N/A)
1 parent 9f51a30 commit 4023658

File tree

3 files changed

+92
-2
lines changed

3 files changed

+92
-2
lines changed

tensorboard/webapp/metrics/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ tf_ts_library(
110110
"//tensorboard/webapp/angular:expect_angular_core_testing",
111111
"//tensorboard/webapp/angular:expect_angular_platform_browser_animations",
112112
"//tensorboard/webapp/angular:expect_angular_platform_browser_dynamic_testing",
113+
"//tensorboard/webapp/feature_flag",
113114
"//tensorboard/webapp/metrics/store:metrics_initial_state_provider",
114115
"//tensorboard/webapp/metrics/store:types",
115116
"//tensorboard/webapp/metrics/views",

tensorboard/webapp/metrics/effects/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ export class MetricsEffects implements OnInitEffects {
333333
})
334334
);
335335

336-
private readonly removeSavedPinsOnDisable$ = this.actions$.pipe(
336+
private readonly removeAllPins$ = this.actions$.pipe(
337337
ofType(actions.metricsClearAllPinnedCards),
338338
withLatestFrom(
339339
this.store.select(selectors.getEnableGlobalPins),
@@ -356,7 +356,7 @@ export class MetricsEffects implements OnInitEffects {
356356
})
357357
);
358358

359-
private readonly disableSavingPins$ = this.actions$.pipe(
359+
private readonly removeSavedPinsOnDisable$ = this.actions$.pipe(
360360
ofType(actions.metricsEnableSavingPinsToggled),
361361
withLatestFrom(
362362
this.store.select(selectors.getEnableGlobalPins),
@@ -423,6 +423,10 @@ export class MetricsEffects implements OnInitEffects {
423423
/**
424424
* Subscribes to: metricsClearAllPinnedCards.
425425
*/
426+
this.removeAllPins$,
427+
/**
428+
* Subscribes to: metricsEnableSavingPinsToggled.
429+
*/
426430
this.removeSavedPinsOnDisable$
427431
);
428432
},

tensorboard/webapp/metrics/effects/metrics_effects_test.ts

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,22 @@ describe('metrics effects', () => {
918918
expect(saveScalarPinSpy).not.toHaveBeenCalled();
919919
expect(removeScalarPinSpy).not.toHaveBeenCalled();
920920
});
921+
922+
it('does not pin the card if getMetricsSavingPinsEnabled is false', () => {
923+
store.overrideSelector(selectors.getMetricsSavingPinsEnabled, false);
924+
store.refreshState();
925+
926+
actions$.next(
927+
actions.cardPinStateToggled({
928+
cardId: 'card1',
929+
wasPinned: false,
930+
canCreateNewPins: true,
931+
})
932+
);
933+
934+
expect(saveScalarPinSpy).not.toHaveBeenCalled();
935+
expect(removeScalarPinSpy).not.toHaveBeenCalled();
936+
});
921937
});
922938

923939
describe('loadSavedPins', () => {
@@ -984,6 +1000,19 @@ describe('metrics effects', () => {
9841000

9851001
expect(actualActions).toEqual([]);
9861002
});
1003+
1004+
it('does not load saved pins if getMetricsSavingPinsEnabled is false', () => {
1005+
getSavedScalarPinsSpy = spyOn(
1006+
savedPinsDataSource,
1007+
'getSavedScalarPins'
1008+
).and.returnValue(['tagA', 'tagB']);
1009+
store.overrideSelector(selectors.getMetricsSavingPinsEnabled, false);
1010+
store.refreshState();
1011+
1012+
actions$.next(TEST_ONLY.initAction());
1013+
1014+
expect(actualActions).toEqual([]);
1015+
});
9871016
});
9881017

9891018
describe('removeAllPins', () => {
@@ -1021,6 +1050,62 @@ describe('metrics effects', () => {
10211050

10221051
expect(removeAllScalarPinsSpy).not.toHaveBeenCalled();
10231052
});
1053+
1054+
it('does not remove pins if getMetricsSavingPinsEnabled is false', () => {
1055+
store.overrideSelector(selectors.getMetricsSavingPinsEnabled, false);
1056+
store.refreshState();
1057+
1058+
actions$.next(actions.metricsClearAllPinnedCards());
1059+
1060+
expect(removeAllScalarPinsSpy).not.toHaveBeenCalled();
1061+
});
1062+
});
1063+
1064+
describe('removeSavedPinsOnDisable', () => {
1065+
let removeAllScalarPinsSpy: jasmine.Spy;
1066+
1067+
beforeEach(() => {
1068+
removeAllScalarPinsSpy = spyOn(
1069+
savedPinsDataSource,
1070+
'removeAllScalarPins'
1071+
);
1072+
store.overrideSelector(selectors.getEnableGlobalPins, true);
1073+
store.overrideSelector(selectors.getMetricsSavingPinsEnabled, false);
1074+
store.refreshState();
1075+
});
1076+
1077+
it('removes all pins by calling metricsEnableSavingPinsToggled method', () => {
1078+
actions$.next(actions.metricsEnableSavingPinsToggled());
1079+
1080+
expect(removeAllScalarPinsSpy).toHaveBeenCalled();
1081+
});
1082+
1083+
it('does not remove pins if getEnableGlobalPins is false', () => {
1084+
store.overrideSelector(selectors.getEnableGlobalPins, false);
1085+
store.refreshState();
1086+
1087+
actions$.next(actions.metricsEnableSavingPinsToggled());
1088+
1089+
expect(removeAllScalarPinsSpy).not.toHaveBeenCalled();
1090+
});
1091+
1092+
it('does not remove pins if getShouldPersistSettings is false', () => {
1093+
store.overrideSelector(selectors.getShouldPersistSettings, false);
1094+
store.refreshState();
1095+
1096+
actions$.next(actions.metricsEnableSavingPinsToggled());
1097+
1098+
expect(removeAllScalarPinsSpy).not.toHaveBeenCalled();
1099+
});
1100+
1101+
it('does not remove pins if getMetricsSavingPinsEnabled is true', () => {
1102+
store.overrideSelector(selectors.getMetricsSavingPinsEnabled, true);
1103+
store.refreshState();
1104+
1105+
actions$.next(actions.metricsEnableSavingPinsToggled());
1106+
1107+
expect(removeAllScalarPinsSpy).not.toHaveBeenCalled();
1108+
});
10241109
});
10251110
});
10261111
});

0 commit comments

Comments
 (0)