Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional UI unit tests (KANBAN-601) #282

Merged
merged 4 commits into from
Sep 5, 2024
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 @@ -88,7 +88,7 @@ export const AlignmentEntryList: FunctionComponent<AlignmentEntryListProps> = (p
<tbody>
{Array.from(alignmentEntries.values()).map((listEntry) => (
<tr key={listEntry.props.index}>
<td><Button text icon="pi pi-trash" onClick={() => removeAlignmentEntry(listEntry.props.index)} /></td>
<td><Button text id="remove-record" icon="pi pi-trash" onClick={() => removeAlignmentEntry(listEntry.props.index)} /></td>
<td>< AlignmentEntry {...listEntry.props} /></td>
</tr>))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
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(
<AlignmentEntryList agrjBrowseDataRelease='7.3.0' dispatchInputPayloadPart={jest.fn()} />
)

const inputGroups = result.container.querySelectorAll('div.p-inputgroup')
expect(inputGroups).toHaveLength(1) // Expect exactly one input group to be found
})

it('renders a functional button to remove individual records', () => {
const result = render(
<AlignmentEntryList agrjBrowseDataRelease='7.3.0' dispatchInputPayloadPart={jest.fn()} />
)

const inputGroupsBefore = result.container.querySelectorAll('div.p-inputgroup')
expect(inputGroupsBefore).toHaveLength(1) // Expect exactly one input group to be found

const removeRecordBtn = result.container.querySelector('button#remove-record')
expect(removeRecordBtn).not.toBeNull() // Expect remove-record button to be found
expect(removeRecordBtn).toBeEnabled()

fireEvent.click(removeRecordBtn!)

//Check one entry-record was removed (zero left)
const inputGroupsAfter = result.container.querySelectorAll('div.p-inputgroup')
expect(inputGroupsAfter).toHaveLength(0) // Expect exactly one input group to be found
})

it('renders a functional add-record button', () => {
const result = render(
<AlignmentEntryList agrjBrowseDataRelease='7.3.0' dispatchInputPayloadPart={jest.fn()} />
)

const addRecordBtn = result.container.querySelector('button#add-record')
expect(addRecordBtn).not.toBeNull() // 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
})
})
35 changes: 35 additions & 0 deletions webui/src/app/components/client/__tests__/JobSubmitForm.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { describe, expect, it } from '@jest/globals';

import { render } from '@testing-library/react'
import { JobSubmitForm } from '../JobSubmitForm/JobSubmitForm'

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('AlignmentEntry', () => {
it('renders a data-entry form', () => {
const result = render(
<JobSubmitForm agrjBrowseDataRelease='7.3.0' />
)

const inputGroup = result.container.querySelector('div.p-inputgroup')
expect(inputGroup).not.toBeNull() // Expect (at least one) input group to be found
})

it('renders a submit button that is disabled by default', () => {
const result = render(
<JobSubmitForm agrjBrowseDataRelease='7.3.0' />
)

const submitBtn = result.container.querySelector('button[aria-label="Submit"]')
expect(submitBtn).not.toBeNull() // Expect submit button to be found
expect(submitBtn).toBeDisabled()
})
})