import React from 'react'
import { render, screen, fireEvent } from '@testing-library/react'
import Exceptions from './Exceptions'
import { AppState, User } from 'src/models/Models'
import { StateContext } from 'src/state/StateProvider'
import { NotificationContext } from 'src/state/NotificationProvider'
import { createMemoryHistory } from 'history'
import { Router } from 'react-router-dom'
import { SearchResult } from 'src/models/QuoteSearchModels'
import userEvent from '@testing-library/user-event'
test('can sort exceptions table by date attempted', () => {
const testUser: User = require('src/test/mocks/user.json')
const testState: AppState = {
searchQuote: getTestSearchResult(),
user: testUser,
}
render(
{}]}>
{}]}>
)
let tableRows = screen.getAllByRole('row')
expect(tableRows).toHaveLength(3)
// initial sort order (ascending)
expect(tableRows[0]).toHaveTextContent('IA-OTZ-L3D-2NC-NHP')
expect(tableRows[1]).toHaveTextContent('IA-DFR-0W9-0Q7-V16')
expect(tableRows[2]).toHaveTextContent('IA-BHI-MGF-SN8-F2W')
expect(screen.getByRole('button', { name: 'From Oldest' })).toBeInTheDocument()
// toggle sort order (descending)
userEvent.click(screen.getByRole('button', { name: 'From Oldest' }))
tableRows = screen.getAllByRole('row')
expect(tableRows[0]).toHaveTextContent('IA-BHI-MGF-SN8-F2W')
expect(tableRows[1]).toHaveTextContent('IA-DFR-0W9-0Q7-V16')
expect(tableRows[2]).toHaveTextContent('IA-OTZ-L3D-2NC-NHP')
// toggle back to initial sort order (ascending)
userEvent.click(screen.getByRole('button', { name: 'From Latest' }))
tableRows = screen.getAllByRole('row')
expect(tableRows[0]).toHaveTextContent('IA-OTZ-L3D-2NC-NHP')
expect(tableRows[1]).toHaveTextContent('IA-DFR-0W9-0Q7-V16')
expect(tableRows[2]).toHaveTextContent('IA-BHI-MGF-SN8-F2W')
expect(screen.getByRole('button', { name: 'From Oldest' })).toBeInTheDocument()
})
test('open new window when click quote id from exception search result', () => {
const testUser: User = require('src/test/mocks/user.json')
const quoteId = 'IA-OTZ-L3D-2NC-NHP'
const testState: AppState = {
searchQuote: getTestSearchResult(),
user: testUser,
}
window.open = jest.fn()
render(
{}]}>
{}]}>
)
fireEvent.click(screen.getByRole('button', { name: quoteId }))
expect(window.open).toHaveBeenCalledWith(`/exceptions/quote?quoteId=${quoteId}`)
})
test('render quote status column', () => {
const testUser: User = require('src/test/mocks/user.json')
const testState: AppState = {
searchQuote: getTestSearchResult(),
user: testUser,
}
render(
{}]}>
{}]}>
)
const tableRows = screen.getAllByRole('row')
expect(tableRows[0]).toHaveTextContent('IA-OTZ-L3D-2NC-NHP')
expect(tableRows[0]).toHaveTextContent('ACCEPTED')
})
function getTestSearchResult(): SearchResult {
return {
totalResultCount: 3,
pageSize: 3,
sortOrder: 'lastmodifieddate',
results: [
{
quoteId: 'IA-OTZ-L3D-2NC-NHP',
applicationId: 'IA-OTZ-L3D-2NC',
provider: {
code: 'DIR',
},
status: 'ACCEPTED',
clientParty: {
partyName: 'FGQLSY',
},
effectiveDate: {
value: '2022-06-28T12:00:00.000Z',
format: "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
},
receivedDate: {
value: '2022-06-28T21:21:17.000Z',
format: "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
},
quotedItemSet: {
policyId: '123',
externalReferences: [
{
namespace: 'THIRD_PARTY_POLICY_AGENTREF',
identifier: 'DIR',
},
{
namespace: 'THIRD_PARTY_POLICY_VERSION',
identifier: '01',
},
{
namespace: 'THIRD_PARTY_POLICY_ID',
identifier: '2YY03SE',
},
],
transactionType: 'NEW_BUSINESS',
insuredRiskGroups: [
{
insuredRisks: [
{
riskId: 'P021.1',
riskType: 'HOME',
},
],
},
],
},
underwritingAssessments: [],
lastModifiedDate: '2022-06-28T21:21:17.000Z',
},
{
quoteId: 'IA-BHI-MGF-SN8-F2W',
applicationId: 'IA-BHI-MGF-SN8',
provider: {
code: 'ICI',
},
status: 'ACCEPTED',
clientParty: {
partyName: 'RRL001',
},
effectiveDate: {
value: '2022-06-28T12:00:00.000Z',
format: "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
},
receivedDate: {
value: '2022-06-28T22:31:56.000Z',
format: "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
},
quotedItemSet: {
policyId: 'NEWBIZ2',
externalReferences: [
{
namespace: 'THIRD_PARTY_POLICY_ID',
identifier: 'NEWBIZ2',
},
{
namespace: 'THIRD_PARTY_POLICY_VERSION',
identifier: '2',
},
],
transactionType: 'NEW_BUSINESS',
insuredRiskGroups: [
{
insuredRisks: [
{
riskId: 'P024.1',
riskType: 'HOME',
},
],
},
],
},
underwritingAssessments: [],
lastModifiedDate: '2022-06-28T22:31:56.000Z',
},
{
quoteId: 'IA-DFR-0W9-0Q7-V16',
applicationId: 'IA-DFR-0W9-0Q7',
provider: {
code: 'TAK',
},
status: 'ACCEPTED',
clientParty: {
partyName: 'FS',
},
effectiveDate: {
value: '2022-06-28T12:00:00.000Z',
format: "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
},
receivedDate: {
value: '2022-06-28T22:28:01.000Z',
format: "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
},
quotedItemSet: {
policyId: 'NEWBIZ',
externalReferences: [
{
namespace: 'THIRD_PARTY_POLICY_ID',
identifier: 'NEWBIZ1',
},
{
namespace: 'THIRD_PARTY_POLICY_VERSION',
identifier: '1',
},
],
transactionType: 'NEW_BUSINESS',
insuredRiskGroups: [
{
insuredRisks: [
{
riskId: 'P010.1',
riskType: 'HOME',
},
],
},
],
},
underwritingAssessments: [],
lastModifiedDate: '2022-06-28T22:28:01.000Z',
},
],
}
}