test.tsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. Copyright (C) 2017 Cloudbase Solutions SRL
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. import React from "react";
  15. import { shallow } from "enzyme";
  16. import sinon from "sinon";
  17. import TW from "@src/utils/TestWrapper";
  18. import ReplicaDetailsContent from ".";
  19. const wrap = props =>
  20. new TW(shallow(<ReplicaDetailsContent {...props} />), "rdContent");
  21. const endpoints = [
  22. { id: "endpoint-1", name: "Endpoint OPS", type: "openstack" },
  23. { id: "endpoint-2", name: "Endpoint AZURE", type: "azure" },
  24. ];
  25. const item = {
  26. origin_endpoint_id: "endpoint-1",
  27. destination_endpoint_id: "endpoint-2",
  28. id: "item-id",
  29. created_at: new Date(2017, 10, 24, 16, 15),
  30. destination_environment: { description: "A description" },
  31. type: "Replica",
  32. executions: [
  33. { id: "execution-1", status: "ERROR", created_at: new Date() },
  34. { id: "execution-2", status: "COMPLETED", created_at: new Date() },
  35. { id: "execution-2-1", status: "CANCELED", created_at: new Date() },
  36. { id: "execution-3", status: "RUNNING", created_at: new Date() },
  37. ],
  38. };
  39. describe("ReplicaDetailsContent Component", () => {
  40. it("renders main details page", () => {
  41. const wrapper = wrap({ endpoints, item, page: "" });
  42. expect(wrapper.find("mainDetails").prop("item").id).toBe("item-id");
  43. });
  44. it("renders executions page", () => {
  45. const wrapper = wrap({ endpoints, item, page: "executions" });
  46. expect(wrapper.find("executions").prop("item").executions[1].id).toBe(
  47. "execution-2"
  48. );
  49. });
  50. it("renders details loading", () => {
  51. const wrapper = wrap({ endpoints, item, page: "", detailsLoading: true });
  52. expect(wrapper.find("mainDetails").prop("loading")).toBe(true);
  53. });
  54. it("renders schedule page", () => {
  55. const wrapper = wrap({
  56. endpoints,
  57. item,
  58. page: "schedule",
  59. scheduleStore: { schedules: [] },
  60. });
  61. expect(wrapper.find("schedule").prop("schedules").length).toBe(0);
  62. });
  63. it("has `Create migration` button disabled if endpoint is missing", () => {
  64. const wrapper = wrap({ endpoints, item: null, page: "" });
  65. const bottomControls = new TW(
  66. shallow(wrapper.find("mainDetails").prop("bottomControls")),
  67. "rdContent"
  68. );
  69. expect(bottomControls.find("createButton").prop("disabled")).toBe(true);
  70. });
  71. it("has `Create migration` button enabled if the last status is completed", () => {
  72. const newItem = {
  73. ...item,
  74. executions: [
  75. ...item.executions,
  76. { id: "execution-4", status: "COMPLETED", created_at: new Date() },
  77. ],
  78. };
  79. const wrapper = wrap({ endpoints, item: newItem, page: "" });
  80. const bottomControls = new TW(
  81. shallow(wrapper.find("mainDetails").prop("bottomControls")),
  82. "rdContent"
  83. );
  84. expect(bottomControls.find("createButton").prop("disabled")).toBe(false);
  85. });
  86. it("dispaches create migration click", () => {
  87. const onCreateMigrationClick = sinon.spy();
  88. const wrapper = wrap({ endpoints, item, page: "", onCreateMigrationClick });
  89. const bottomControls = new TW(
  90. shallow(wrapper.find("mainDetails").prop("bottomControls")),
  91. "rdContent"
  92. );
  93. bottomControls.find("createButton").click();
  94. expect(onCreateMigrationClick.calledOnce).toBe(true);
  95. });
  96. it("has `Create migration` button disabled if endpoint is missing and last status is completed", () => {
  97. const newItem = {
  98. ...item,
  99. origin_endpoint_id: "missing",
  100. executions: [
  101. ...item.executions,
  102. { id: "execution-4", status: "COMPLETED", created_at: new Date() },
  103. ],
  104. };
  105. const wrapper = wrap({ endpoints, item: newItem, page: "" });
  106. const bottomControls = new TW(
  107. shallow(wrapper.find("mainDetails").prop("bottomControls")),
  108. "rdContent"
  109. );
  110. expect(bottomControls.find("createButton").prop("disabled")).toBe(true);
  111. });
  112. it("dispatches delete click", () => {
  113. const onDeleteReplicaClick = sinon.spy();
  114. const wrapper = wrap({ endpoints, item, page: "", onDeleteReplicaClick });
  115. const bottomControls = new TW(
  116. shallow(wrapper.find("mainDetails").prop("bottomControls")),
  117. "rdContent"
  118. );
  119. bottomControls.find("deleteButton").click();
  120. expect(onDeleteReplicaClick.calledOnce).toBe(true);
  121. });
  122. });