You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
3.0 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. import React from "react";
  2. import ReactDOM from "react-dom";
  3. import { MemoryRouter } from "react-router-dom";
  4. import Routes from "./Routes";
  5. import App from "./App";
  6. import Adapter from "enzyme-adapter-react-16";
  7. import { mount, configure } from "enzyme";
  8. import Home from "./components/views/Home";
  9. import CreateElection from "./components/views/CreateElection";
  10. import Result from "./components/views/Result";
  11. import Vote from "./components/views/Vote";
  12. import UnknownView from "./components/views/UnknownView";
  13. configure({ adapter: new Adapter() });
  14. it("renders without crashing", () => {
  15. const div = document.createElement("div");
  16. ReactDOM.render(<App />, div);
  17. ReactDOM.unmountComponentAtNode(div);
  18. });
  19. describe("open good View component for each route", () => {
  20. it("should show Home view component for `/`", () => {
  21. const wrapper = mount(
  22. <MemoryRouter initialEntries={["/"]}>
  23. <Routes />
  24. </MemoryRouter>
  25. );
  26. expect(wrapper.find(Home)).toHaveLength(1);
  27. expect(wrapper.find(UnknownView)).toHaveLength(0);
  28. });
  29. it("should show CreateElection view component for `/create-election`", () => {
  30. const wrapper = mount(
  31. <MemoryRouter initialEntries={["/create-election"]}>
  32. <Routes />
  33. </MemoryRouter>
  34. );
  35. expect(wrapper.find(CreateElection)).toHaveLength(1);
  36. expect(wrapper.find(UnknownView)).toHaveLength(0);
  37. });
  38. //this test is not good because window.location.search is empty even there is ?title= parameter in route
  39. //Clement : I don't know how to achieve this test for now (maybe the component using window.location.search is not a good practice)
  40. /*it("should show CreateElection view component with title for `/create-election/?title=test%20with%20title`", () => {
  41. const wrapper = mount(
  42. <MemoryRouter
  43. initialEntries={["/create-election/?title=test%20with%20title"]}
  44. >
  45. <Routes />
  46. </MemoryRouter>
  47. );
  48. expect(wrapper.find(CreateElection)).toHaveLength(1);
  49. expect(wrapper.find('input[name="title"]').props().value).toBe(
  50. "test with title"
  51. );
  52. expect(wrapper.find(UnknownView)).toHaveLength(0);
  53. });*/
  54. it("should show UnknownView view component for `/vote`", () => {
  55. const wrapper = mount(
  56. <MemoryRouter initialEntries={["/vote"]}>
  57. <Routes />
  58. </MemoryRouter>
  59. );
  60. expect(wrapper.find(Vote)).toHaveLength(0);
  61. expect(wrapper.find(UnknownView)).toHaveLength(1);
  62. });
  63. it("should show UnknownView view component for `/result`", () => {
  64. const wrapper = mount(
  65. <MemoryRouter initialEntries={["/result"]}>
  66. <Routes />
  67. </MemoryRouter>
  68. );
  69. expect(wrapper.find(Result)).toHaveLength(0);
  70. expect(wrapper.find(UnknownView)).toHaveLength(1);
  71. });
  72. it("should show UnknownView view component for `/aaabbbcccddd`", () => {
  73. const wrapper = mount(
  74. <MemoryRouter initialEntries={["/aaabbbcccddd"]} initialIndex={0}>
  75. <Routes />
  76. </MemoryRouter>
  77. );
  78. expect(wrapper.find(UnknownView)).toHaveLength(1);
  79. });
  80. });