-
Notifications
You must be signed in to change notification settings - Fork 33
fix: make voiceover read org detailes #4264
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
Merged
JamalAlabdullah
merged 12 commits into
main
from
4114-wcag-brudd-413-statusbeskjeder-aa---skjermleser-voiceover-does-not-read-found-organization-after-search-in-org-lookup-likely-same-in-person-lookup
Jun 23, 2026
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5a05978
fix: make voiceover read org detailes
JamalAlabdullah a9d9b82
fixed coderabbitai feedback
JamalAlabdullah f2f57c5
added test
JamalAlabdullah 53a9718
fixed cypress test
JamalAlabdullah fd274f0
voiceover read also error message
JamalAlabdullah 14df853
Merge remote-tracking branch 'origin/main' into 4114-wcag-brudd-413-s…
JamalAlabdullah eadc2b1
fixed test in organisationlookup.ts
JamalAlabdullah b3a73da
feedback fixing
JamalAlabdullah 4a9a01a
Merge remote-tracking branch 'origin/main' into 4114-wcag-brudd-413-s…
JamalAlabdullah 9af0162
Merge remote-tracking branch 'origin' into 4114-wcag-brudd-413-status…
JamalAlabdullah 40e52ed
fixed test
JamalAlabdullah aa4c2a2
test
JamalAlabdullah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
221 changes: 221 additions & 0 deletions
221
src/layout/OrganisationLookup/OrganisationLookupComponent.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,221 @@ | ||
| import React from 'react'; | ||
|
|
||
| import { jest } from '@jest/globals'; | ||
| import { screen, waitFor } from '@testing-library/react'; | ||
| import { userEvent } from '@testing-library/user-event'; | ||
|
|
||
| import { defaultDataTypeMock } from 'src/__mocks__/getLayoutSetsMock'; | ||
| import { OrganisationLookupComponent } from 'src/layout/OrganisationLookup/OrganisationLookupComponent'; | ||
| import { renderGenericComponentTest } from 'src/test/renderWithProviders'; | ||
| import { httpGet } from 'src/utils/network/networking'; | ||
| import type { ILayoutCollection } from 'src/layout/layout'; | ||
| import type { RenderGenericComponentTestProps } from 'src/test/renderWithProviders'; | ||
|
|
||
| jest.mock('src/utils/network/networking', () => ({ | ||
| httpGet: jest.fn(), | ||
| })); | ||
|
|
||
| const mockedHttpGet = jest.mocked(httpGet); | ||
|
|
||
| const validOrgNr = '043871668'; | ||
| const orgName = 'Skog og Fjell Consulting'; | ||
| const orgLookupId = 'org-lookup'; | ||
| const textSiblingId = 'text-sibling'; | ||
|
|
||
| const defaultBindings = { | ||
| organisation_lookup_orgnr: { field: 'orgNr', dataType: defaultDataTypeMock }, | ||
| organisation_lookup_name: { field: 'orgName', dataType: defaultDataTypeMock }, | ||
| }; | ||
|
|
||
| const render = async ({ | ||
| component, | ||
| queries, | ||
| ...rest | ||
| }: Partial<RenderGenericComponentTestProps<'OrganisationLookup'>> = {}) => | ||
| await renderGenericComponentTest({ | ||
| type: 'OrganisationLookup', | ||
| renderer: (props) => <OrganisationLookupComponent {...props} />, | ||
| mockFormDataSaving: true, | ||
| component: { | ||
| id: orgLookupId, | ||
| dataModelBindings: defaultBindings, | ||
| textResourceBindings: { | ||
| title: 'Organisation lookup', | ||
| }, | ||
| ...component, | ||
| }, | ||
| queries: { | ||
| fetchFormData: async () => ({ | ||
| orgNr: '', | ||
| orgName: '', | ||
| address: { name: '', street: '' }, | ||
| }), | ||
| ...queries, | ||
| }, | ||
| ...rest, | ||
| }); | ||
|
|
||
| const layoutWithSiblingText: ILayoutCollection = { | ||
| FormLayout: { | ||
| data: { | ||
| layout: [ | ||
| { | ||
| id: 'group-1', | ||
| type: 'Group', | ||
| children: [orgLookupId, textSiblingId], | ||
| }, | ||
| { | ||
| id: orgLookupId, | ||
| type: 'OrganisationLookup', | ||
| dataModelBindings: defaultBindings, | ||
| textResourceBindings: { | ||
| title: 'Organisation lookup', | ||
| }, | ||
| }, | ||
| { | ||
| id: textSiblingId, | ||
| type: 'Text', | ||
| textResourceBindings: { | ||
| title: 'Org name title', | ||
| }, | ||
| value: ['dataModel', 'address.name', defaultDataTypeMock], | ||
| }, | ||
| { | ||
| id: 'text-street', | ||
| type: 'Text', | ||
| value: ['dataModel', 'address.street', defaultDataTypeMock], | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| describe('OrganisationLookupComponent', () => { | ||
| beforeEach(() => { | ||
| mockedHttpGet.mockReset(); | ||
| }); | ||
|
|
||
| it('renders lookup field and submit button', async () => { | ||
| await render(); | ||
|
|
||
| expect(screen.getByRole('textbox', { name: /Organisasjonsnummer/i })).toBeInTheDocument(); | ||
| expect(screen.getByRole('button', { name: /Hent opplysninger/i })).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('shows validation error for invalid organisation number', async () => { | ||
| await render(); | ||
|
|
||
| await userEvent.type(screen.getByRole('textbox', { name: /Organisasjonsnummer/i }), '123456789'); | ||
| await userEvent.click(screen.getByRole('button', { name: /Hent opplysninger/i })); | ||
|
|
||
| expect(screen.getByText(/Organisasjonsnummeret er ugyldig/i)).toBeInTheDocument(); | ||
| expect(mockedHttpGet).not.toHaveBeenCalled(); | ||
|
|
||
| const statusRegion = screen.getByTestId('organisation-lookup-status'); | ||
| await waitFor(() => { | ||
| expect(statusRegion).toHaveTextContent(/Organisasjonsnummeret er ugyldig/i); | ||
| }); | ||
| }); | ||
|
|
||
| it('fetches organisation, announces details, and allows clearing', async () => { | ||
| mockedHttpGet.mockResolvedValue({ | ||
| success: true, | ||
| organisationDetails: { | ||
| orgNr: validOrgNr, | ||
| name: orgName, | ||
| }, | ||
| }); | ||
|
|
||
| await render({ | ||
| queries: { | ||
| fetchLayouts: async (_layoutSetId): Promise<ILayoutCollection> => layoutWithSiblingText, | ||
| }, | ||
| mockFormDataSaving: (data) => ({ | ||
| ...(data as object), | ||
| address: { name: 'Sibling Name', street: 'Street 1' }, | ||
| }), | ||
| }); | ||
|
|
||
| await userEvent.type(screen.getByRole('textbox', { name: /Organisasjonsnummer/i }), validOrgNr); | ||
| await userEvent.click(screen.getByRole('button', { name: /Hent opplysninger/i })); | ||
|
|
||
| await waitFor(() => expect(mockedHttpGet).toHaveBeenCalled()); | ||
| await waitFor(() => expect(screen.getByRole('button', { name: /Fjern/i })).toBeInTheDocument()); | ||
|
|
||
| expect(screen.getByLabelText('Organisasjonsnavn')).toHaveTextContent(orgName); | ||
|
|
||
| const statusRegion = screen.getByTestId('organisation-lookup-status'); | ||
| await waitFor(() => { | ||
| expect(statusRegion).toHaveTextContent(`Organisasjonsnummer ${validOrgNr}`); | ||
| expect(statusRegion).toHaveTextContent('Sibling Name'); | ||
| }); | ||
|
|
||
| await userEvent.click(screen.getByRole('button', { name: /Fjern/i })); | ||
|
|
||
| expect(screen.getByRole('button', { name: /Hent opplysninger/i })).toBeInTheDocument(); | ||
| expect(statusRegion).toHaveTextContent(''); | ||
| }); | ||
|
|
||
| it('submits lookup on Enter key', async () => { | ||
| mockedHttpGet.mockResolvedValue({ | ||
| success: true, | ||
| organisationDetails: { | ||
| orgNr: validOrgNr, | ||
| name: orgName, | ||
| }, | ||
| }); | ||
|
|
||
| await render(); | ||
|
|
||
| await userEvent.type(screen.getByRole('textbox', { name: /Organisasjonsnummer/i }), `${validOrgNr}{Enter}`); | ||
|
|
||
| await waitFor(() => expect(mockedHttpGet).toHaveBeenCalled()); | ||
| }); | ||
|
|
||
| it('shows not found error when lookup returns no organisation', async () => { | ||
| mockedHttpGet.mockResolvedValue({ | ||
| success: false, | ||
| organisationDetails: null, | ||
| }); | ||
|
|
||
| await render(); | ||
|
|
||
| await userEvent.type(screen.getByRole('textbox', { name: /Organisasjonsnummer/i }), validOrgNr); | ||
| await userEvent.click(screen.getByRole('button', { name: /Hent opplysninger/i })); | ||
|
|
||
| expect(await screen.findByText(/Organisasjonsnummeret ble ikke funnet i enhetsregisteret/i)).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('shows invalid response error when lookup response is invalid', async () => { | ||
| mockedHttpGet.mockResolvedValue({ unexpected: true }); | ||
|
|
||
| await render(); | ||
|
|
||
| await userEvent.type(screen.getByRole('textbox', { name: /Organisasjonsnummer/i }), validOrgNr); | ||
| await userEvent.click(screen.getByRole('button', { name: /Hent opplysninger/i })); | ||
|
|
||
| expect(await screen.findByText(/Ugyldig respons fra server/i)).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('shows unknown error when lookup request fails', async () => { | ||
| mockedHttpGet.mockRejectedValue(new Error('network error')); | ||
|
|
||
| await render(); | ||
|
|
||
| await userEvent.type(screen.getByRole('textbox', { name: /Organisasjonsnummer/i }), validOrgNr); | ||
| await userEvent.click(screen.getByRole('button', { name: /Hent opplysninger/i })); | ||
|
|
||
| expect(await screen.findByText(/Ukjent feil. Vennligst prøv igjen senere/i)).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('does not render action buttons when read only', async () => { | ||
| await render({ | ||
| component: { | ||
| readOnly: true, | ||
| }, | ||
| }); | ||
|
|
||
| expect(screen.queryByRole('button', { name: /Hent opplysninger/i })).not.toBeInTheDocument(); | ||
| expect(screen.queryByRole('button', { name: /Fjern/i })).not.toBeInTheDocument(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.