|
| 1 | +import { fromJS } from "immutable"; |
| 2 | + |
| 3 | +import { mountedComponent, screen, fireEvent } from "../../../../../test-utils"; |
| 4 | + |
| 5 | +import Transfers from "./component"; |
| 6 | + |
| 7 | +describe("<RecordActions />/transitions/components/<Transfers />", () => { |
| 8 | + const initialState = fromJS({ |
| 9 | + forms: { |
| 10 | + options: { |
| 11 | + lookups: [], |
| 12 | + locations: [] |
| 13 | + } |
| 14 | + }, |
| 15 | + records: { |
| 16 | + transitions: { |
| 17 | + referral: { |
| 18 | + users: [] |
| 19 | + } |
| 20 | + } |
| 21 | + }, |
| 22 | + application: { |
| 23 | + reportingLocationConfig: { admin_level: 1 }, |
| 24 | + agencies: [] |
| 25 | + } |
| 26 | + }); |
| 27 | + |
| 28 | + const initialProps = { |
| 29 | + isBulkTransfer: false, |
| 30 | + providedConsent: true, |
| 31 | + canConsentOverride: false, |
| 32 | + record: fromJS({ module_id: "module_1" }), |
| 33 | + recordType: "record_type_1", |
| 34 | + setDisabled: () => {}, |
| 35 | + setPending: () => {} |
| 36 | + }; |
| 37 | + |
| 38 | + it("should not render the Consent Not Provided Alert if consent was provided", () => { |
| 39 | + mountedComponent(<Transfers {...initialProps} />, initialState); |
| 40 | + expect(screen.queryByRole("alert")).toBeNull(); |
| 41 | + }); |
| 42 | + |
| 43 | + it("should not disabled field if consent was provided", () => { |
| 44 | + mountedComponent(<Transfers {...initialProps} />, initialState); |
| 45 | + const textFields = document.querySelectorAll('input[type="text"]'); |
| 46 | + |
| 47 | + textFields.forEach(combobox => { |
| 48 | + expect(combobox).not.toBeDisabled(); |
| 49 | + }); |
| 50 | + }); |
| 51 | + |
| 52 | + it("should render the Consent Not Provided Alert if consent was not provided", () => { |
| 53 | + const props = { |
| 54 | + ...initialProps, |
| 55 | + providedConsent: false |
| 56 | + }; |
| 57 | + |
| 58 | + mountedComponent(<Transfers {...props} />, initialState); |
| 59 | + |
| 60 | + expect(screen.getByRole("alert")).toBeInTheDocument(); |
| 61 | + }); |
| 62 | + |
| 63 | + it("should disabled field if consent was not provided", () => { |
| 64 | + const props = { |
| 65 | + ...initialProps, |
| 66 | + providedConsent: false |
| 67 | + }; |
| 68 | + |
| 69 | + mountedComponent(<Transfers {...props} />, initialState); |
| 70 | + |
| 71 | + const textFields = document.querySelectorAll('input[type="text"]'); |
| 72 | + |
| 73 | + textFields.forEach(field => { |
| 74 | + expect(field).toBeDisabled(); |
| 75 | + }); |
| 76 | + }); |
| 77 | + |
| 78 | + describe("when consent was not provided ", () => { |
| 79 | + it("should not render checkbox if can not override consent", () => { |
| 80 | + const props = { |
| 81 | + ...initialProps, |
| 82 | + providedConsent: false |
| 83 | + }; |
| 84 | + |
| 85 | + mountedComponent(<Transfers {...props} />, initialState); |
| 86 | + |
| 87 | + expect(screen.getByRole("alert")).toBeInTheDocument(); |
| 88 | + expect(screen.queryAllByRole("checkbox")).toHaveLength(2); |
| 89 | + }); |
| 90 | + |
| 91 | + it("should render checkbox if can not override consent", () => { |
| 92 | + const props = { |
| 93 | + ...initialProps, |
| 94 | + providedConsent: false, |
| 95 | + canConsentOverride: true |
| 96 | + }; |
| 97 | + |
| 98 | + mountedComponent(<Transfers {...props} />, initialState); |
| 99 | + |
| 100 | + expect(screen.getByRole("alert")).toBeInTheDocument(); |
| 101 | + expect(screen.queryAllByRole("checkbox")).toHaveLength(3); |
| 102 | + }); |
| 103 | + |
| 104 | + it("should set the consent_overridden to true if checked", () => { |
| 105 | + const props = { |
| 106 | + ...initialProps, |
| 107 | + providedConsent: false, |
| 108 | + canConsentOverride: true |
| 109 | + }; |
| 110 | + |
| 111 | + mountedComponent(<Transfers {...props} />, initialState); |
| 112 | + |
| 113 | + document.querySelectorAll('input[type="text"]').forEach(field => { |
| 114 | + expect(field).toBeDisabled(); |
| 115 | + }); |
| 116 | + |
| 117 | + const consentCheckbox = document.querySelectorAll('input[type="checkbox"]')[0]; |
| 118 | + |
| 119 | + expect(consentCheckbox).not.toBeChecked(); |
| 120 | + fireEvent.click(consentCheckbox); |
| 121 | + expect(consentCheckbox).toBeChecked(); |
| 122 | + |
| 123 | + document.querySelectorAll('input[type="text"]').forEach(field => { |
| 124 | + expect(field).not.toBeDisabled(); |
| 125 | + }); |
| 126 | + }); |
| 127 | + }); |
| 128 | + |
| 129 | + describe("when consent is provided", () => { |
| 130 | + it("should set the consent_overridden to false", () => { |
| 131 | + const props = { |
| 132 | + ...initialProps, |
| 133 | + providedConsent: true, |
| 134 | + canConsentOverride: true |
| 135 | + }; |
| 136 | + |
| 137 | + mountedComponent(<Transfers {...props} />, initialState); |
| 138 | + |
| 139 | + expect(screen.queryByRole("alert")).toBeNull(); |
| 140 | + expect(screen.queryAllByRole("checkbox")).toHaveLength(2); |
| 141 | + }); |
| 142 | + }); |
| 143 | +}); |
0 commit comments