Skip to content

Commit b464a5d

Browse files
Merge pull request #466 from primeroIMS/trigyn-testcases-login
Trigyn testcases login
2 parents e490fdb + be5c2cc commit b464a5d

15 files changed

+385
-428
lines changed

app/javascript/components/login/component.jsx

+5-9
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import IdpSelection from "./components/idp-selection";
1414
import LoginForm from "./components/login-form";
1515
import { getLoading, getUseIdentityProvider } from "./selectors";
1616

17-
const Container = ({ modal }) => {
17+
function Component({ modal = false }) {
1818
const useIdentity = useMemoizedSelector(state => getUseIdentityProvider(state));
1919
const isLoading = useMemoizedSelector(state => getLoading(state));
2020
const location = useLocation();
@@ -39,16 +39,12 @@ const Container = ({ modal }) => {
3939
<LoginComponent modal={modal} />
4040
</LoadingIndicator>
4141
);
42-
};
43-
44-
Container.displayName = NAME;
42+
}
4543

46-
Container.defaultProps = {
47-
modal: false
48-
};
44+
Component.displayName = NAME;
4945

50-
Container.propTypes = {
46+
Component.propTypes = {
5147
modal: PropTypes.bool
5248
};
5349

54-
export default Container;
50+
export default Component;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { mountedComponent, screen } from "../../test-utils";
2+
3+
import Login from "./component";
4+
5+
describe("<Login />", () => {
6+
describe("for login form", () => {
7+
it("renders form", () => {
8+
mountedComponent(<Login />, {
9+
idp: {
10+
use_identity_provider: false
11+
},
12+
user: {
13+
module: "primero",
14+
agency: "unicef",
15+
isAuthenticated: false
16+
}
17+
});
18+
});
19+
screen.debug();
20+
expect(screen.queryByText((content, element) => element.tagName.toLowerCase() === "form")).toBeInTheDocument();
21+
});
22+
23+
describe("for provider selection", () => {
24+
it("renders login selection", () => {
25+
mountedComponent(<Login />, {
26+
idp: {
27+
use_identity_provider: true,
28+
identity_providers: [
29+
{
30+
name: "UNICEF",
31+
type: "b2c",
32+
domain_hint: "unicef",
33+
authority: "authority",
34+
client_id: "clientid",
35+
scope: ["scope"],
36+
redirect_uri: "redirect"
37+
}
38+
]
39+
}
40+
});
41+
});
42+
screen.debug();
43+
expect(screen.queryByTestId("PrimeroIdpSelect")).toBeInTheDocument();
44+
});
45+
});

app/javascript/components/login/component.unit.test.js

-66
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { mountedComponent, screen } from "../../../../../test-utils";
2+
3+
import PrimeroIdpLink from "./primero-idp-link";
4+
5+
describe("<PrimeroIdpLink />", () => {
6+
const props = {
7+
identityProviders: [
8+
new Map([
9+
["unique_id", "primeroims"],
10+
["name", "Primero"]
11+
]),
12+
new Map([
13+
["unique_id", "randomidp"],
14+
["name", "RandomIDP"]
15+
])
16+
],
17+
css: {},
18+
dispatch: jest.fn(),
19+
i18n: {
20+
t: () => {}
21+
}
22+
};
23+
24+
it("renders forms components", () => {
25+
mountedComponent(<PrimeroIdpLink {...props} />);
26+
expect(screen.getByText((content, element) => element.tagName.toLowerCase() === "span")).toBeInTheDocument();
27+
expect(screen.getByText((content, element) => element.tagName.toLowerCase() === "a")).toBeInTheDocument();
28+
});
29+
30+
describe("when primeroims is the only one", () => {
31+
const propsOnlyPrimeroIDP = {
32+
identityProviders: [
33+
new Map([
34+
["unique_id", "primeroims"],
35+
["name", "Primero"]
36+
])
37+
],
38+
css: {},
39+
dispatch: jest.fn(),
40+
i18n: {
41+
t: () => {}
42+
}
43+
};
44+
45+
it("renders forms components", () => {
46+
mountedComponent(<PrimeroIdpLink {...propsOnlyPrimeroIDP} />);
47+
48+
expect(screen.getByText((content, element) => element.tagName.toLowerCase() === "span")).toBeInTheDocument();
49+
expect(screen.getByText((content, element) => element.tagName.toLowerCase() === "a")).toBeInTheDocument();
50+
});
51+
});
52+
53+
describe("when there is only one IDP but not primeroims", () => {
54+
const propsOnlyPrimeroIDP = {
55+
identityProviders: [
56+
new Map([
57+
["unique_id", "primeroims"],
58+
["name", "Primero"]
59+
]),
60+
new Map([
61+
["unique_id", "randomidp"],
62+
["name", "RandomIDP"]
63+
])
64+
],
65+
css: {},
66+
dispatch: jest.fn(),
67+
i18n: {
68+
t: () => {}
69+
}
70+
};
71+
72+
it("renders forms components", () => {
73+
mountedComponent(<PrimeroIdpLink {...propsOnlyPrimeroIDP} />);
74+
75+
expect(document.querySelectorAll("a")).toHaveLength(1);
76+
});
77+
});
78+
});

app/javascript/components/login/components/idp-selection/components/primero-idp-link.unit.test.js

-90
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { mountedComponent, screen } from "../../../../../test-utils";
2+
3+
import PrimeroIdpSelect from "./primero-idp-select";
4+
5+
describe("<PrimeroIdpSelect />", () => {
6+
const props = {
7+
identityProviders: [
8+
new Map([
9+
["unique_id", "primeroims"],
10+
["name", "Primero"]
11+
]),
12+
new Map([
13+
["unique_id", "randomidp"],
14+
["name", "RandomIDP"]
15+
])
16+
],
17+
css: {}
18+
};
19+
20+
mountedComponent(<PrimeroIdpSelect {...props} />);
21+
22+
it("renders forms components", () => {
23+
expect(screen.getByText(/select_provider/i)).toBeInTheDocument();
24+
expect(screen.getByRole("combobox")).toBeInTheDocument();
25+
expect(screen.getByText((content, element) => element.tagName.toLowerCase() === "form")).toBeInTheDocument();
26+
expect(screen.getByText(/go/i)).toBeInTheDocument();
27+
});
28+
});

app/javascript/components/login/components/idp-selection/components/primero-idp-select.unit.test.js

-36
This file was deleted.

0 commit comments

Comments
 (0)