-
-
Notifications
You must be signed in to change notification settings - Fork 147
Expand file tree
/
Copy pathcontact.test.js
More file actions
85 lines (78 loc) · 2.57 KB
/
Copy pathcontact.test.js
File metadata and controls
85 lines (78 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { shallow } from "enzyme";
import React from "react";
import ShallowRenderer from "react-test-renderer/shallow";
import getConfig from "../../utils/get-config";
import loadTranslation from "../../utils/load-translation";
import Contact from "./contact";
jest.mock("../../utils/get-config");
jest.mock("../../utils/load-translation");
const defaultConfig = getConfig("default", true);
const links = [
{
alt: { en: "x" },
icon: "x.svg",
url: "https://x.com/openwisp",
authenticated: true,
css: "x",
},
{
alt: { en: "facebook" },
icon: "facebook.svg",
url: "https://facebook.com/openwisp",
authenticated: false,
css: "facebook",
},
{
alt: { en: "google" },
icon: "google.svg",
url: "https://google.com/openwisp",
css: "google",
},
];
const createTestProps = (props) => ({
language: "en",
orgSlug: "default",
contactPage: defaultConfig.components.contact_page,
userData: { is_verified: true },
...props,
});
describe("<Contact /> rendering with placeholder translation tags", () => {
const props = createTestProps();
it("should render translation placeholder correctly", () => {
const renderer = new ShallowRenderer();
const wrapper = renderer.render(<Contact {...props} />);
expect(wrapper).toMatchSnapshot();
});
});
describe("<Status /> rendering", () => {
let props;
beforeEach(() => {
loadTranslation("en", "default");
});
it("should render correctly", () => {
props = createTestProps();
const renderer = new ShallowRenderer();
const component = renderer.render(<Contact {...props} />);
expect(component).toMatchSnapshot();
});
it("should render without authenticated links when not authenticated", () => {
props = createTestProps();
props.contactPage.social_links = links;
props.isAuthenticated = false;
const wrapper = shallow(<Contact {...props} />);
expect(wrapper.find(".contact-image")).toHaveLength(2);
expect(wrapper.find(".link.google")).toHaveLength(1);
expect(wrapper.find(".link.facebook")).toHaveLength(1);
expect(wrapper.find(".link.x")).toHaveLength(0);
});
it("should render with authenticated links when authenticated", () => {
props = createTestProps();
props.contactPage.social_links = links;
props.isAuthenticated = true;
const wrapper = shallow(<Contact {...props} />);
expect(wrapper.find(".contact-image")).toHaveLength(2);
expect(wrapper.find(".link.google")).toHaveLength(1);
expect(wrapper.find(".link.x")).toHaveLength(1);
expect(wrapper.find(".link.facebook")).toHaveLength(0);
});
});