Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

adsCandidatesPageUI.test.js 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import { render, fireEvent, waitFor } from "@testing-library/react";
  2. import * as redux from "react-redux";
  3. import store from "../../store";
  4. import { mockState } from "../../mockState";
  5. import { Router } from "react-router-dom";
  6. import history from "../../store/utils/history";
  7. import AdsCandidatesPage from "../../pages/CandidatesPage/AdsCandidatesPage";
  8. describe("TableViewPage render tests", () => {
  9. var props = {
  10. history: {
  11. replace: jest.fn(),
  12. push: jest.fn(),
  13. location: {
  14. pathname: "/candidates",
  15. },
  16. },
  17. };
  18. const cont = (
  19. <redux.Provider store={store}>
  20. <Router history={history}>
  21. <AdsCandidatesPage search="" {...props} />
  22. </Router>
  23. </redux.Provider>
  24. );
  25. let spyOnUseSelector;
  26. beforeEach(() => {
  27. spyOnUseSelector = jest.spyOn(redux, "useSelector");
  28. spyOnUseSelector.mockReturnValueOnce(mockState.candidates.adsCandidates);
  29. });
  30. afterEach(() => {
  31. jest.restoreAllMocks();
  32. });
  33. it("Should render", () => {
  34. const { container } = render(cont);
  35. expect(
  36. container.getElementsByClassName("jobs-candidates-container")[0]
  37. ).toBeDefined();
  38. });
  39. it("Number of sliders should be equal to length of our adsCandidates array", () => {
  40. const { container } = render(cont);
  41. expect(container.getElementsByClassName("jobs-candidates").length).toBe(
  42. mockState.candidates.adsCandidates.length
  43. );
  44. });
  45. it("Number of candidates in slider (vissible and hidden) should be equal to the number of candidates which applied for ad", () => {
  46. const { container } = render(cont);
  47. expect(
  48. container
  49. .getElementsByClassName("jobs-candidates")[0]
  50. .getElementsByClassName("slick-slide").length
  51. ).toBe(mockState.candidates.adsCandidates[0].applicants.length);
  52. });
  53. it("Number of arrows (left and right) should be 1 because there is more than 4 candidates which applied for ad", () => {
  54. const { container } = render(cont);
  55. expect(
  56. container.getElementsByClassName("active-jobs-jobs-arrows").length
  57. ).toBe(1);
  58. });
  59. it("After clicking on right arrow of first slider, first slider should show fifth candidate as forth card of slider", async () => {
  60. const { container } = render(cont);
  61. fireEvent.click(
  62. container
  63. .getElementsByClassName("active-jobs-jobs-arrows")[0]
  64. .getElementsByTagName("button")[1]
  65. );
  66. await waitFor(() =>
  67. expect(
  68. container
  69. .getElementsByClassName("jobs-candidates")[0]
  70. .getElementsByClassName("slick-active")[0]
  71. .getElementsByClassName("candidate-card-container")[0]
  72. .getElementsByClassName("candidate-card-applicant-name")[0]
  73. .textContent
  74. ).toBe(
  75. mockState.candidates.adsCandidates[0].applicants[3].firstName +
  76. " " +
  77. mockState.candidates.adsCandidates[0].applicants[3].lastName
  78. )
  79. );
  80. });
  81. it("Should render candidate details page after clicking on candidate card", () => {
  82. const { container } = render(cont);
  83. fireEvent.click(
  84. container.getElementsByClassName("candidate-card-container")[0]
  85. );
  86. const arg = { pathname: "/candidates/1" };
  87. expect(props.history.push).toHaveBeenCalledWith(arg);
  88. });
  89. });