This repository has been archived by the owner on Oct 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
La til test for metrikkutsendelse ved print-klikk.
Flyttet testen for autoutsendelse til samme fil.
- Loading branch information
Showing
5 changed files
with
102 additions
and
71 deletions.
There are no files selected for viewing
This file contains 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
69 changes: 0 additions & 69 deletions
69
src/Forside/Sammenligningspaneler/Sammenligningspaneler.test.tsx
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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,88 @@ | ||
import { MockResizeObserver } from '../jest/MockResizeObserver'; | ||
import { render, screen, fireEvent, waitFor } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { mockAllDatahentingStatusOk } from './api/mockedApiResponses/use-analytics-test-mocks'; | ||
import { BrowserRouter } from 'react-router-dom'; | ||
import { Forside } from './Forside/Forside'; | ||
import { RestRessurs, RestStatus } from './api/api-utils'; | ||
import { AltinnOrganisasjon } from './api/altinnorganisasjon-api'; | ||
import { fleskOgFisk, heiOgHåBarnehage } from './api/mockedApiResponses/altinn-mock'; | ||
import * as hooks from './hooks/useOrgnr'; | ||
import * as metrikker from './metrikker/iatjenester'; | ||
import { act } from 'react-dom/test-utils'; | ||
|
||
describe('Metrikkutsendelser', () => { | ||
const MockObserver = new MockResizeObserver(); | ||
let spy: jest.SpyInstance; | ||
|
||
beforeEach(() => { | ||
MockObserver.startmock(); | ||
const valgtBedriftMedSykefraværsstatistikkRettigheter = | ||
heiOgHåBarnehage[0].OrganizationNumber; | ||
jest.spyOn(hooks, 'useOrgnr').mockReturnValue( | ||
valgtBedriftMedSykefraværsstatistikkRettigheter | ||
); | ||
spy = jest.spyOn(metrikker, 'sendIaTjenesteMetrikkMottatt'); | ||
}); | ||
|
||
afterEach(() => { | ||
MockObserver.stopmock(); | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
const altinnOrganisasjoner: RestRessurs<AltinnOrganisasjon[]> = { | ||
status: RestStatus.Suksess, | ||
data: [...fleskOgFisk, ...heiOgHåBarnehage], | ||
}; | ||
|
||
const altinnOrganisasjonerMedStatistikktilgang: RestRessurs<AltinnOrganisasjon[]> = { | ||
status: RestStatus.Suksess, | ||
data: heiOgHåBarnehage, | ||
}; | ||
|
||
const mockAppData = { | ||
...mockAllDatahentingStatusOk, | ||
altinnOrganisasjonerMedStatistikktilgang, | ||
altinnOrganisasjoner, | ||
}; | ||
|
||
function renderForside(skalSendeMetrikkerAutomatisk = true) { | ||
return render( | ||
<BrowserRouter> | ||
<Forside | ||
{...mockAppData} | ||
skalSendeMetrikkerAutomatisk={skalSendeMetrikkerAutomatisk} | ||
/> | ||
</BrowserRouter> | ||
); | ||
} | ||
it('Sender ia-tjenestermetrikk etter ca. 5 sekunder', async () => { | ||
jest.useFakeTimers(); | ||
|
||
renderForside(); | ||
|
||
expect(spy).not.toHaveBeenCalled(); | ||
|
||
act(() => { | ||
jest.advanceTimersByTime(7000); | ||
}); | ||
|
||
expect(spy).toHaveBeenCalled(); | ||
jest.useRealTimers(); | ||
}); | ||
|
||
it('Sender ia-tjenestermetrikk ved print-klikk', async () => { | ||
renderForside(false); | ||
|
||
const knapp = screen.getByText('Last ned'); | ||
|
||
expect(knapp).toBeDefined(); | ||
|
||
expect(spy).not.toHaveBeenCalled(); | ||
|
||
fireEvent.click(knapp); | ||
await waitFor(() => { | ||
expect(spy).toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); |
This file contains 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