Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@
value="{{ title }}"
></tb-truncated-path>
<span class="controls">
<button
mat-icon-button
[disabled]="!seriesDataList || !seriesDataList.length || (newLineChart && !newLineChart.getIsViewBoxOverridden())"
(click)="resetDomain()"
[title]="
(newLineChart && !newLineChart.getIsViewBoxOverridden()) ?
'Line chart is already fitted to data. When data updates, the line chart '
+ 'will auto fit to its domain.' :
'Fit line chart domains to data'
"
i18n-aria-label="A button that resets line chart domain to the data"
aria-label="Fit line chart domains to data"
>
<mat-icon svgIcon="settings_overscan_24px"></mat-icon>
</button>
<button
mat-icon-button
class="pin-button"
Expand Down Expand Up @@ -64,22 +79,6 @@
<mat-icon svgIcon="line_weight_24px"></mat-icon>
<span>Toggle Y-axis log scale</span>
</button>
<button
mat-menu-item
[disabled]="!seriesDataList || !seriesDataList.length || (newLineChart && !newLineChart.getIsViewBoxOverridden())"
(click)="resetDomain()"
[title]="
(newLineChart && !newLineChart.getIsViewBoxOverridden) ?
'Line chart is already fitted to data. When data updates, the line chart '
+ 'will auto fit to its domain.' :
''
"
i18n-aria-label="A button that resets line chart domain to the data"
aria-label="Fit line chart domains to data"
>
<mat-icon svgIcon="settings_overscan_24px"></mat-icon>
<span>Fit domain to data</span>
</button>
<button
mat-menu-item
(click)="openDataDownloadDialog()"
Expand Down
88 changes: 49 additions & 39 deletions tensorboard/webapp/metrics/views/card_renderer/scalar_card_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -779,13 +779,16 @@ describe('scalar card', () => {
expect(visibleRunIds).toEqual(['run3']);
}));

describe('overflow menu', () => {
beforeEach(() => {
describe('controls', () => {
const ByCss = {
FIT_TO_DOMAIN: By.css('[aria-label="Fit line chart domains to data"]'),
};

it('resets domain when user clicks on reset button', fakeAsync(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checking, since this test case doesn't do any flush()ing, can fakeAsync be dropped?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used in the createComponent or one of these utils (I tried and it threw an error).

const runToSeries = {
run1: [
{wallTime: 100, value: 1, step: 333},
{wallTime: 101, value: 2, step: 555},
],
run1: [{wallTime: 100, value: 1, step: 333}],
run2: [{wallTime: 100, value: 1, step: 333}],
run3: [{wallTime: 100, value: 1, step: 333}],
};
provideMockCardRunToSeriesData(
selectSpy,
Expand All @@ -794,31 +797,6 @@ describe('scalar card', () => {
null /* metadataOverride */,
runToSeries
);
});

it('toggles yAxisType when you click on button in overflow menu', fakeAsync(() => {
const fixture = createComponent('card1');

openOverflowMenu(fixture);
getMenuButton('Toggle Y-axis log scale on line chart').click();
fixture.detectChanges();

const lineChartEl = fixture.debugElement.query(
By.directive(TestableLineChart)
);
expect(lineChartEl.componentInstance.yAxisType).toBe(YAxisType.LOG);

openOverflowMenu(fixture);
getMenuButton('Toggle Y-axis log scale on line chart').click();
fixture.detectChanges();

expect(lineChartEl.componentInstance.yAxisType).toBe(YAxisType.LINEAR);

// Clicking on overflow menu and mat button enqueue asyncs. Flush them.
flush();
}));

it('resets domain when user clicks on reset button', fakeAsync(() => {
const fixture = createComponent('card1');

const lineChartEl = fixture.debugElement.query(
Expand All @@ -829,14 +807,10 @@ describe('scalar card', () => {
'resetDomain'
);

openOverflowMenu(fixture);
getMenuButton('Fit line chart domains to data').click();
fixture.debugElement.query(ByCss.FIT_TO_DOMAIN).nativeElement.click();
fixture.detectChanges();

expect(resetDomainSpy).toHaveBeenCalledTimes(1);

// Clicking on overflow menu and mat button enqueue asyncs. Flush them.
flush();
}));

it('disables the resetDomain button when there are no runs', fakeAsync(() => {
Expand All @@ -850,11 +824,47 @@ describe('scalar card', () => {
);
const fixture = createComponent('card1');

const button = fixture.debugElement.query(ByCss.FIT_TO_DOMAIN);
expect(button.properties['disabled']).toBe(true);
}));
});

describe('overflow menu', () => {
beforeEach(() => {
const runToSeries = {
run1: [
{wallTime: 100, value: 1, step: 333},
{wallTime: 101, value: 2, step: 555},
],
};
provideMockCardRunToSeriesData(
selectSpy,
PluginType.SCALARS,
'card1',
null /* metadataOverride */,
runToSeries
);
});

it('toggles yAxisType when you click on button in overflow menu', fakeAsync(() => {
const fixture = createComponent('card1');

openOverflowMenu(fixture);
getMenuButton('Toggle Y-axis log scale on line chart').click();
fixture.detectChanges();

const lineChartEl = fixture.debugElement.query(
By.directive(TestableLineChart)
);
expect(lineChartEl.componentInstance.yAxisType).toBe(YAxisType.LOG);

openOverflowMenu(fixture);
const button = getMenuButton('Fit line chart domains to data');
expect(button.disabled).toBe(true);
getMenuButton('Toggle Y-axis log scale on line chart').click();
fixture.detectChanges();

expect(lineChartEl.componentInstance.yAxisType).toBe(YAxisType.LINEAR);

// Clicking on overflow menu enqueues async.
// Clicking on overflow menu and mat button enqueue asyncs. Flush them.
flush();
}));
});
Expand Down