epam-ai-conductor 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/dist/content/{content/module-1/tests/Button.test.tsx → module-1/tests/Button.test.js} +8 -8
  2. package/dist/content/module-1/tests/CourseCard.test.js +68 -0
  3. package/dist/content/module-1/tests/CourseInfo.test.js +136 -0
  4. package/dist/content/module-1/tests/Courses.test.js +81 -0
  5. package/dist/content/{content/module-1/tests/Header.test.tsx → module-1/tests/Header.test.js} +5 -7
  6. package/dist/content/module-1/tests/Input.test.js +42 -0
  7. package/dist/content/module-1/tests/helpers.test.js +13 -0
  8. package/dist/content/module-2/tests/App.test.js +130 -0
  9. package/dist/content/module-2/tests/Button.test.js +22 -0
  10. package/dist/content/module-2/tests/CourseCard.test.js +93 -0
  11. package/dist/content/module-2/tests/CourseInfo.test.js +125 -0
  12. package/dist/content/module-2/tests/Courses.test.js +106 -0
  13. package/dist/content/module-2/tests/CreateCourse.test.js +117 -0
  14. package/dist/content/module-2/tests/Header.test.js +45 -0
  15. package/dist/content/module-2/tests/Input.test.js +42 -0
  16. package/dist/content/module-2/tests/Login.test.js +128 -0
  17. package/dist/content/module-2/tests/Registration.test.js +119 -0
  18. package/dist/content/module-2/tests/helpers.test.js +13 -0
  19. package/dist/content/module-2/tests/services.test.js +79 -0
  20. package/dist/content/module-3/tests/App.test.js +192 -0
  21. package/dist/content/{module-1/tests/Button.test.tsx → module-3/tests/Button.test.js} +8 -8
  22. package/dist/content/module-3/tests/CourseCard.test.js +50 -0
  23. package/dist/content/module-3/tests/CourseInfo.test.js +148 -0
  24. package/dist/content/module-3/tests/Courses.test.js +107 -0
  25. package/dist/content/module-3/tests/CreateAuthor.test.js +36 -0
  26. package/dist/content/module-3/tests/CreateCourse.test.js +66 -0
  27. package/dist/content/module-3/tests/Header.test.js +76 -0
  28. package/dist/content/module-3/tests/Input.test.js +42 -0
  29. package/dist/content/module-3/tests/Login.test.js +62 -0
  30. package/dist/content/{module-2/tests/Registration.test.tsx → module-3/tests/Registration.test.js} +13 -13
  31. package/dist/content/module-3/tests/helpers.test.js +13 -0
  32. package/dist/content/module-3/tests/services.test.js +83 -0
  33. package/dist/content/module-3/tests/slices.test.js +146 -0
  34. package/dist/content/module-4/tests/App.test.js +309 -0
  35. package/dist/content/module-4/tests/Button.test.js +22 -0
  36. package/dist/content/module-4/tests/CourseCard.test.js +111 -0
  37. package/dist/content/module-4/tests/CourseForm.test.js +108 -0
  38. package/dist/content/module-4/tests/CourseInfo.test.js +146 -0
  39. package/dist/content/module-4/tests/Courses.test.js +129 -0
  40. package/dist/content/module-4/tests/CreateAuthor.test.js +37 -0
  41. package/dist/content/module-4/tests/Header.test.js +79 -0
  42. package/dist/content/{content/module-1/tests/Input.test.tsx → module-4/tests/Input.test.js} +17 -11
  43. package/dist/content/module-4/tests/Login.test.js +61 -0
  44. package/dist/content/module-4/tests/PrivateRoute.test.js +45 -0
  45. package/dist/content/{content/module-2/tests/Registration.test.tsx → module-4/tests/Registration.test.js} +14 -13
  46. package/dist/content/module-4/tests/helpers.test.js +13 -0
  47. package/dist/content/module-4/tests/services.test.js +267 -0
  48. package/dist/content/module-4/tests/slices.test.js +146 -0
  49. package/dist/content/module-4/tests/thunk.test.js +238 -0
  50. package/package.json +4 -3
  51. package/scripts/postinstall.cjs +24 -0
  52. package/dist/content/content/module-1/task/module-1_home-task_components.md +0 -257
  53. package/dist/content/content/module-1/task/module-1_home-task_good_practices.md +0 -69
  54. package/dist/content/content/module-1/task/module-1_home-task_task.md +0 -253
  55. package/dist/content/content/module-1/tests/CourseCard.test.tsx +0 -64
  56. package/dist/content/content/module-1/tests/CourseInfo.test.tsx +0 -73
  57. package/dist/content/content/module-1/tests/Courses.test.tsx +0 -87
  58. package/dist/content/content/module-1/tests/helpers.test.ts +0 -13
  59. package/dist/content/content/module-1/theory/module-1_elements-render.md +0 -66
  60. package/dist/content/content/module-1/theory/module-1_hooks_useEffect.md +0 -178
  61. package/dist/content/content/module-1/theory/module-1_hooks_useState.md +0 -131
  62. package/dist/content/content/module-1/theory/module-1_react.md +0 -64
  63. package/dist/content/content/module-1/theory/module-1_spa.md +0 -74
  64. package/dist/content/content/module-2/task/module-2_home-task_components.md +0 -313
  65. package/dist/content/content/module-2/task/module-2_home-task_good_practices.md +0 -35
  66. package/dist/content/content/module-2/task/module-2_home-task_task.md +0 -210
  67. package/dist/content/content/module-2/tests/App.test.tsx +0 -54
  68. package/dist/content/content/module-2/tests/Login.test.tsx +0 -73
  69. package/dist/content/content/module-2/tests/SearchBar.test.tsx +0 -39
  70. package/dist/content/content/module-2/theory/module-2_custom-hooks.md +0 -201
  71. package/dist/content/content/module-2/theory/module-2_hooks.md +0 -117
  72. package/dist/content/content/module-2/theory/module-2_react-router.md +0 -328
  73. package/dist/content/content/module-3/task/module-3_home-task_components.md +0 -94
  74. package/dist/content/content/module-3/task/module-3_home-task_good_practices.md +0 -26
  75. package/dist/content/content/module-3/task/module-3_home-task_task.md +0 -170
  76. package/dist/content/content/module-3/tests/App.test.tsx +0 -54
  77. package/dist/content/content/module-3/tests/Courses.test.tsx +0 -87
  78. package/dist/content/content/module-3/tests/CreateAuthor.test.tsx +0 -44
  79. package/dist/content/content/module-3/tests/CreateCourse.test.tsx +0 -122
  80. package/dist/content/content/module-3/theory/module-3_redux-hooks.md +0 -194
  81. package/dist/content/content/module-3/theory/module-3_state-actions-reducers.md +0 -445
  82. package/dist/content/content/module-4/task/module-4_home-task_components.md +0 -187
  83. package/dist/content/content/module-4/task/module-4_home-task_task.md +0 -139
  84. package/dist/content/content/module-4/tests/App.test.tsx +0 -54
  85. package/dist/content/content/module-4/tests/Courses.test.tsx +0 -87
  86. package/dist/content/content/module-4/tests/CreateCourse.test.tsx +0 -122
  87. package/dist/content/content/module-4/tests/Login.test.tsx +0 -73
  88. package/dist/content/content/module-4/theory/module-4_async-redux.md +0 -99
  89. package/dist/content/content/module-4/theory/module-4_private-routes.md +0 -55
  90. package/dist/content/content/module-5/task/module-5_home-task_instruction.md +0 -68
  91. package/dist/content/content/module-5/task/module-5_home-task_task.md +0 -154
  92. package/dist/content/content/module-5/tests/App.test.tsx +0 -54
  93. package/dist/content/content/module-5/tests/CourseCard.test.tsx +0 -64
  94. package/dist/content/content/module-5/tests/Courses.test.tsx +0 -87
  95. package/dist/content/content/module-5/tests/Header.test.tsx +0 -23
  96. package/dist/content/content/module-5/theory/module-5_react-testing-library_example.md +0 -379
  97. package/dist/content/content/module-5/theory/module-5_redux-writing-tests.md +0 -246
  98. package/dist/content/module-1/tests/CourseCard.test.tsx +0 -64
  99. package/dist/content/module-1/tests/CourseInfo.test.tsx +0 -73
  100. package/dist/content/module-1/tests/Courses.test.tsx +0 -87
  101. package/dist/content/module-1/tests/Header.test.tsx +0 -23
  102. package/dist/content/module-1/tests/Input.test.tsx +0 -36
  103. package/dist/content/module-1/tests/helpers.test.ts +0 -13
  104. package/dist/content/module-2/tests/App.test.tsx +0 -54
  105. package/dist/content/module-2/tests/Login.test.tsx +0 -73
  106. package/dist/content/module-2/tests/SearchBar.test.tsx +0 -39
  107. package/dist/content/module-3/tests/App.test.tsx +0 -54
  108. package/dist/content/module-3/tests/Courses.test.tsx +0 -87
  109. package/dist/content/module-3/tests/CreateAuthor.test.tsx +0 -44
  110. package/dist/content/module-3/tests/CreateCourse.test.tsx +0 -122
  111. package/dist/content/module-4/tests/App.test.tsx +0 -54
  112. package/dist/content/module-4/tests/Courses.test.tsx +0 -87
  113. package/dist/content/module-4/tests/CreateCourse.test.tsx +0 -122
  114. package/dist/content/module-4/tests/Login.test.tsx +0 -73
  115. package/dist/content/module-5/tests/App.test.tsx +0 -54
  116. package/dist/content/module-5/tests/CourseCard.test.tsx +0 -64
  117. package/dist/content/module-5/tests/Courses.test.tsx +0 -87
  118. package/dist/content/module-5/tests/Header.test.tsx +0 -23
