|
| 1 | +import React from 'react'; |
| 2 | +import '@testing-library/jest-dom/extend-expect'; |
| 3 | +import { render } from '@testing-library/react'; |
| 4 | +import { Trustee } from '../cards/trustee/trustee'; |
| 5 | + |
| 6 | +// TODO |
| 7 | + |
| 8 | +// test state transitions |
| 9 | +// test each form |
| 10 | +// test search functionality |
| 11 | +// test checkbox state toggles |
| 12 | + |
| 13 | +const trustee = { |
| 14 | + schemeRoleId: '12345', |
| 15 | + // |
| 16 | + title: 'Mr', |
| 17 | + forename: 'John', |
| 18 | + surname: 'Smith', |
| 19 | + trusteeType: 'member-nominated', |
| 20 | + isProfessionalTrustee: false, |
| 21 | + // |
| 22 | + addressLine1: 'The Pensions Regulator', |
| 23 | + addressLine2: 'Napier House', |
| 24 | + addressLine3: 'Trafalgar Pl', |
| 25 | + postTown: 'Brighton', |
| 26 | + postcode: 'BN1 4DW', |
| 27 | + county: 'West Sussex', |
| 28 | + countryId: '', |
| 29 | + // |
| 30 | + telephoneNumber: '01273 000 111', |
| 31 | + emailAddress: 'fred.sandoors@trp.gov.uk', |
| 32 | +}; |
| 33 | + |
| 34 | +describe('Trustee Preview', () => { |
| 35 | + test('buttons renders correctly', () => { |
| 36 | + const callbackFn = () => Promise.resolve(); |
| 37 | + const { getByText } = render( |
| 38 | + <Trustee |
| 39 | + onDetailsSave={callbackFn} |
| 40 | + onContactSave={callbackFn} |
| 41 | + onAddressSave={callbackFn} |
| 42 | + onRemove={callbackFn} |
| 43 | + onCorrect={(_value) => {}} |
| 44 | + addressAPI={{ |
| 45 | + get: (_endpont) => Promise.resolve(), |
| 46 | + limit: 100, |
| 47 | + }} |
| 48 | + complete={true} |
| 49 | + trustee={trustee} |
| 50 | + testId={trustee.schemeRoleId} |
| 51 | + />, |
| 52 | + ); |
| 53 | + |
| 54 | + // Buttons are visible |
| 55 | + |
| 56 | + expect(getByText('Trustee')).toBeDefined(); |
| 57 | + expect(getByText('Correspondence address')).toBeDefined(); |
| 58 | + expect(getByText('Contact details')).toBeDefined(); |
| 59 | + expect(getByText('Remove')).toBeDefined(); |
| 60 | + }); |
| 61 | + |
| 62 | + test('initial status is correct', () => { |
| 63 | + const callbackFn = () => Promise.resolve(); |
| 64 | + const { getByText } = render( |
| 65 | + <Trustee |
| 66 | + onDetailsSave={callbackFn} |
| 67 | + onContactSave={callbackFn} |
| 68 | + onAddressSave={callbackFn} |
| 69 | + onRemove={callbackFn} |
| 70 | + onCorrect={(_value) => {}} |
| 71 | + addressAPI={{ |
| 72 | + get: (_endpont) => Promise.resolve(), |
| 73 | + limit: 100, |
| 74 | + }} |
| 75 | + complete={true} |
| 76 | + trustee={trustee} |
| 77 | + testId={trustee.schemeRoleId} |
| 78 | + />, |
| 79 | + ); |
| 80 | + |
| 81 | + expect(getByText('No issues')).toBeDefined(); |
| 82 | + expect(getByText('All details are correct.')).toBeDefined(); |
| 83 | + }); |
| 84 | + |
| 85 | + test('address shows up correctly', () => { |
| 86 | + const callbackFn = () => Promise.resolve(); |
| 87 | + const { getByText } = render( |
| 88 | + <Trustee |
| 89 | + onDetailsSave={callbackFn} |
| 90 | + onContactSave={callbackFn} |
| 91 | + onAddressSave={callbackFn} |
| 92 | + onRemove={callbackFn} |
| 93 | + onCorrect={(_value) => {}} |
| 94 | + addressAPI={{ |
| 95 | + get: (_endpont) => Promise.resolve(), |
| 96 | + limit: 100, |
| 97 | + }} |
| 98 | + complete={true} |
| 99 | + trustee={trustee} |
| 100 | + testId={trustee.schemeRoleId} |
| 101 | + />, |
| 102 | + ); |
| 103 | + |
| 104 | + expect(getByText(/The Pensions Regulator/gi)).toBeDefined(); |
| 105 | + expect(getByText(/Napier House/gi)).toBeDefined(); |
| 106 | + expect(getByText(/Trafalgar Pl/gi)).toBeDefined(); |
| 107 | + expect(getByText(/Brighton/gi)).toBeDefined(); |
| 108 | + expect(getByText(/BN1 4DW/gi)).toBeDefined(); |
| 109 | + }); |
| 110 | + |
| 111 | + test('contact details shows up correctly', () => { |
| 112 | + const callbackFn = () => Promise.resolve(); |
| 113 | + const { getByText } = render( |
| 114 | + <Trustee |
| 115 | + onDetailsSave={callbackFn} |
| 116 | + onContactSave={callbackFn} |
| 117 | + onAddressSave={callbackFn} |
| 118 | + onRemove={callbackFn} |
| 119 | + onCorrect={(_value) => {}} |
| 120 | + addressAPI={{ |
| 121 | + get: (_endpont) => Promise.resolve(), |
| 122 | + limit: 100, |
| 123 | + }} |
| 124 | + complete={true} |
| 125 | + trustee={trustee} |
| 126 | + testId={trustee.schemeRoleId} |
| 127 | + />, |
| 128 | + ); |
| 129 | + |
| 130 | + expect(getByText('Phone')).toBeDefined(); |
| 131 | + expect(getByText('01273 000 111')).toBeDefined(); |
| 132 | + expect(getByText('Email')).toBeDefined(); |
| 133 | + expect(getByText('fred.sandoors@trp.gov.uk')).toBeDefined(); |
| 134 | + }); |
| 135 | +}); |
0 commit comments