From fc3929183b1a87e7855cfb511f5489c9209a599a Mon Sep 17 00:00:00 2001 From: srinivasulu chimaladinne Date: Fri, 8 Sep 2023 11:45:36 +0530 Subject: [PATCH 1/6] [New] Added test cases for pages export list --- app/javascript/components/page/component.jsx | 2 +- .../pages/export-list/container.jsx | 3 +- ...ntainer.unit.test.js => container.spec.js} | 33 ++++++++----------- 3 files changed, 16 insertions(+), 22 deletions(-) rename app/javascript/components/pages/export-list/{container.unit.test.js => container.spec.js} (75%) diff --git a/app/javascript/components/page/component.jsx b/app/javascript/components/page/component.jsx index e475a65670..ed072d11dd 100644 --- a/app/javascript/components/page/component.jsx +++ b/app/javascript/components/page/component.jsx @@ -21,7 +21,7 @@ const Component = ({ children, twoCol, fullWidthMobile }) => { } return ( -
+
{children}
); diff --git a/app/javascript/components/pages/export-list/container.jsx b/app/javascript/components/pages/export-list/container.jsx index cdff16e1e0..48709aa2fc 100644 --- a/app/javascript/components/pages/export-list/container.jsx +++ b/app/javascript/components/pages/export-list/container.jsx @@ -57,6 +57,7 @@ const ExportList = () => { {/* eslint-disable-next-line jsx-a11y/click-events-have-key-events */}
{ return ( - + diff --git a/app/javascript/components/pages/export-list/container.unit.test.js b/app/javascript/components/pages/export-list/container.spec.js similarity index 75% rename from app/javascript/components/pages/export-list/container.unit.test.js rename to app/javascript/components/pages/export-list/container.spec.js index 59e96e2f28..43b117801b 100644 --- a/app/javascript/components/pages/export-list/container.unit.test.js +++ b/app/javascript/components/pages/export-list/container.spec.js @@ -1,21 +1,16 @@ // Copyright (c) 2014 - 2023 UNICEF. All rights reserved. import { fromJS } from "immutable"; -import MUIDataTable, { TableBodyRow } from "mui-datatables"; -import IndexTable from "../../index-table"; -import PageContainer, { PageHeading, PageContent } from "../../page"; import { ListHeaderRecord } from "../../user/records"; -import { setupMountedComponent } from "../../../test"; +import { mountedComponent, screen } from "../../../test-utils"; import { FieldRecord } from "../../record-form"; import { mapEntriesToRecord } from "../../../libs"; -import DisableOffline from "../../disable-offline"; import { ExportRecord } from "./records"; import ExportList from "./container"; describe("", () => { - let component; const initialState = fromJS({ records: { @@ -98,39 +93,37 @@ describe("", () => { } }); - beforeEach(() => { - ({ component } = setupMountedComponent(ExportList, {}, initialState)); - }); - it("should render a table with three rows", () => { - expect(component.find(MUIDataTable).find(TableBodyRow)).to.have.lengthOf(3); + mountedComponent(, {}, initialState); + expect(screen.getAllByRole("row")).toHaveLength(3); }); it("should render ", () => { - expect(component.find(PageContainer)).to.have.lengthOf(1); + mountedComponent(, {}, initialState); + expect(screen.getByTestId("page-container")).toBeInTheDocument(1); }); it("should render ", () => { - expect(component.find(PageHeading)).to.have.lengthOf(1); + mountedComponent(, {}, initialState); + expect(screen.getByTestId("page-heading")).toBeInTheDocument(); }); it("should render ", () => { - expect(component.find(PageContent)).to.have.lengthOf(1); + mountedComponent(, {}, initialState); + expect(screen.getByText(/messages.record_list.rows_per_page/i)).toBeInTheDocument(); }); it("should render ", () => { - expect(component.find(IndexTable)).to.have.lengthOf(1); + mountedComponent(, {}, initialState); + expect(screen.getByText(/messages.record_list.rows_per_page/i)).toBeInTheDocument(); }); describe("when offline", () => { const stateOffline = initialState.setIn(["application", "online"], false); - beforeEach(() => { - ({ component } = setupMountedComponent(ExportList, {}, stateOffline)); - }); - it("should render DisabledOffline components for each row", () => { - expect(component.find(DisableOffline)).to.have.lengthOf(9); + mountedComponent(, stateOffline); + expect(screen.getAllByTestId("offline")).toHaveLength(3); }); }); }); From 415d105caac50a35c232699fcc713206fa94b720 Mon Sep 17 00:00:00 2001 From: srinivasulu chimaladinne Date: Thu, 28 Mar 2024 14:57:17 +0530 Subject: [PATCH 2/6] Resolved PR comments --- .../components/disable-offline/component.jsx | 2 +- .../pages/export-list/container.jsx | 1 - .../pages/export-list/container.spec.js | 92 +++++++++++++++++-- 3 files changed, 85 insertions(+), 10 deletions(-) diff --git a/app/javascript/components/disable-offline/component.jsx b/app/javascript/components/disable-offline/component.jsx index a5258cfff6..0dc3ebba86 100644 --- a/app/javascript/components/disable-offline/component.jsx +++ b/app/javascript/components/disable-offline/component.jsx @@ -20,7 +20,7 @@ const Component = ({ overrideCondition, children, button, offlineTextKey }) => { if (overrideCondition || !online) { return ( -
+
{!button &&
} {cloneElement(children, { disabled: true })}
diff --git a/app/javascript/components/pages/export-list/container.jsx b/app/javascript/components/pages/export-list/container.jsx index 48709aa2fc..a37550ccd7 100644 --- a/app/javascript/components/pages/export-list/container.jsx +++ b/app/javascript/components/pages/export-list/container.jsx @@ -57,7 +57,6 @@ const ExportList = () => { {/* eslint-disable-next-line jsx-a11y/click-events-have-key-events */}
", () => { - const initialState = fromJS({ records: { bulk_exports: { @@ -108,22 +107,99 @@ describe("", () => { expect(screen.getByTestId("page-heading")).toBeInTheDocument(); }); - it("should render ", () => { - mountedComponent(, {}, initialState); - expect(screen.getByText(/messages.record_list.rows_per_page/i)).toBeInTheDocument(); - }); - it("should render ", () => { mountedComponent(, {}, initialState); expect(screen.getByText(/messages.record_list.rows_per_page/i)).toBeInTheDocument(); }); describe("when offline", () => { - const stateOffline = initialState.setIn(["application", "online"], false); + const stateOffline = fromJS({ + connectivity: { + online: false + }, + records: { + bulk_exports: { + data: [ + ExportRecord({ + id: "d5e1a4a019ec727efd34a35d1d9a271e", + file_name: "PRIMERO-CHILD-UNHCR.CSV", + record_type: "Case", + started_on: "2020-02-04T20:32:50.078Z" + }), + ExportRecord({ + id: "d5e1a4a019ec727efd34a35d1d9a272e", + file_name: "PRIMERO - CHILD.PDF", + record_type: "Case", + started_on: "2020-02-03T20:32:50.078Z" + }), + ExportRecord({ + id: "d5e1a4a019ec727efd34a35d1d9a273e", + file_name: "PRIMERO - CHILD.JSON", + record_type: "Case", + started_on: "2020-02-02T20:32:50.078Z" + }) + ], + metadata: { + total: 15, + per: 20, + page: 1 + }, + errors: false + } + }, + user: { + listHeaders: { + bulk_exports: [ + ListHeaderRecord({ + name: "file_name", + field_name: "file_name", + id_search: false + }), + ListHeaderRecord({ + name: "record_type", + field_name: "record_type", + id_search: false + }), + ListHeaderRecord({ + name: "started_on", + field_name: "started_on", + id_search: false + }) + ] + }, + permissions: { + exports: ["manage"], + bulk_exports: ["manage"] + } + }, + forms: { + fields: mapEntriesToRecord( + { + 1: { + name: "name_first", + type: "text_field" + } + }, + FieldRecord + ), + options: { + lookups: [ + { + id: 1, + unique_id: "lookup-location-type", + values: [ + { id: "country", display_text: "Country" }, + { id: "region", display_text: "Region" } + ] + } + ] + } + } + }); it("should render DisabledOffline components for each row", () => { mountedComponent(, stateOffline); - expect(screen.getAllByTestId("offline")).toHaveLength(3); + expect(screen.getAllByTestId("disable-offline")).toHaveLength(9); }); }); }); From fa1a484dfdeda3a8001ed60df2fa333636e37ea3 Mon Sep 17 00:00:00 2001 From: srinivasulu chimaladinne Date: Fri, 29 Mar 2024 18:14:31 +0530 Subject: [PATCH 3/6] Resolved PR comments --- app/javascript/components/page/components/page-content.jsx | 6 +++++- .../components/pages/export-list/container.spec.js | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/javascript/components/page/components/page-content.jsx b/app/javascript/components/page/components/page-content.jsx index 617f4d4276..5f36b09c09 100644 --- a/app/javascript/components/page/components/page-content.jsx +++ b/app/javascript/components/page/components/page-content.jsx @@ -8,7 +8,11 @@ import css from "../styles.css"; const PageContent = ({ children, flex = false, hasNav = false }) => { const contentClasses = clsx(css.content, { [css.contentFlex]: flex, [css.hasNav]: hasNav }); - return
{children}
; + return ( +
+ {children} +
+ ); }; PageContent.propTypes = { diff --git a/app/javascript/components/pages/export-list/container.spec.js b/app/javascript/components/pages/export-list/container.spec.js index 784d2bae66..92f21aa4dd 100644 --- a/app/javascript/components/pages/export-list/container.spec.js +++ b/app/javascript/components/pages/export-list/container.spec.js @@ -107,6 +107,11 @@ describe("", () => { expect(screen.getByTestId("page-heading")).toBeInTheDocument(); }); + it("should render ", () => { + mountedComponent(, {}, initialState); + expect(screen.getByTestId("page-content")).toBeInTheDocument(); + }); + it("should render ", () => { mountedComponent(, {}, initialState); expect(screen.getByText(/messages.record_list.rows_per_page/i)).toBeInTheDocument(); From 46dd49e9c5bcdd7d06298fe9c7d6a2129996159f Mon Sep 17 00:00:00 2001 From: srinivasulu chimaladinne Date: Wed, 17 Apr 2024 12:18:04 +0530 Subject: [PATCH 4/6] Reverted old test file --- .../pages/export-list/container.unit.test.js | 134 ++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 app/javascript/components/pages/export-list/container.unit.test.js diff --git a/app/javascript/components/pages/export-list/container.unit.test.js b/app/javascript/components/pages/export-list/container.unit.test.js new file mode 100644 index 0000000000..c21f5cf8f5 --- /dev/null +++ b/app/javascript/components/pages/export-list/container.unit.test.js @@ -0,0 +1,134 @@ +import { fromJS } from "immutable"; +import MUIDataTable, { TableBodyRow } from "mui-datatables"; + +import IndexTable from "../../index-table"; +import PageContainer, { PageHeading, PageContent } from "../../page"; +import { ListHeaderRecord } from "../../user/records"; +import { setupMountedComponent } from "../../../test"; +import { FieldRecord } from "../../record-form"; +import { mapEntriesToRecord } from "../../../libs"; +import DisableOffline from "../../disable-offline"; + +import { ExportRecord } from "./records"; +import ExportList from "./container"; + +describe("", () => { + let component; + + const initialState = fromJS({ + records: { + bulk_exports: { + data: [ + ExportRecord({ + id: "d5e1a4a019ec727efd34a35d1d9a271e", + file_name: "PRIMERO-CHILD-UNHCR.CSV", + record_type: "Case", + started_on: "2020-02-04T20:32:50.078Z" + }), + ExportRecord({ + id: "d5e1a4a019ec727efd34a35d1d9a272e", + file_name: "PRIMERO - CHILD.PDF", + record_type: "Case", + started_on: "2020-02-03T20:32:50.078Z" + }), + ExportRecord({ + id: "d5e1a4a019ec727efd34a35d1d9a273e", + file_name: "PRIMERO - CHILD.JSON", + record_type: "Case", + started_on: "2020-02-02T20:32:50.078Z" + }) + ], + metadata: { + total: 15, + per: 20, + page: 1 + }, + errors: false + } + }, + user: { + listHeaders: { + bulk_exports: [ + ListHeaderRecord({ + name: "file_name", + field_name: "file_name", + id_search: false + }), + ListHeaderRecord({ + name: "record_type", + field_name: "record_type", + id_search: false + }), + ListHeaderRecord({ + name: "started_on", + field_name: "started_on", + id_search: false + }) + ] + }, + permissions: { + exports: ["manage"], + bulk_exports: ["manage"] + } + }, + forms: { + fields: mapEntriesToRecord( + { + 1: { + name: "name_first", + type: "text_field" + } + }, + FieldRecord + ), + options: { + lookups: [ + { + id: 1, + unique_id: "lookup-location-type", + values: [ + { id: "country", display_text: "Country" }, + { id: "region", display_text: "Region" } + ] + } + ] + } + } + }); + + beforeEach(() => { + ({ component } = setupMountedComponent(ExportList, {}, initialState)); + }); + + it("should render a table with three rows", () => { + expect(component.find(MUIDataTable).find(TableBodyRow)).to.have.lengthOf(3); + }); + + it("should render ", () => { + expect(component.find(PageContainer)).to.have.lengthOf(1); + }); + + it("should render ", () => { + expect(component.find(PageHeading)).to.have.lengthOf(1); + }); + + it("should render ", () => { + expect(component.find(PageContent)).to.have.lengthOf(1); + }); + + it("should render ", () => { + expect(component.find(IndexTable)).to.have.lengthOf(1); + }); + + describe("when offline", () => { + const stateOffline = initialState.setIn(["application", "online"], false); + + beforeEach(() => { + ({ component } = setupMountedComponent(ExportList, {}, stateOffline)); + }); + + it("should render DisabledOffline components for each row", () => { + expect(component.find(DisableOffline)).to.have.lengthOf(9); + }); + }); +}); \ No newline at end of file From fcc9365bcc05bc4e243a2218ceb6fb4055ee91fe Mon Sep 17 00:00:00 2001 From: srinivasulu chimaladinne Date: Wed, 17 Apr 2024 12:20:07 +0530 Subject: [PATCH 5/6] deleted old test file --- .../pages/export-list/container.unit.test.js | 134 ------------------ 1 file changed, 134 deletions(-) delete mode 100644 app/javascript/components/pages/export-list/container.unit.test.js diff --git a/app/javascript/components/pages/export-list/container.unit.test.js b/app/javascript/components/pages/export-list/container.unit.test.js deleted file mode 100644 index c21f5cf8f5..0000000000 --- a/app/javascript/components/pages/export-list/container.unit.test.js +++ /dev/null @@ -1,134 +0,0 @@ -import { fromJS } from "immutable"; -import MUIDataTable, { TableBodyRow } from "mui-datatables"; - -import IndexTable from "../../index-table"; -import PageContainer, { PageHeading, PageContent } from "../../page"; -import { ListHeaderRecord } from "../../user/records"; -import { setupMountedComponent } from "../../../test"; -import { FieldRecord } from "../../record-form"; -import { mapEntriesToRecord } from "../../../libs"; -import DisableOffline from "../../disable-offline"; - -import { ExportRecord } from "./records"; -import ExportList from "./container"; - -describe("", () => { - let component; - - const initialState = fromJS({ - records: { - bulk_exports: { - data: [ - ExportRecord({ - id: "d5e1a4a019ec727efd34a35d1d9a271e", - file_name: "PRIMERO-CHILD-UNHCR.CSV", - record_type: "Case", - started_on: "2020-02-04T20:32:50.078Z" - }), - ExportRecord({ - id: "d5e1a4a019ec727efd34a35d1d9a272e", - file_name: "PRIMERO - CHILD.PDF", - record_type: "Case", - started_on: "2020-02-03T20:32:50.078Z" - }), - ExportRecord({ - id: "d5e1a4a019ec727efd34a35d1d9a273e", - file_name: "PRIMERO - CHILD.JSON", - record_type: "Case", - started_on: "2020-02-02T20:32:50.078Z" - }) - ], - metadata: { - total: 15, - per: 20, - page: 1 - }, - errors: false - } - }, - user: { - listHeaders: { - bulk_exports: [ - ListHeaderRecord({ - name: "file_name", - field_name: "file_name", - id_search: false - }), - ListHeaderRecord({ - name: "record_type", - field_name: "record_type", - id_search: false - }), - ListHeaderRecord({ - name: "started_on", - field_name: "started_on", - id_search: false - }) - ] - }, - permissions: { - exports: ["manage"], - bulk_exports: ["manage"] - } - }, - forms: { - fields: mapEntriesToRecord( - { - 1: { - name: "name_first", - type: "text_field" - } - }, - FieldRecord - ), - options: { - lookups: [ - { - id: 1, - unique_id: "lookup-location-type", - values: [ - { id: "country", display_text: "Country" }, - { id: "region", display_text: "Region" } - ] - } - ] - } - } - }); - - beforeEach(() => { - ({ component } = setupMountedComponent(ExportList, {}, initialState)); - }); - - it("should render a table with three rows", () => { - expect(component.find(MUIDataTable).find(TableBodyRow)).to.have.lengthOf(3); - }); - - it("should render ", () => { - expect(component.find(PageContainer)).to.have.lengthOf(1); - }); - - it("should render ", () => { - expect(component.find(PageHeading)).to.have.lengthOf(1); - }); - - it("should render ", () => { - expect(component.find(PageContent)).to.have.lengthOf(1); - }); - - it("should render ", () => { - expect(component.find(IndexTable)).to.have.lengthOf(1); - }); - - describe("when offline", () => { - const stateOffline = initialState.setIn(["application", "online"], false); - - beforeEach(() => { - ({ component } = setupMountedComponent(ExportList, {}, stateOffline)); - }); - - it("should render DisabledOffline components for each row", () => { - expect(component.find(DisableOffline)).to.have.lengthOf(9); - }); - }); -}); \ No newline at end of file From 34cf18c35e6df7e71c95d9dd396c4882de042ad6 Mon Sep 17 00:00:00 2001 From: srinivasulu chimaladinne Date: Fri, 17 May 2024 13:42:17 +0530 Subject: [PATCH 6/6] Resolved PR comment --- app/javascript/components/pages/export-list/container.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/javascript/components/pages/export-list/container.spec.js b/app/javascript/components/pages/export-list/container.spec.js index 92f21aa4dd..0d50381bc4 100644 --- a/app/javascript/components/pages/export-list/container.spec.js +++ b/app/javascript/components/pages/export-list/container.spec.js @@ -114,7 +114,7 @@ describe("", () => { it("should render ", () => { mountedComponent(, {}, initialState); - expect(screen.getByText(/messages.record_list.rows_per_page/i)).toBeInTheDocument(); + expect(screen.getByRole('table')).toBeInTheDocument(); }); describe("when offline", () => {