@@ -1,22 +1,22 @@
1
- import '@testing-library/jest-dom'
1
+ import "@testing-library/jest-dom";
2
2
  import { render, fireEvent, screen } from "@testing-library/react";
3
- import { Button } from "../common/Button/Button";
3
+ import { Button } from "../../common/Button";
4
4
 
5
- describe('Button component', () => {
6
- test("Should render button with provided label", () => {
5
+ describe("Button component", () => {
6
+ test("should render with provided `buttonText` prop value", () => {
7
7
  const handleClickMock = jest.fn();
8
- render(<Button buttonText='Hello' handleClick={handleClickMock}/>);
8
+ render(<Button buttonText="Hello" handleClick={handleClickMock} />);
9
9
  const buttonElement = screen.getByText("Hello");
10
10
 
11
11
  expect(buttonElement).toBeInTheDocument();
12
12
  });
13
13
 
14
- test("Should call provided callback", () => {
14
+ test("should call provided handleClick callback prop", () => {
15
15
  const handleClickMock = jest.fn();
16
- render(<Button handleClick={handleClickMock} buttonText='Click me'/>);
16
+ render(<Button handleClick={handleClickMock} buttonText="Click me" />);
17
17
  const buttonElement = screen.getByText("Click me");
18
18
 
19
19
  fireEvent.click(buttonElement);
20
20
  expect(handleClickMock).toHaveBeenCalledTimes(1);
21
21
  });
22
- })
22
+ });
@@ -0,0 +1,68 @@
1
+ import "@testing-library/jest-dom";
2
+ import { render, screen } from "@testing-library/react";
3
+ import { CourseCard } from "../../components/Courses/components/CourseCard/CourseCard";
4
+
5
+ describe("CourseCard component", () => {
6
+ const course = {
7
+ id: "1",
8
+ title: "Course Title",
9
+ description: "Course Description",
10
+ creationDate: "08/03/2021",
11
+ duration: 60,
12
+ authors: [
13
+ "27cc3006-e93a-4748-8ca8-73d06aa93b6d",
14
+ "f762978b-61eb-4096-812b-ebde22838167",
15
+ ],
16
+ };
17
+ const authorsList = [
18
+ { id: "df32994e-b23d-497c-9e4d-84e4dc02882f", name: "name1" },
19
+ { id: "27cc3006-e93a-4748-8ca8-73d06aa93b6d", name: "name2" },
20
+ { id: "f762978b-61eb-4096-812b-ebde22838167", name: "name3" },
21
+ ];
22
+
23
+ test("should render correct title from course prop", () => {
24
+ render(<CourseCard course={course} authorsList={authorsList} />);
25
+
26
+ const titleElement = screen.getByText("Course Title");
27
+
28
+ expect(titleElement).toBeInTheDocument();
29
+ });
30
+
31
+ test("should render correct description from course prop", () => {
32
+ render(<CourseCard course={course} authorsList={authorsList} />);
33
+ const descriptionElement = screen.getByText("Course Description");
34
+ expect(descriptionElement).toBeInTheDocument();
35
+ });
36
+
37
+ test("should render correct duration (use getCourseDuration e.g. duration: 60 => 01:00 hour)", () => {
38
+ render(<CourseCard course={course} authorsList={authorsList} />);
39
+
40
+ const durationElement = screen.getByText(/01:00 hour/);
41
+
42
+ expect(durationElement).toBeInTheDocument();
43
+ });
44
+
45
+ test("should render correct date (use formatCreationDate e.g. creationDate: 08/03/2021 => 08.03.2021)", () => {
46
+ render(<CourseCard course={course} authorsList={authorsList} />);
47
+
48
+ const creationDateElement = screen.getByText(/08.03.2021/);
49
+
50
+ expect(creationDateElement).toBeInTheDocument();
51
+ });
52
+
53
+ test("should render authors list (match data from props course.authors and authorsList)", () => {
54
+ render(<CourseCard course={course} authorsList={authorsList} />);
55
+
56
+ const creationDateElement = screen.getByText(/name2, name3/);
57
+
58
+ expect(creationDateElement).toBeInTheDocument();
59
+ });
60
+
61
+ test("should render 'SHOW COURSE' button", () => {
62
+ render(<CourseCard course={course} authorsList={authorsList} />);
63
+
64
+ const creationDateElement = screen.getByText(/Show course/i);
65
+
66
+ expect(creationDateElement).toBeInTheDocument();
67
+ });
68
+ });
@@ -0,0 +1,136 @@
1
+ import "@testing-library/jest-dom";
2
+ import { render, screen, fireEvent } from "@testing-library/react";
3
+ import { CourseInfo } from "../../components/CourseInfo";
4
+ import { formatCreationDate, getCourseDuration } from "../../helpers";
5
+
6
+ const mockedCoursesList = [
7
+ {
8
+ id: "1",
9
+ title: "Course 1",
10
+ description: "Course 1 description",
11
+ creationDate: "2022-01-01",
12
+ duration: 60,
13
+ authors: [
14
+ "27cc3006-e93a-4748-8ca8-73d06aa93b6d",
15
+ "f762978b-61eb-4096-812b-ebde22838167",
16
+ ],
17
+ },
18
+ {
19
+ id: "2",
20
+ title: "Course 2",
21
+ description: "Course 2 description",
22
+ creationDate: "2022-02-01",
23
+ duration: 90,
24
+ authors: ["df32994e-b23d-497c-9e4d-84e4dc02882f"],
25
+ },
26
+ ];
27
+ const authorsList = [
28
+ { id: "df32994e-b23d-497c-9e4d-84e4dc02882f", name: "name1" },
29
+ { id: "27cc3006-e93a-4748-8ca8-73d06aa93b6d", name: "name2" },
30
+ { id: "f762978b-61eb-4096-812b-ebde22838167", name: "name3" },
31
+ ];
32
+
33
+ describe("CourseInfo", () => {
34
+ test("should renders correct title (find correct course from coursesList based on showCourseId prop) ", () => {
35
+ render(
36
+ <CourseInfo
37
+ coursesList={mockedCoursesList}
38
+ authorsList={authorsList}
39
+ showCourseId="1"
40
+ />
41
+ );
42
+
43
+ const courseTitle = screen.getByRole("heading", { level: 1 });
44
+
45
+ expect(courseTitle.textContent).toBe("Course 1");
46
+ });
47
+
48
+ test("should renders correct description", () => {
49
+ render(
50
+ <CourseInfo
51
+ coursesList={mockedCoursesList}
52
+ authorsList={authorsList}
53
+ showCourseId="1"
54
+ />
55
+ );
56
+
57
+ const courseDescription = screen.getByText("Course 1 description");
58
+
59
+ expect(courseDescription).toBeInTheDocument();
60
+ });
61
+
62
+ test("should renders correct course duration (use getCourseDuration)", () => {
63
+ render(
64
+ <CourseInfo
65
+ coursesList={mockedCoursesList}
66
+ authorsList={authorsList}
67
+ showCourseId="1"
68
+ />
69
+ );
70
+
71
+ const courseDuration = screen.queryByText(getCourseDuration(60));
72
+
73
+ expect(courseDuration).toBeInTheDocument();
74
+ });
75
+
76
+ test("should renders correct course creation date (use formatCreationDate)", () => {
77
+ render(
78
+ <CourseInfo
79
+ coursesList={mockedCoursesList}
80
+ authorsList={authorsList}
81
+ showCourseId="1"
82
+ />
83
+ );
84
+
85
+ const courseCreationDate = screen.getByText(
86
+ formatCreationDate(mockedCoursesList[0].creationDate)
87
+ );
88
+ expect(courseCreationDate).toBeInTheDocument();
89
+ });
90
+
91
+ test("should renders correct course authors names (find a course in the coursesList and match data from course authors and authorsList prop)", () => {
92
+ render(
93
+ <CourseInfo
94
+ coursesList={mockedCoursesList}
95
+ authorsList={authorsList}
96
+ showCourseId="1"
97
+ />
98
+ );
99
+
100
+ const authorNames = screen
101
+ .getAllByRole("listitem")
102
+ .map((li) => li.textContent);
103
+
104
+ expect(authorNames).toEqual(["name2", "name3"]);
105
+ });
106
+
107
+ test("should render `BACK` button correctly", () => {
108
+ render(
109
+ <CourseInfo
110
+ coursesList={mockedCoursesList}
111
+ authorsList={authorsList}
112
+ showCourseId="1"
113
+ />
114
+ );
115
+
116
+ const backButton = screen.getByRole("button");
117
+
118
+ expect(backButton).toBeInTheDocument();
119
+ });
120
+
121
+ test("should call onBack handler on Back button click", () => {
122
+ const onBack = jest.fn();
123
+ render(
124
+ <CourseInfo
125
+ coursesList={mockedCoursesList}
126
+ authorsList={authorsList}
127
+ showCourseId="1"
128
+ onBack={onBack}
129
+ />
130
+ );
131
+
132
+ const backButton = screen.queryByText(/back/i);
133
+ fireEvent.click(backButton);
134
+ expect(onBack).toHaveBeenCalledTimes(1);
135
+ });
136
+ });
@@ -0,0 +1,81 @@
1
+ import "@testing-library/jest-dom";
2
+ import { render, screen } from "@testing-library/react";
3
+ import { Courses } from "../../components/Courses/Courses";
4
+
5
+ describe("Courses component", () => {
6
+ const mockedCoursesList = [
7
+ {
8
+ id: "1",
9
+ title: "Course 1",
10
+ description: "Course 1 description",
11
+ creationDate: "2022-01-01",
12
+ duration: 60,
13
+ authors: [
14
+ "27cc3006-e93a-4748-8ca8-73d06aa93b6d",
15
+ "f762978b-61eb-4096-812b-ebde22838167",
16
+ ],
17
+ },
18
+ {
19
+ id: "2",
20
+ title: "Course 2",
21
+ description: "Course 2 description",
22
+ creationDate: "2022-02-01",
23
+ duration: 90,
24
+ authors: ["df32994e-b23d-497c-9e4d-84e4dc02882f"],
25
+ },
26
+ ];
27
+ const authorsList = [
28
+ { id: "df32994e-b23d-497c-9e4d-84e4dc02882f", name: "name" },
29
+ { id: "27cc3006-e93a-4748-8ca8-73d06aa93b6d", name: "name" },
30
+ { id: "f762978b-61eb-4096-812b-ebde22838167", name: "name" },
31
+ ];
32
+ const onAddClick = jest.fn();
33
+
34
+ test("should render list of courses from coursesList prop", () => {
35
+ render(
36
+ <Courses
37
+ coursesList={mockedCoursesList}
38
+ authorsList={authorsList}
39
+ onAddClick={onAddClick}
40
+ handleShowCourse={(id) => {}}
41
+ />
42
+ );
43
+
44
+ const courseElements = screen.getAllByTestId("courseCard");
45
+
46
+ expect(courseElements[0]).toBeInTheDocument();
47
+ expect(courseElements).toHaveLength(2);
48
+ });
49
+
50
+ test("should render 'ADD NEW COURSE' button", () => {
51
+ render(
52
+ <Courses
53
+ coursesList={mockedCoursesList}
54
+ authorsList={authorsList}
55
+ onAddClick={onAddClick}
56
+ handleShowCourse={(id) => {}}
57
+ />
58
+ );
59
+
60
+ const button = screen.getByText(/Add new/i);
61
+
62
+ expect(button).toBeInTheDocument();
63
+ });
64
+
65
+ test("should render EmptycoursesList component if no courses (with 'Your List Is Empty' text and button with data-testid='addCourse')", () => {
66
+ render(
67
+ <Courses
68
+ coursesList={[]}
69
+ authorsList={authorsList}
70
+ onAddClick={onAddClick}
71
+ handleShowCourse={(id) => {}}
72
+ />
73
+ );
74
+
75
+ const emptyText = screen.queryByText(/Your List Is Empty/i);
76
+ const addButtonElement = screen.getByTestId("addCourse");
77
+
78
+ expect(emptyText).toBeInTheDocument();
79
+ expect(addButtonElement).toBeInTheDocument();
80
+ });
81
+ });
@@ -1,9 +1,9 @@
1
1
  import "@testing-library/jest-dom";
2
2
  import { render, screen } from "@testing-library/react";
3
- import { Header } from "../components/Header/Header";
3
+ import { Header } from "../../components/Header/Header";
4
4
 
5
- describe('Header component', () => {
6
- test("Should render logo", () => {
5
+ describe("Header component", () => {
6
+ test("should render logo (<img /> tag)", () => {
7
7
  render(<Header />);
8
8
 
9
9
  const imageElement = screen.getByRole("img");
@@ -11,13 +11,11 @@ describe('Header component', () => {
11
11
  expect(imageElement).toBeInTheDocument();
12
12
  });
13
13
 
14
- test("Should render logout button", () => {
14
+ test("should render logout button", () => {
15
15
  render(<Header />);
16
16
 
17
17
  const logoutButtonElement = screen.getByRole("button");
18
18
 
19
19
  expect(logoutButtonElement).toBeInTheDocument();
20
20
  });
21
- })
22
-
23
-
21
+ });
@@ -0,0 +1,42 @@
1
+ import "@testing-library/jest-dom";
2
+ import { render, fireEvent, screen } from "@testing-library/react";
3
+ import { Input } from "../../common/Input";
4
+
5
+ describe("Input component", () => {
6
+ const placeholderTextMock = "Enter a value";
7
+
8
+ test("should render input with provided labelText prop value", () => {
9
+ render(
10
+ <Input labelText="Test Input" placeholderText={placeholderTextMock} />
11
+ );
12
+
13
+ const inputElement = screen.getByLabelText("Test Input");
14
+ expect(inputElement).toBeInTheDocument();
15
+ });
16
+
17
+ test("should render input with provided placeholderText prop value", () => {
18
+ const { getByPlaceholderText } = render(
19
+ <Input labelText="Test Input" placeholderText={placeholderTextMock} />
20
+ );
21
+
22
+ expect(getByPlaceholderText(placeholderTextMock)).toBeInTheDocument();
23
+ });
24
+
25
+ test("should call provided callback for onChange event", () => {
26
+ const handleChange = jest.fn();
27
+
28
+ render(
29
+ <Input
30
+ labelText="Test Input"
31
+ onChange={handleChange}
32
+ placeholderText={placeholderTextMock}
33
+ />
34
+ );
35
+
36
+ const inputElement = screen.getByLabelText("Test Input");
37
+ fireEvent.change(inputElement, { target: { value: "Hello" } });
38
+
39
+ expect(handleChange).toHaveBeenCalledTimes(1);
40
+ expect(inputElement.value).toBe("Hello");
41
+ });
42
+ });
@@ -0,0 +1,13 @@
1
+ import { formatCreationDate, getCourseDuration } from "../../helpers";
2
+
3
+ test("formatCreationDate function returns formatted date", () => {
4
+ const date = "2022/01/01";
5
+ const formattedDate = formatCreationDate(date);
6
+ expect(formattedDate).toBe("2022.01.01");
7
+ });
8
+
9
+ test("getCourseDuration function returns formatted duration", () => {
10
+ expect(getCourseDuration(60)).toBe("01:00 hour");
11
+ expect(getCourseDuration(90)).toBe("01:30 hour");
12
+ expect(getCourseDuration(120)).toBe("02:00 hours");
13
+ });
@@ -0,0 +1,130 @@
1
+ import "@testing-library/jest-dom";
2
+ import { fireEvent, render, screen } from "@testing-library/react";
3
+ import { MemoryRouter } from "react-router-dom";
4
+ import App from "../../App";
5
+
6
+ describe("App", () => {
7
+ test('should render Login component when "token" is not present in localStorage and route "/"', () => {
8
+ localStorage.removeItem("token");
9
+ render(
10
+ <MemoryRouter initialEntries={["/"]}>
11
+ <App />
12
+ </MemoryRouter>
13
+ );
14
+
15
+ expect(
16
+ screen.getByText(/If you don't have an account you/i)
17
+ ).toBeInTheDocument();
18
+ });
19
+
20
+ test('should switch to registration page from login page on "Registration" link click', () => {
21
+ localStorage.removeItem("token");
22
+
23
+ render(
24
+ <MemoryRouter initialEntries={["/"]}>
25
+ <App />
26
+ </MemoryRouter>
27
+ );
28
+
29
+ expect(
30
+ screen.getByText(/If you don't have an account you/i)
31
+ ).toBeInTheDocument();
32
+
33
+ fireEvent.click(screen.getByText(/registration/i));
34
+
35
+ expect(screen.queryByText(/name/i)).toBeInTheDocument();
36
+ });
37
+
38
+ test('should render Registration component when route "/registration"', () => {
39
+ localStorage.removeItem("token");
40
+ render(
41
+ <MemoryRouter initialEntries={["/registration"]}>
42
+ <App />
43
+ </MemoryRouter>
44
+ );
45
+
46
+ expect(screen.queryByText(/name/i)).toBeInTheDocument();
47
+ expect(screen.queryByText(/email/i)).toBeInTheDocument();
48
+ expect(screen.queryByText(/password/i)).toBeInTheDocument();
49
+ });
50
+
51
+ test('should switch to login page from registration page on "Login" link click', () => {
52
+ localStorage.removeItem("token");
53
+ render(
54
+ <MemoryRouter initialEntries={["/registration"]}>
55
+ <App />
56
+ </MemoryRouter>
57
+ );
58
+
59
+ expect(screen.queryByText(/name/i)).toBeInTheDocument();
60
+ expect(screen.queryByText(/email/i)).toBeInTheDocument();
61
+ expect(screen.queryByText(/password/i)).toBeInTheDocument();
62
+
63
+ fireEvent.click(screen.getByRole("link", { name: /login/i }));
64
+
65
+ expect(screen.queryByText(/name/i)).not.toBeInTheDocument();
66
+ });
67
+
68
+ test('should render CourseCard components with data-testid="courseCard" when token is present in localStorage and route "/"', () => {
69
+ localStorage.setItem("token", "token");
70
+ render(
71
+ <MemoryRouter initialEntries={["/"]}>
72
+ <App />
73
+ </MemoryRouter>
74
+ );
75
+
76
+ const courseElements = screen.getAllByTestId("courseCard");
77
+
78
+ expect(courseElements[0]).toBeInTheDocument();
79
+ });
80
+
81
+ test('should render CourseForm component with "CREATE COURSE" button with data-testid="createCourseButton" if route "/courses/add"', () => {
82
+ render(
83
+ <MemoryRouter initialEntries={["/courses/add"]}>
84
+ <App />
85
+ </MemoryRouter>
86
+ );
87
+
88
+ expect(screen.getByTestId("createCourseButton")).toBeInTheDocument();
89
+ });
90
+
91
+ test('should render CourseInfo component with data-testid="courseInfo" when route "/courses/:courseId"', () => {
92
+ render(
93
+ <MemoryRouter
94
+ initialEntries={["/courses/de5aaa59-90f5-4dbc-b8a9-aaf205c551ba"]}
95
+ >
96
+ <App />
97
+ </MemoryRouter>
98
+ );
99
+
100
+ expect(screen.getByTestId("courseInfo")).toBeInTheDocument();
101
+ });
102
+
103
+ test('should render CourseInfo with data-testid="courseInfo" component after "SHOW COURSE" button click', () => {
104
+ render(
105
+ <MemoryRouter>
106
+ <App />
107
+ </MemoryRouter>
108
+ );
109
+
110
+ fireEvent.click(screen.queryAllByText(/show/i)[0]);
111
+
112
+ expect(screen.getByTestId("courseInfo")).toBeInTheDocument();
113
+ });
114
+
115
+ test('should render list of courses with data-testid="courseCard" after "BACK" button click on CourseInfo page', () => {
116
+ render(
117
+ <MemoryRouter>
118
+ <App />
119
+ </MemoryRouter>
120
+ );
121
+
122
+ fireEvent.click(screen.queryAllByText(/show/i)[0]);
123
+ expect(screen.getByTestId("courseInfo")).toBeInTheDocument();
124
+
125
+ fireEvent.click(screen.queryAllByText(/back/i)[0]);
126
+ expect(screen.getAllByTestId("courseCard").length).toBeGreaterThanOrEqual(
127
+ 1
128
+ );
129
+ });
130
+ });
@@ -0,0 +1,22 @@
1
+ import "@testing-library/jest-dom";
2
+ import { render, fireEvent, screen } from "@testing-library/react";
3
+ import { Button } from "../../common/Button";
4
+
5
+ describe("Button component", () => {
6
+ test("should render button with provided buttonText prop value", () => {
7
+ const handleClickMock = jest.fn();
8
+ render(<Button buttonText="Hello" handleClick={handleClickMock} />);
9
+ const buttonElement = screen.getByText("Hello");
10
+
11
+ expect(buttonElement).toBeInTheDocument();
12
+ });
13
+
14
+ test("should call provided handleClick callback prop", () => {
15
+ const handleClickMock = jest.fn();
16
+ render(<Button handleClick={handleClickMock} buttonText="Click me" />);
17
+ const buttonElement = screen.getByText("Click me");
18
+
19
+ fireEvent.click(buttonElement);
20
+ expect(handleClickMock).toHaveBeenCalledTimes(1);
21
+ });
22
+ });
@@ -0,0 +1,93 @@
1
+ import "@testing-library/jest-dom";
2
+ import { render, screen } from "@testing-library/react";
3
+ import { CourseCard } from "../../components/Courses/components/CourseCard/CourseCard";
4
+ import { MemoryRouter } from "react-router-dom";
5
+
6
+ describe("CourseCard component", () => {
7
+ const course = {
8
+ id: "1",
9
+ title: "Course Title",
10
+ description: "Course Description",
11
+ creationDate: "08/03/2021",
12
+ duration: 60,
13
+ authors: [
14
+ "27cc3006-e93a-4748-8ca8-73d06aa93b6d",
15
+ "f762978b-61eb-4096-812b-ebde22838167",
16
+ ],
17
+ };
18
+ const authorsList = [
19
+ { id: "df32994e-b23d-497c-9e4d-84e4dc02882f", name: "name1" },
20
+ { id: "27cc3006-e93a-4748-8ca8-73d06aa93b6d", name: "name2" },
21
+ { id: "f762978b-61eb-4096-812b-ebde22838167", name: "name3" },
22
+ ];
23
+
24
+ test("should render correct title from course prop", () => {
25
+ render(
26
+ <MemoryRouter>
27
+ <CourseCard course={course} authorsList={authorsList} />
28
+ </MemoryRouter>
29
+ );
30
+
31
+ const titleElement = screen.getByText("Course Title");
32
+
33
+ expect(titleElement).toBeInTheDocument();
34
+ });
35
+
36
+ test("should render correct description from course prop", () => {
37
+ render(
38
+ <MemoryRouter>
39
+ <CourseCard course={course} authorsList={authorsList} />
40
+ </MemoryRouter>
41
+ );
42
+ const descriptionElement = screen.getByText("Course Description");
43
+ expect(descriptionElement).toBeInTheDocument();
44
+ });
45
+
46
+ test("should render correct duration (use getCourseDuration)", () => {
47
+ render(
48
+ <MemoryRouter>
49
+ <CourseCard course={course} authorsList={authorsList} />
50
+ </MemoryRouter>
51
+ );
52
+
53
+ const durationElement = screen.getByText(/01:00 hour/i);
54
+
55
+ expect(durationElement).toBeInTheDocument();
56
+ });
57
+
58
+ test("should render correct date (use formatCreationDate)", () => {
59
+ render(
60
+ <MemoryRouter>
61
+ <CourseCard course={course} authorsList={authorsList} />
62
+ </MemoryRouter>
63
+ );
64
+
65
+ const creationDateElement = screen.getByText(/08.03.2021/);
66
+
67
+ expect(creationDateElement).toBeInTheDocument();
68
+ });
69
+
70
+ test("should render authors list (match data from props course.authors and authorsList)", () => {
71
+ render(
72
+ <MemoryRouter>
73
+ <CourseCard course={course} authorsList={authorsList} />
74
+ </MemoryRouter>
75
+ );
76
+
77
+ const creationDateElement = screen.getByText(/name2, name3/);
78
+
79
+ expect(creationDateElement).toBeInTheDocument();
80
+ });
81
+
82
+ test("should render 'SHOW COURSE' button", () => {
83
+ render(
84
+ <MemoryRouter>
85
+ <CourseCard course={course} authorsList={authorsList} />
86
+ </MemoryRouter>
87
+ );
88
+
89
+ const creationDateElement = screen.getByText(/show course/i);
90
+
91
+ expect(creationDateElement).toBeInTheDocument();
92
+ });
93
+ });