This repository was archived by the owner on Apr 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathUserOverview.test.tsx
More file actions
124 lines (112 loc) · 4.29 KB
/
Copy pathUserOverview.test.tsx
File metadata and controls
124 lines (112 loc) · 4.29 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import { render, screen } from "@testing-library/react";
import { HostingStatus, MeetupStatus } from "proto/api_pb";
import wrapper from "test/hookWrapper";
import { addDefaultUser, t } from "test/utils";
import {
hostingStatusLabels,
meetupStatusLabels,
} from "../../features/profile/constants";
import { ProfileUserProvider } from "../../features/profile/hooks/useProfileUser";
import UserOverview from "./UserOverview";
describe("UserOverview", () => {
beforeEach(() => {
addDefaultUser();
});
describe("when user is loaded and provided via context", () => {
it("should display the username", () => {
render(
<ProfileUserProvider user={defaultUser}>
<UserOverview showHostAndMeetAvailability={false} />
</ProfileUserProvider>,
{ wrapper }
);
expect(screen.getByText(`@${defaultUser.username}`)).toBeInTheDocument();
});
it("should display the user's name", () => {
render(
<ProfileUserProvider user={defaultUser}>
<UserOverview showHostAndMeetAvailability={false} />
</ProfileUserProvider>,
{ wrapper }
);
expect(screen.getByText(defaultUser.name)).toBeInTheDocument();
});
it("should display the user location", () => {
render(
<ProfileUserProvider user={defaultUser}>
<UserOverview showHostAndMeetAvailability={false} />
</ProfileUserProvider>,
{ wrapper }
);
expect(screen.getByText(defaultUser.city)).toBeInTheDocument();
});
describe("hosting and meeting status", () => {
const expectedLabelHosting =
hostingStatusLabels(t)[defaultUser.hostingStatus as HostingStatus];
const expectedLabelMeeting =
meetupStatusLabels(t)[defaultUser.meetupStatus as MeetupStatus];
it("should display the hosting and meeting status when showHostAndMeetAvailability is true", () => {
render(
<ProfileUserProvider user={defaultUser}>
<UserOverview showHostAndMeetAvailability />
</ProfileUserProvider>,
{ wrapper }
);
expect(screen.getByText(expectedLabelHosting)).toBeInTheDocument();
expect(screen.getByText(expectedLabelMeeting)).toBeInTheDocument();
});
it("should not display the hosting and meeting status when showHostAndMeetAvailability is false", () => {
render(
<ProfileUserProvider user={defaultUser}>
<UserOverview showHostAndMeetAvailability={false} />
</ProfileUserProvider>,
{ wrapper }
);
expect(
screen.queryByText(expectedLabelHosting)
).not.toBeInTheDocument();
expect(
screen.queryByText(expectedLabelMeeting)
).not.toBeInTheDocument();
});
});
it("should display the community and verification scores when the feature flag is enabled", () => {
const previousEnvValueVerificationEnabled =
process.env.NEXT_PUBLIC_IS_VERIFICATION_ENABLED;
process.env.NEXT_PUBLIC_IS_VERIFICATION_ENABLED = "true";
const previousEnvValuePostBetaEnabled =
process.env.NEXT_PUBLIC_IS_POST_BETA_ENABLED;
process.env.NEXT_PUBLIC_IS_POST_BETA_ENABLED = "true";
const expectedLabelCommunity = t("global:community_standing");
const expectedLabelVerification = t("global:verification_score");
render(
<ProfileUserProvider user={defaultUser}>
<UserOverview showHostAndMeetAvailability={false} />
</ProfileUserProvider>,
{ wrapper }
);
expect(screen.getByText(expectedLabelCommunity)).toBeInTheDocument();
expect(screen.getByText(expectedLabelVerification)).toBeInTheDocument();
process.env.NEXT_PUBLIC_IS_VERIFICATION_ENABLED =
previousEnvValueVerificationEnabled;
process.env.NEXT_PUBLIC_IS_POST_BETA_ENABLED =
previousEnvValuePostBetaEnabled;
});
it("should render the action buttons", () => {
render(
<ProfileUserProvider user={defaultUser}>
<UserOverview
showHostAndMeetAvailability={false}
actions={
<>
<button>Edit profile</button>
</>
}
/>
</ProfileUserProvider>,
{ wrapper }
);
expect(screen.getByText("Edit profile")).toBeInTheDocument();
});
});
});