Skip to content

Commit e7bf11f

Browse files
Merge pull request #455 from primeroIMS/trigyn-testcase-flagging
Trigyn testcase flagging
2 parents e5cef77 + 7ab4e7d commit e7bf11f

15 files changed

+280
-484
lines changed

app/javascript/components/flagging/component.unit.test.js app/javascript/components/flagging/component.spec.js

+20-16
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
// Copyright (c) 2014 - 2023 UNICEF. All rights reserved.
22

3-
import { Map } from "immutable";
4-
5-
import { setupMountedComponent } from "../../test";
3+
import { mountedComponent, screen } from "test-utils";
4+
import { fromJS } from "immutable";
65

76
import Flagging from "./component";
8-
import { FlagDialog } from "./components";
7+
import { FLAG_DIALOG } from "./constants";
98

10-
describe("<Flagging /> - Component", () => {
11-
let component;
9+
describe("<FlagDialog /> - Component", () => {
10+
const props = {
11+
recordType: "cases",
12+
record: "0df32f52-4290-4ce1-b859-74ac14c081bf"
13+
};
1214

13-
before(() => {
14-
component = setupMountedComponent(
15-
Flagging,
16-
{ recordType: "cases", record: "0df32f52-4290-4ce1-b859-74ac14c081bf" },
17-
Map({
18-
records: Map({
15+
beforeEach(() => {
16+
mountedComponent(
17+
<Flagging {...props} />,
18+
fromJS({
19+
ui: { dialogs: { dialog: FLAG_DIALOG, open: true } },
20+
records: {
1921
cases: {
2022
data: {
2123
0: {
@@ -42,16 +44,18 @@ describe("<Flagging /> - Component", () => {
4244
}
4345
]
4446
}
45-
})
47+
}
4648
})
47-
).component;
49+
);
4850
});
4951

5052
it("renders Flagging form", () => {
51-
expect(component.find(Flagging)).to.have.lengthOf(1);
53+
expect(screen.getByText("buttons.flags")).toBeInTheDocument();
54+
expect(screen.getByText("flags.add_flag_tab")).toBeInTheDocument();
55+
expect(document.querySelector("#FlagForm")).toBeInTheDocument();
5256
});
5357

5458
it("renders FlagDialog", () => {
55-
expect(component.find(FlagDialog)).to.have.lengthOf(1);
59+
expect(screen.getByText("flags.title")).toBeInTheDocument();
5660
});
5761
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { mountedComponent, screen } from "test-utils";
2+
3+
import DialogTabs from "./component";
4+
5+
describe("<DialogTabs /> - Component", () => {
6+
const props = {
7+
children: [{ props: { hidetab: true } }],
8+
isBulkFlags: false,
9+
tab: 0,
10+
setTab: () => {}
11+
};
12+
13+
beforeEach(() => {
14+
mountedComponent(<DialogTabs {...props} />);
15+
});
16+
17+
it("should render the DialogTabs", () => {
18+
screen.debug();
19+
expect(screen.getByText("flags.flags_tab")).toBeInTheDocument();
20+
expect(screen.getByText("flags.add_flag_tab")).toBeInTheDocument();
21+
});
22+
});

app/javascript/components/flagging/components/dialog-tabs/component.unit.test.js

-48
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { mountedComponent, screen } from "test-utils";
2+
3+
import DialogTabs from "../dialog-tabs";
4+
5+
import FlagDialog from "./component";
6+
7+
describe("<FlagDialog />", () => {
8+
const props = {
9+
children: [{ props: { hidetab: true } }],
10+
isBulkFlags: false,
11+
tab: 0,
12+
setTab: () => {},
13+
dialogOpen: true
14+
};
15+
16+
it("should render the FlagDialog", () => {
17+
mountedComponent(<FlagDialog {...props} />);
18+
expect(screen.getByText("flags.add_flag_tab")).toBeInTheDocument();
19+
});
20+
21+
it("should render the ActionDialog", () => {
22+
mountedComponent(<FlagDialog {...props} />);
23+
expect(screen.getByText("flags.title")).toBeInTheDocument();
24+
});
25+
26+
it("should render the DialogTabs", () => {
27+
mountedComponent(<DialogTabs {...props} />);
28+
expect(screen.getAllByRole("tab")).toHaveLength(2);
29+
});
30+
});

app/javascript/components/flagging/components/flag-dialog/component.unit.test.js

-45
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { mountedComponent, screen } from "test-utils";
2+
3+
import { RECORD_TYPES } from "../../../../config/constants";
4+
5+
import FlagForm from "./component";
6+
7+
describe("<FlagForm />", () => {
8+
const props = {
9+
recordType: RECORD_TYPES.cases,
10+
record: "230590",
11+
handleActiveTab: () => {}
12+
};
13+
14+
it("renders Form", () => {
15+
mountedComponent(<FlagForm {...props} />);
16+
expect(screen.getAllByText("flags.flag_date")).toHaveLength(2);
17+
});
18+
19+
it("should render the FlagForm", () => {
20+
mountedComponent(<FlagForm {...props} />);
21+
expect(document.querySelector("#FlagForm")).toBeInTheDocument();
22+
});
23+
});

app/javascript/components/flagging/components/flag-form/component.unit.test.js

-62
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { mountedComponent, screen, cleanup } from "test-utils";
2+
import { fromJS } from "immutable";
3+
4+
import ListFlagsItemActions from "./component";
5+
6+
describe("<ListFlagsItemActions />", () => {
7+
const props = {
8+
flag: {
9+
id: 7,
10+
record_id: "d6a6dbb4-e5e9-4720-a661-e181a12fd3a0",
11+
record_type: "cases",
12+
date: "2019-08-01",
13+
message: "This is a flag 1",
14+
flagged_by: "primero",
15+
removed: false
16+
}
17+
};
18+
19+
const initialState = fromJS({
20+
user: {
21+
username: "primero"
22+
}
23+
});
24+
25+
beforeEach(() => {
26+
mountedComponent(<ListFlagsItemActions {...props} />, initialState);
27+
});
28+
29+
it("should render the ListFlagsItem", () => {
30+
expect(screen.getByText("flags.date")).toBeInTheDocument();
31+
});
32+
33+
it("should render the FormAction", () => {
34+
expect(screen.getByText("flags.resolve_button")).toBeInTheDocument();
35+
});
36+
37+
it("should render the DateFlag", () => {
38+
expect(screen.getByTestId("date")).toBeInTheDocument();
39+
});
40+
41+
describe("when user has NOT resolve_any_flag permission", () => {
42+
const stateDiffentUser = fromJS({
43+
user: {
44+
username: "primero_cp"
45+
}
46+
});
47+
48+
beforeEach(() => {
49+
cleanup();
50+
mountedComponent(<ListFlagsItemActions {...props} />, stateDiffentUser);
51+
});
52+
53+
it("should NOT render the ActionButton", () => {
54+
const buttonElement = screen.queryByRole("button", { name: /resolve_button/i });
55+
56+
expect(buttonElement).not.toBeInTheDocument();
57+
});
58+
});
59+
});

0 commit comments

Comments
 (0)