Skip to content

Commit

Permalink
fix tests for downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
bhushankhope committed Oct 2, 2024
1 parent d570345 commit b1b9df9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import userEvent from '@testing-library/user-event';
import { mockDeep } from 'jest-mock-extended';
import embed, { Result } from 'vega-embed';

import { provideScrolling } from '@hra-ui/design-system/scrolling';
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
import { MatMenuHarness } from '@angular/material/menu/testing';
import { rgbToHex } from '@hra-ui/design-system/color-picker';
import { provideScrolling } from '@hra-ui/design-system/scrolling';
import { ColorMapEntry, DEFAULT_COLOR_MAP_KEY, DEFAULT_COLOR_MAP_VALUE_KEY } from '../models/color-map';
import { EdgeEntry } from '../models/edge';
import { DEFAULT_NODE_TARGET_KEY, DEFAULT_NODE_TARGET_VALUE, NodeEntry } from '../models/node';
Expand Down Expand Up @@ -144,25 +146,26 @@ describe('CdeVisualizationComponent', () => {
});

it('should update color map when downloadColorMap is called', async () => {
const {
fixture: { componentInstance: instance },
} = await setup({
const { fixture } = await setup({
componentInputs: {
...sampleData,
nodes: sampleNodes,
colorMap: sampleColorMap,
},
});

const instance = fixture.componentInstance;
const processedColorMap = instance
.cellTypesAsColorMap()
.map((entry) => ({ ...entry, [instance.colorMapValueKey()]: rgbToHex(entry[instance.colorMapValueKey()]) }));

const fileSaver = TestBed.inject(FileSaverService);
const fileSaveSpy = jest.spyOn(fileSaver, 'saveCsv').mockReturnValue(undefined);

const downloadColorMapButton = screen.getByText('CSV');
await userEvent.click(downloadColorMapButton);
const loader = TestbedHarnessEnvironment.loader(fixture);
const menu = await loader.getHarness(MatMenuHarness);

await menu.clickItem({ text: /Download/ }, { text: /Cell Color Map CSV/ });
expect(fileSaveSpy).toHaveBeenCalledWith(processedColorMap, 'color-map.csv');
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<span class="cell-types-label">
Cell Types
<button mat-icon-button [matMenuTriggerFor]="menu" hraIconButtonSize="medium">
<button mat-icon-button [matMenuTriggerFor]="menu" hraIconButtonSize="medium" data-testid="trigger">
<mat-icon>more_vert</mat-icon>
</button>
<mat-menu #menu="matMenu">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ describe('NodeDistVisualizationComponent', () => {
[2, 0, 4, 3, 4, 5, 6],
];
const sampleCellTypes: CellTypeEntry[] = [
{ name: 'a', count: 2, color: [0, 0, 0] },
{ name: 'b', count: 4, color: [0, 1, 2] },
{ name: 'c', count: 6, color: [0, 1, 3] },
{ name: 'a', count: 2, color: [0, 0, 0], outgoingEdgeCount: 0 },
{ name: 'b', count: 4, color: [0, 1, 2], outgoingEdgeCount: 0 },
{ name: 'c', count: 6, color: [0, 1, 3], outgoingEdgeCount: 0 },
];
const sampleCellTypesSelection: string[] = [sampleCellTypes[0].name, sampleCellTypes[1].name];

Expand Down

0 comments on commit b1b9df9

Please sign in to comment.