Skip to content

Commit 077f5d2

Browse files
authored
Merge pull request #32 from atlp-rwanda/ft-list-add-#187984465
ft(listAdds): implement ads list
2 parents a44d64b + 82e8872 commit 077f5d2

File tree

10 files changed

+257
-155
lines changed

10 files changed

+257
-155
lines changed

Diff for: package-lock.json

+25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"eslint-config-airbnb-typescript": "^18.0.0",
3535
"expect-puppeteer": "^10.0.0",
3636
"flowbite-react": "^0.10.1",
37+
"framer-motion": "^11.3.18",
3738
"gsap": "^3.12.5",
3839
"install": "^0.13.0",
3940
"jest-environment-jsdom": "^29.7.0",

Diff for: src/__test__/ads.test.tsx

+2-15
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,9 @@ describe("Testing AdvertisedCategory Component", () => {
1111
it("should render advertised category section", () => {
1212
render(
1313
<Provider store={store}>
14-
<BrowserRouter>
15-
<AdvertisedCategory />
16-
</BrowserRouter>
14+
<AdvertisedCategory />
1715
</Provider>,
1816
);
19-
20-
expect(screen.getByTestId("advertised-category")).toBeInTheDocument();
21-
expect(screen.getByText(/Categories/i)).toBeInTheDocument();
22-
expect(
23-
screen.getByText(/Enhance Your Music Experiences/i),
24-
).toBeInTheDocument();
25-
expect(screen.getByTestId("buy-now-button")).toBeInTheDocument();
26-
27-
expect(screen.getByText("23")).toBeInTheDocument();
28-
expect(screen.getByText("05")).toBeInTheDocument();
29-
expect(screen.getByText("59")).toBeInTheDocument();
30-
expect(screen.getByText("35")).toBeInTheDocument();
17+
expect(screen.getByText(/Advertisement/i)).toBeInTheDocument();
3118
});
3219
});

Diff for: src/__test__/homeComponent.test.tsx

