|
| 1 | +// Copyright (c) 2014 - 2023 UNICEF. All rights reserved. |
| 2 | + |
| 3 | +import { fromJS } from "immutable"; |
| 4 | + |
| 5 | +import { ListHeaderRecord } from "../../user/records"; |
| 6 | +import { mountedComponent, screen } from "../../../test-utils"; |
| 7 | +import { FieldRecord } from "../../record-form"; |
| 8 | +import { mapEntriesToRecord } from "../../../libs"; |
| 9 | + |
| 10 | +import { ExportRecord } from "./records"; |
| 11 | +import ExportList from "./container"; |
| 12 | + |
| 13 | +describe("<ExportList />", () => { |
| 14 | + const initialState = fromJS({ |
| 15 | + records: { |
| 16 | + bulk_exports: { |
| 17 | + data: [ |
| 18 | + ExportRecord({ |
| 19 | + id: "d5e1a4a019ec727efd34a35d1d9a271e", |
| 20 | + file_name: "PRIMERO-CHILD-UNHCR.CSV", |
| 21 | + record_type: "Case", |
| 22 | + started_on: "2020-02-04T20:32:50.078Z" |
| 23 | + }), |
| 24 | + ExportRecord({ |
| 25 | + id: "d5e1a4a019ec727efd34a35d1d9a272e", |
| 26 | + file_name: "PRIMERO - CHILD.PDF", |
| 27 | + record_type: "Case", |
| 28 | + started_on: "2020-02-03T20:32:50.078Z" |
| 29 | + }), |
| 30 | + ExportRecord({ |
| 31 | + id: "d5e1a4a019ec727efd34a35d1d9a273e", |
| 32 | + file_name: "PRIMERO - CHILD.JSON", |
| 33 | + record_type: "Case", |
| 34 | + started_on: "2020-02-02T20:32:50.078Z" |
| 35 | + }) |
| 36 | + ], |
| 37 | + metadata: { |
| 38 | + total: 15, |
| 39 | + per: 20, |
| 40 | + page: 1 |
| 41 | + }, |
| 42 | + errors: false |
| 43 | + } |
| 44 | + }, |
| 45 | + user: { |
| 46 | + listHeaders: { |
| 47 | + bulk_exports: [ |
| 48 | + ListHeaderRecord({ |
| 49 | + name: "file_name", |
| 50 | + field_name: "file_name", |
| 51 | + id_search: false |
| 52 | + }), |
| 53 | + ListHeaderRecord({ |
| 54 | + name: "record_type", |
| 55 | + field_name: "record_type", |
| 56 | + id_search: false |
| 57 | + }), |
| 58 | + ListHeaderRecord({ |
| 59 | + name: "started_on", |
| 60 | + field_name: "started_on", |
| 61 | + id_search: false |
| 62 | + }) |
| 63 | + ] |
| 64 | + }, |
| 65 | + permissions: { |
| 66 | + exports: ["manage"], |
| 67 | + bulk_exports: ["manage"] |
| 68 | + } |
| 69 | + }, |
| 70 | + forms: { |
| 71 | + fields: mapEntriesToRecord( |
| 72 | + { |
| 73 | + 1: { |
| 74 | + name: "name_first", |
| 75 | + type: "text_field" |
| 76 | + } |
| 77 | + }, |
| 78 | + FieldRecord |
| 79 | + ), |
| 80 | + options: { |
| 81 | + lookups: [ |
| 82 | + { |
| 83 | + id: 1, |
| 84 | + unique_id: "lookup-location-type", |
| 85 | + values: [ |
| 86 | + { id: "country", display_text: "Country" }, |
| 87 | + { id: "region", display_text: "Region" } |
| 88 | + ] |
| 89 | + } |
| 90 | + ] |
| 91 | + } |
| 92 | + } |
| 93 | + }); |
| 94 | + |
| 95 | + it("should render a table with three rows", () => { |
| 96 | + mountedComponent(<ExportList />, {}, initialState); |
| 97 | + expect(screen.getAllByRole("row")).toHaveLength(3); |
| 98 | + }); |
| 99 | + |
| 100 | + it("should render <PageContainer>", () => { |
| 101 | + mountedComponent(<ExportList />, {}, initialState); |
| 102 | + expect(screen.getByTestId("page-container")).toBeInTheDocument(1); |
| 103 | + }); |
| 104 | + |
| 105 | + it("should render <PageHeading>", () => { |
| 106 | + mountedComponent(<ExportList />, {}, initialState); |
| 107 | + expect(screen.getByTestId("page-heading")).toBeInTheDocument(); |
| 108 | + }); |
| 109 | + |
| 110 | + it("should render <PageContent>", () => { |
| 111 | + mountedComponent(<ExportList />, {}, initialState); |
| 112 | + expect(screen.getByTestId("page-content")).toBeInTheDocument(); |
| 113 | + }); |
| 114 | + |
| 115 | + it("should render <IndexTable>", () => { |
| 116 | + mountedComponent(<ExportList />, {}, initialState); |
| 117 | + expect(screen.getByRole('table')).toBeInTheDocument(); |
| 118 | + }); |
| 119 | + |
| 120 | + describe("when offline", () => { |
| 121 | + const stateOffline = fromJS({ |
| 122 | + connectivity: { |
| 123 | + online: false |
| 124 | + }, |
| 125 | + records: { |
| 126 | + bulk_exports: { |
| 127 | + data: [ |
| 128 | + ExportRecord({ |
| 129 | + id: "d5e1a4a019ec727efd34a35d1d9a271e", |
| 130 | + file_name: "PRIMERO-CHILD-UNHCR.CSV", |
| 131 | + record_type: "Case", |
| 132 | + started_on: "2020-02-04T20:32:50.078Z" |
| 133 | + }), |
| 134 | + ExportRecord({ |
| 135 | + id: "d5e1a4a019ec727efd34a35d1d9a272e", |
| 136 | + file_name: "PRIMERO - CHILD.PDF", |
| 137 | + record_type: "Case", |
| 138 | + started_on: "2020-02-03T20:32:50.078Z" |
| 139 | + }), |
| 140 | + ExportRecord({ |
| 141 | + id: "d5e1a4a019ec727efd34a35d1d9a273e", |
| 142 | + file_name: "PRIMERO - CHILD.JSON", |
| 143 | + record_type: "Case", |
| 144 | + started_on: "2020-02-02T20:32:50.078Z" |
| 145 | + }) |
| 146 | + ], |
| 147 | + metadata: { |
| 148 | + total: 15, |
| 149 | + per: 20, |
| 150 | + page: 1 |
| 151 | + }, |
| 152 | + errors: false |
| 153 | + } |
| 154 | + }, |
| 155 | + user: { |
| 156 | + listHeaders: { |
| 157 | + bulk_exports: [ |
| 158 | + ListHeaderRecord({ |
| 159 | + name: "file_name", |
| 160 | + field_name: "file_name", |
| 161 | + id_search: false |
| 162 | + }), |
| 163 | + ListHeaderRecord({ |
| 164 | + name: "record_type", |
| 165 | + field_name: "record_type", |
| 166 | + id_search: false |
| 167 | + }), |
| 168 | + ListHeaderRecord({ |
| 169 | + name: "started_on", |
| 170 | + field_name: "started_on", |
| 171 | + id_search: false |
| 172 | + }) |
| 173 | + ] |
| 174 | + }, |
| 175 | + permissions: { |
| 176 | + exports: ["manage"], |
| 177 | + bulk_exports: ["manage"] |
| 178 | + } |
| 179 | + }, |
| 180 | + forms: { |
| 181 | + fields: mapEntriesToRecord( |
| 182 | + { |
| 183 | + 1: { |
| 184 | + name: "name_first", |
| 185 | + type: "text_field" |
| 186 | + } |
| 187 | + }, |
| 188 | + FieldRecord |
| 189 | + ), |
| 190 | + options: { |
| 191 | + lookups: [ |
| 192 | + { |
| 193 | + id: 1, |
| 194 | + unique_id: "lookup-location-type", |
| 195 | + values: [ |
| 196 | + { id: "country", display_text: "Country" }, |
| 197 | + { id: "region", display_text: "Region" } |
| 198 | + ] |
| 199 | + } |
| 200 | + ] |
| 201 | + } |
| 202 | + } |
| 203 | + }); |
| 204 | + |
| 205 | + it("should render DisabledOffline components for each row", () => { |
| 206 | + mountedComponent(<ExportList />, stateOffline); |
| 207 | + expect(screen.getAllByTestId("disable-offline")).toHaveLength(9); |
| 208 | + }); |
| 209 | + }); |
| 210 | +}); |
0 commit comments