Skip to content

Commit 8d69b7a

Browse files
Merge pull request #467 from primeroIMS/trigyn-testcases-layouts
Trigyn testcases layouts
2 parents b464a5d + ab18db2 commit 8d69b7a

File tree

7 files changed

+309
-328
lines changed

7 files changed

+309
-328
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
import { fromJS } from "immutable";
2+
3+
import { mountedComponent, screen, userEvent, stub } from "../../../../test-utils";
4+
5+
import AppLayout from "./component";
6+
7+
describe("<AppLayout />", () => {
8+
describe("if hasUserPermissions is true", () => {
9+
const state = fromJS({
10+
ui: {
11+
Nav: {
12+
drawerOpen: true
13+
}
14+
},
15+
user: {
16+
modules: "primero",
17+
agency: "unicef",
18+
isAuthenticated: true,
19+
messages: null,
20+
permissions: {
21+
incidents: ["manage"],
22+
tracing_requests: ["manage"],
23+
cases: ["manage"]
24+
}
25+
},
26+
application: {
27+
baseLanguage: "en",
28+
primero: {
29+
sandbox_ui: true
30+
},
31+
modules: [
32+
{
33+
unique_id: "primeromodule-cp",
34+
name: "CP",
35+
associated_record_types: ["case"]
36+
}
37+
]
38+
},
39+
records: {
40+
support: {
41+
data: {
42+
demo: true
43+
}
44+
}
45+
}
46+
});
47+
48+
it("renders navigation", () => {
49+
mountedComponent(<AppLayout />, state);
50+
expect(screen.getAllByAltText("Primero")).toHaveLength(3);
51+
expect(screen.getAllByRole("img", { className: "logo" })).toHaveLength(2);
52+
});
53+
54+
it("navigate to cases list", async () => {
55+
const user = userEvent.setup();
56+
const { history } = mountedComponent(<AppLayout />, state);
57+
58+
expect(screen.getAllByText("navigation.cases", { selector: "span" })).toHaveLength(2);
59+
await user.click(screen.getAllByText("navigation.cases")[0]);
60+
expect(history.location.pathname).toBe("/cases");
61+
});
62+
63+
it("renders DemoIndicator component", () => {
64+
mountedComponent(<AppLayout />, state);
65+
expect(screen.queryAllByText(/sandbox_ui/i)).toHaveLength(2);
66+
});
67+
});
68+
69+
describe("if hasUserPermissions is false", () => {
70+
const state = fromJS({
71+
ui: {
72+
Nav: {
73+
drawerOpen: true
74+
}
75+
},
76+
user: {
77+
module: "primero",
78+
agency: "unicef",
79+
isAuthenticated: true,
80+
messages: null
81+
},
82+
application: {
83+
baseLanguage: "en"
84+
}
85+
});
86+
87+
it("should render CircularProgress", () => {
88+
mountedComponent(<AppLayout />, state);
89+
expect(screen.getByRole("progressbar")).toBeInTheDocument();
90+
});
91+
92+
it("renders DemoIndicator component", () => {
93+
mountedComponent(<AppLayout />, state);
94+
expect(screen.queryAllByText(/sandbox_ui/i)).toHaveLength(0);
95+
});
96+
});
97+
98+
describe("when the mobile is displayed", () => {
99+
beforeEach(() => {
100+
stub(window, "matchMedia").returns(window.defaultMediaQueryList({ matches: true }));
101+
});
102+
103+
it("should not render the DemoIndicator", () => {
104+
const initialState = fromJS({
105+
ui: {
106+
Nav: {
107+
drawerOpen: false
108+
}
109+
},
110+
user: {
111+
modules: "primero",
112+
agency: "unicef",
113+
isAuthenticated: true,
114+
messages: null,
115+
permissions: {
116+
incidents: ["manage"],
117+
tracing_requests: ["manage"],
118+
cases: ["manage"]
119+
}
120+
},
121+
application: {
122+
baseLanguage: "en",
123+
modules: [
124+
{
125+
unique_id: "primeromodule-cp",
126+
name: "CP",
127+
associated_record_types: ["case"]
128+
}
129+
],
130+
primero: {
131+
sandbox_ui: false
132+
}
133+
},
134+
records: {
135+
support: {
136+
data: {
137+
demo: true
138+
}
139+
}
140+
}
141+
});
142+
143+
mountedComponent(<AppLayout />, initialState);
144+
145+
expect(screen.queryAllByText(/sandbox_ui/i)).toHaveLength(0);
146+
});
147+
148+
afterEach(() => {
149+
window.matchMedia.restore();
150+
});
151+
});
152+
});

app/javascript/components/layouts/components/app-layout/component.unit.test.js

-158
This file was deleted.

app/javascript/components/layouts/components/empty-layout/component.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const Component = ({ children }) => {
1414
<>
1515
<DemoIndicator isDemo={demo} />
1616
{children}
17-
<SessionTimeoutDialog />
17+
<SessionTimeoutDialog data-testid="session-time-dialog"/>
1818
</>
1919
);
2020
};

0 commit comments

Comments
 (0)