From 575e2b80df23950304d9da2d90dc326c3c6c400c Mon Sep 17 00:00:00 2001 From: Manuel Luypaert Date: Thu, 5 Sep 2024 10:12:52 +0100 Subject: [PATCH 1/4] Added unit testing for AlignmentEntryList component --- .../__tests__/AlignmentEntryList.test.tsx | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 webui/src/app/components/client/__tests__/AlignmentEntryList.test.tsx diff --git a/webui/src/app/components/client/__tests__/AlignmentEntryList.test.tsx b/webui/src/app/components/client/__tests__/AlignmentEntryList.test.tsx new file mode 100644 index 00000000..d8052c5d --- /dev/null +++ b/webui/src/app/components/client/__tests__/AlignmentEntryList.test.tsx @@ -0,0 +1,42 @@ +import { describe, expect, it } from '@jest/globals'; + +import { render, fireEvent } from '@testing-library/react' +import { AlignmentEntryList } from '../AlignmentEntryList/AlignmentEntryList' + +jest.mock('https://raw.githubusercontent.com/alliance-genome/agr_ui/main/src/lib/utils.js', + () => { + return { + getSpecies: jest.fn(() => {}), + getSingleGenomeLocation: jest.fn(() => {}) + } + }, + {virtual: true} +) + +describe('AlignmentEntryList', () => { + it('renders one input record by default', () => { + const result = render( + + ) + + const inputGroups = result.container.querySelectorAll('div.p-inputgroup') + expect(inputGroups).toHaveLength(1) // Expect exactly one input group to be found + }) + + it('renders a functional add-record button', () => { + const result = render( + + ) + + const addRecordBtn = result.container.querySelector('button#add-record') + expect(addRecordBtn).not.toBe(null) // Expect add-record button to be found + expect(addRecordBtn).toBeEnabled() + + //Click the button + fireEvent.click(addRecordBtn!) + + //Check one new entry-record was added (two total) + const inputGroups = result.container.querySelectorAll('div.p-inputgroup') + expect(inputGroups).toHaveLength(2) // Expect exactly two input groups to be found + }) +}) From 6ddc30237b0e74c8a15f8d149699922342678743 Mon Sep 17 00:00:00 2001 From: Manuel Luypaert Date: Thu, 5 Sep 2024 10:38:52 +0100 Subject: [PATCH 2/4] Added unit test for webUI record removal --- .../AlignmentEntryList/AlignmentEntryList.tsx | 2 +- .../__tests__/AlignmentEntryList.test.tsx | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/webui/src/app/components/client/AlignmentEntryList/AlignmentEntryList.tsx b/webui/src/app/components/client/AlignmentEntryList/AlignmentEntryList.tsx index 9e9202c4..ac801256 100644 --- a/webui/src/app/components/client/AlignmentEntryList/AlignmentEntryList.tsx +++ b/webui/src/app/components/client/AlignmentEntryList/AlignmentEntryList.tsx @@ -88,7 +88,7 @@ export const AlignmentEntryList: FunctionComponent = (p {Array.from(alignmentEntries.values()).map((listEntry) => ( -