From c7eef8ab49deb034567f050bdf99a012d8e24429 Mon Sep 17 00:00:00 2001 From: Bhushan Khope Date: Wed, 16 Oct 2024 16:21:42 -0400 Subject: [PATCH] fix tests for cell types module --- .../cde-visualization.component.html | 2 - .../cde-visualization.component.spec.ts | 68 +------------------ .../cell-types/cell-types.component.spec.ts | 48 +++++++++++++ .../visualization-header.component.ts | 5 -- 4 files changed, 49 insertions(+), 74 deletions(-) diff --git a/libs/cde-visualization/src/lib/cde-visualization/cde-visualization.component.html b/libs/cde-visualization/src/lib/cde-visualization/cde-visualization.component.html index 63b3519dc..dc31b3bf4 100644 --- a/libs/cde-visualization/src/lib/cde-visualization/cde-visualization.component.html +++ b/libs/cde-visualization/src/lib/cde-visualization/cde-visualization.component.html @@ -2,8 +2,6 @@ diff --git a/libs/cde-visualization/src/lib/cde-visualization/cde-visualization.component.spec.ts b/libs/cde-visualization/src/lib/cde-visualization/cde-visualization.component.spec.ts index 68b940f1f..1f670e9ad 100644 --- a/libs/cde-visualization/src/lib/cde-visualization/cde-visualization.component.spec.ts +++ b/libs/cde-visualization/src/lib/cde-visualization/cde-visualization.component.spec.ts @@ -1,17 +1,11 @@ -import { TestBed } from '@angular/core/testing'; -import { RenderComponentOptions, render, screen } from '@testing-library/angular'; -import userEvent from '@testing-library/user-event'; +import { RenderComponentOptions, render } from '@testing-library/angular'; import { mockDeep } from 'jest-mock-extended'; import embed, { Result } from 'vega-embed'; -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'; -import { FileSaverService } from '../services/file-saver/file-saver.service'; import { CdeVisualizationComponent } from './cde-visualization.component'; jest.mock('hra-node-dist-vis/docs/hra-node-dist-vis.wc.js', () => ({})); @@ -109,66 +103,6 @@ describe('CdeVisualizationComponent', () => { embedResult.view.signal.mockReturnThis(); }); - it('should update nodes when downloadNodes is called', async () => { - const { - fixture: { componentInstance: instance }, - } = await setup({ - componentInputs: { - ...sampleData, - nodes: sampleNodes, - }, - }); - - const fileSaver = TestBed.inject(FileSaverService); - const fileSaveSpy = jest.spyOn(fileSaver, 'saveCsv').mockReturnValue(undefined); - - const downloadNodesButton = screen.getByText('Nodes'); - await userEvent.click(downloadNodesButton); - expect(fileSaveSpy).toHaveBeenCalledWith(instance.loadedNodes(), 'nodes.csv'); - }); - - it('should update edges when downloadEdges is called', async () => { - const { - fixture: { componentInstance: instance }, - } = await setup({ - componentInputs: { - ...sampleData, - edges: sampleEdges, - }, - }); - - const fileSaver = TestBed.inject(FileSaverService); - const fileSaveSpy = jest.spyOn(fileSaver, 'saveCsv').mockReturnValue(undefined); - - const downloadEdgesButton = screen.getByText('Edges'); - await userEvent.click(downloadEdgesButton); - expect(fileSaveSpy).toHaveBeenCalledWith(instance.loadedEdges(), 'edges.csv'); - }); - - it('should update color map when downloadColorMap is called', async () => { - 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 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'); - }); - it('should reset cell types and increase reset counter', async () => { const { fixture: { componentInstance: instance }, diff --git a/libs/cde-visualization/src/lib/components/cell-types/cell-types.component.spec.ts b/libs/cde-visualization/src/lib/components/cell-types/cell-types.component.spec.ts index f022e76e2..b6a13c1cb 100644 --- a/libs/cde-visualization/src/lib/components/cell-types/cell-types.component.spec.ts +++ b/libs/cde-visualization/src/lib/components/cell-types/cell-types.component.spec.ts @@ -1,5 +1,6 @@ import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; import { MatCheckboxHarness } from '@angular/material/checkbox/testing'; +import { MatMenuHarness } from '@angular/material/menu/testing'; import { provideScrolling } from '@hra-ui/design-system/scrolling'; import { RenderComponentOptions, render, screen } from '@testing-library/angular'; import { CellTypeEntry } from '../../models/cell-type'; @@ -20,6 +21,53 @@ describe('CellTypesComponent', () => { }); } + it('should update nodes when downloadNodes is called', async () => { + const emitFn = jest.fn(); + const { fixture } = await setup({ + inputs: { cellTypes, cellTypesSelection }, + on: { + downloadNodes: emitFn, + }, + }); + const loader = TestbedHarnessEnvironment.loader(fixture); + const menu = await loader.getHarness(MatMenuHarness); + + await menu.clickItem({ text: /Download/ }, { text: /Cells CSV/ }); + expect(emitFn).toHaveBeenCalled(); + }); + + it('should update edges when downloadEdges is called', async () => { + const emitFn = jest.fn(); + const { fixture } = await setup({ + inputs: { cellTypes, cellTypesSelection }, + on: { + downloadEdges: emitFn, + }, + }); + + const loader = TestbedHarnessEnvironment.loader(fixture); + const menu = await loader.getHarness(MatMenuHarness); + + await menu.clickItem({ text: /Download/ }, { text: /Cell Links CSV/ }); + expect(emitFn).toHaveBeenCalled(); + }); + + it('should update color map when downloadColorMap is called', async () => { + const emitFn = jest.fn(); + const { fixture } = await setup({ + inputs: { cellTypes, cellTypesSelection }, + on: { + downloadColorMap: emitFn, + }, + }); + + const loader = TestbedHarnessEnvironment.loader(fixture); + const menu = await loader.getHarness(MatMenuHarness); + + await menu.clickItem({ text: /Download/ }, { text: /Cell Color Map CSV/ }); + expect(emitFn).toHaveBeenCalled(); + }); + it('should render the component', async () => { await setup({ componentInputs: { cellTypes, cellTypesSelection }, diff --git a/libs/cde-visualization/src/lib/components/visualization-header/visualization-header.component.ts b/libs/cde-visualization/src/lib/components/visualization-header/visualization-header.component.ts index d82488beb..78ac16dca 100644 --- a/libs/cde-visualization/src/lib/components/visualization-header/visualization-header.component.ts +++ b/libs/cde-visualization/src/lib/components/visualization-header/visualization-header.component.ts @@ -26,11 +26,6 @@ export class VisualizationHeaderComponent { /** Defines an output event for resetting all settings */ readonly resetAll = output(); - /** Defines an output event for downloading nodes */ - readonly downloadNodes = output(); - /** Defines an output event for downloading edges */ - readonly downloadEdges = output(); - /** Flag to check if reset info tooltip is open */ resetInfoOpen = false; /** Flag to check if embed info tooltip is open */