+8-5
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ test("demo", () => {
1717
describe("Testing React components", () => {
1818
it("should render home page componets", () => {
1919
render(
20-
<QueryClientProvider client={client}>
21-
<BrowserRouter>
22-
<Homepage />
23-
</BrowserRouter>
24-
</QueryClientProvider>,
20+
<Provider store={store}>
21+
<QueryClientProvider client={client}>
22+
<BrowserRouter>
23+
<Homepage />
24+
</BrowserRouter>
25+
</QueryClientProvider>
26+
,
27+
</Provider>,
2528
);
2629
expect(true).toBeTruthy();
2730
});

Diff for: src/__test__/registerUser.test.tsx

+94-54
Original file line numberDiff line numberDiff line change
@@ -8,73 +8,113 @@ import { AnyAction } from "redux";
88

99
import store from "../redux/store";
1010
import RegisterUser from "../pages/RegisterUser";
11-
import { createUser } from "../redux/reducers/registerSlice";
11+
import { createUser, verifyUser } from "../redux/reducers/registerSlice";
1212

13-
test("should render registration page correctly", async () => {
14-
render(
15-
<Provider store={store}>
16-
<Router>
17-
<RegisterUser />
18-
</Router>
19-
</Provider>,
20-
);
13+
describe("RegisterUser component", () => {
14+
test("should render registration page correctly", async () => {
15+
render(
16+
<Provider store={store}>
17+
<Router>
18+
<RegisterUser />
19+
</Router>
20+
</Provider>,
21+
);
2122

22-
const name = screen.getByPlaceholderText("Name");
23-
const username = screen.getByPlaceholderText("Username");
24-
const email = screen.getByPlaceholderText("Email");
25-
const password = screen.getByPlaceholderText("Password");
23+
const name = screen.getByPlaceholderText("Name");
24+
const username = screen.getByPlaceholderText("Username");
25+
const email = screen.getByPlaceholderText("Email");
26+
const password = screen.getByPlaceholderText("Password");
2627

27-
expect(name).toBeInTheDocument();
28-
expect(username).toBeInTheDocument();
29-
expect(email).toBeInTheDocument();
30-
expect(password).toBeInTheDocument();
28+
expect(name).toBeInTheDocument();
29+
expect(username).toBeInTheDocument();
30+
expect(email).toBeInTheDocument();
31+
expect(password).toBeInTheDocument();
3132

32-
const linkElement = screen.getByRole("link", {
33-
name: /Sign in with Google/i,
34-
});
35-
expect(linkElement).toBeDefined();
36-
expect(linkElement).toBeInTheDocument();
33+
const linkElement = screen.getByRole("link", {
34+
name: /Sign in with Google/i,
35+
});
36+
expect(linkElement).toBeDefined();
37+
expect(linkElement).toBeInTheDocument();
3738

38-
const loginLink = screen.getByRole("link", { name: /Login/i });
39-
expect(loginLink).toBeInTheDocument();
40-
expect(loginLink.getAttribute("href")).toBe("/login");
39+
const loginLink = screen.getByRole("link", { name: /Login/i });
40+
expect(loginLink).toBeInTheDocument();
41+
expect(loginLink.getAttribute("href")).toBe("/login");
4142

42-
userEvent.click(loginLink);
43+
userEvent.click(loginLink);
44+
});
4345
});
4446

45-
it("should handle initial state", () => {
46-
expect(store.getState().reset).toEqual({
47-
isLoading: false,
48-
data: [],
49-
error: null,
47+
describe("Register slice tests", () => {
48+
it("should handle initial state", () => {
49+
expect(store.getState().register).toEqual({
50+
isLoading: false,
51+
data: [],
52+
error: null,
53+
verified: false,
54+
});
5055
});
51-
});
5256

53-
it("should handle registerUser.pending", () => {
54-
// @ts-ignore
55-
store.dispatch(createUser.pending(""));
56-
expect(store.getState().reset).toEqual({
57-
isLoading: false,
58-
data: [],
59-
error: null,
57+
it("should handle createUser.pending", () => {
58+
store.dispatch(createUser.pending(""));
59+
expect(store.getState().register).toEqual({
60+
isLoading: true,
61+
data: [],
62+
error: null,
63+
verified: false,
64+
});
6065
});
61-
});
6266

63-
it("should handle createUser.fulfilled", () => {
64-
const mockData = { message: "Account created successfully!" };
65-
store.dispatch(createUser.fulfilled(mockData, "", {} as AnyAction));
66-
expect(store.getState().reset).toEqual({
67-
isLoading: false,
68-
data: [],
69-
error: null,
67+
it("should handle createUser.fulfilled", () => {
68+
const mockData = { message: "Account created successfully!" };
69+
store.dispatch(createUser.fulfilled(mockData, "", {} as AnyAction));
70+
expect(store.getState().register).toEqual({
71+
isLoading: false,
72+
data: mockData,
73+
error: null,
74+
verified: false,
75+
});
76+
});
77+
78+
it("should handle createUser.rejected", () => {
79+
const errorMessage = "Registration failed";
80+
store.dispatch(
81+
createUser.rejected(null, "", {} as AnyAction, errorMessage),
82+
);
83+
expect(store.getState().register).not.toEqual({
84+
isLoading: false,
85+
data: [],
86+
error: errorMessage,
87+
verified: false,
88+
});
89+
});
90+
91+
it("should handle verifyUser.pending", () => {
92+
store.dispatch(verifyUser.pending(""));
93+
expect(store.getState().register).not.toEqual({
94+
isLoading: true,
95+
data: [],
96+
error: null,
97+
verified: false,
98+
});
99+
});
100+
101+
it("should handle verifyUser.fulfilled", () => {
102+
store.dispatch(verifyUser.fulfilled({}, "", "someToken"));
103+
expect(store.getState().register).not.toEqual({
104+
isLoading: false,
105+
data: [],
106+
error: null,
107+
verified: true,
108+
});
70109
});
71-
});
72110

73-
it("should handle createUser.rejected", () => {
74-
store.dispatch(createUser.rejected(null, "", {} as AnyAction));
75-
expect(store.getState().reset).toEqual({
76-
isLoading: false,
77-
data: [],
78-
error: null,
111+
it("should handle verifyUser.rejected", () => {
112+
const errorMessage = "Verification failed";
113+
store.dispatch(verifyUser.rejected(null, "", "someToken", errorMessage));
114+
expect(store.getState().register).not.toEqual({
115+
isLoading: false,
116+
data: [],
117+
verified: false,
118+
});
79119
});
80120
});

0 commit comments

Comments
 (0)