Guest User

Untitled

a guest
Feb 6th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.14 KB | None | 0 0
  1. describe("Templates", function() {
  2. before(function() {
  3. cy.execRake("specs:seed:templates:base");
  4. cy.login();
  5. Cypress.Cookies.preserveOnce("_forseti_session", "remember_user_token");
  6. });
  7.  
  8. const CONFIRMATION_WORD = "verwijder";
  9.  
  10. describe("design", function() {
  11. it("creates a new text node", function() {
  12. cy.server();
  13. cy.route("GET", "/api/v1/templates/**/chapters/**/comments.json?*").as("getChapterComments");
  14. cy.route("GET", "/api/v1/comments.json").as("getComments");
  15. cy.route("GET", "templates/*/chapters/new").as("newChapter");
  16. cy.route("GET", "/template_nodes/**").as("getTemplateNode");
  17. cy.route("GET", "/content_areas/**").as("getContentAreas");
  18.  
  19. cy.route("POST", "/templates/*/chapters").as("postChapter");
  20. cy.route("POST", "/content_areas/*/text_content").as("postTextContent");
  21. cy.route("POST", "/chapters/*/content_areas/").as("postChapterContentAreas");
  22.  
  23. cy.execRake("specs:seed:templates:with_nested_paragraphs");
  24.  
  25. cy.visit("/templates/new");
  26.  
  27. cy.get("#template_name").type("test template");
  28. cy.get("#template_academic_year").type("2018");
  29. cy.get(".new_template [type=\"submit\"]").click();
  30.  
  31. cy.get(".chapter-sidebar a[href$=\"/chapters/new\"]").click();
  32. cy.wait("@newChapter").then(function(xhr) {
  33. expect(xhr.status).to.eq(200);
  34. });
  35.  
  36. cy.get("#chapter_title").type("hfdst 1 test");
  37. cy.get("#new_chapter [type=\"submit\"]").click();
  38. cy.wait("@postChapter").then(function(xhr) {
  39. expect(xhr.status).to.eq(200);
  40. });
  41.  
  42. cy.get(".template-node-create:first")
  43. .then($elem => {
  44. $elem.addClass("hover");
  45. })
  46. .click();
  47. cy.wait("@getTemplateNode").then(function(xhr) {
  48. expect(xhr.status).to.eq(200);
  49. });
  50.  
  51. cy.get(".add-node-text-uneditable").click();
  52. cy.wait("@postChapterContentAreas").then(function(xhr) {
  53. expect(xhr.status).to.eq(200);
  54. });
  55.  
  56. cy.get(".text_content_content .redactor-box").click();
  57. cy.wait("@getContentAreas").then(function(xhr) {
  58. expect(xhr.status).to.eq(200);
  59. });
  60.  
  61. cy.get(".text_content_content [contenteditable=\"true\"]")
  62. .type("some example text")
  63. .wait(200);
  64. cy.get("#new_text_content [type=\"submit\"]").click();
  65.  
  66. cy.wait("@postTextContent").then(function(xhr) {
  67. expect(xhr.status).to.eq(200);
  68. });
  69. cy.wait("@getTemplateNode").then(function(xhr) {
  70. expect(xhr.status).to.eq(200);
  71. });
  72.  
  73. cy.get(".template-editor").contains("some example text");
  74. });
  75.  
  76. it("move a sub paragraph", function() {
  77. cy.server();
  78. cy.route("GET", "/api/v1/templates/**/chapters/**/comments.json?*")
  79. .as("getComments");
  80. cy.route("GET", "/template_nodes/**").as("getTemplateNode");
  81. cy.route("PATCH", "/template_nodes/*").as("updateTemplateNode");
  82.  
  83. cy.execRake("specs:seed:templates:with_nested_paragraphs");
  84.  
  85. cy.visit("/templates/1/edit/design/chapters/2");
  86. cy.wait("@getTemplateNode").then(function(xhr) {
  87. expect(xhr.status).to.eq(200);
  88. });
  89. cy.wait("@getComments").then(function(xhr) {
  90. expect(xhr.status).to.eq(200);
  91. });
  92.  
  93. cy.get(".template-node.paragraph .template-node.paragraph h2")
  94. .then($elements => $elements.map((idx, el) => el.textContent).get())
  95. .then(textContents => {
  96. expect(textContents).eqls([
  97. "1.1paragraph 1",
  98. "1.1.1paragraph 2",
  99. "1.1.2paragraph 3",
  100. ]);
  101. });
  102.  
  103.  
  104. cy.get(
  105. ".template-node.paragraph .template-node.paragraph .template-node.paragraph > .template-node-content:first",
  106. )
  107. .eq(0)
  108. .as("firstNestedParagraph")
  109. .then($elem => {
  110. $elem.addClass("hover");
  111. })
  112. .contains("paragraph 2"); // NOTE this contains 2 spaces
  113.  
  114. // top drop position
  115. let targetX = 760;
  116. let targetY = 300;
  117.  
  118. cy.get("@firstNestedParagraph")
  119. .find(".btn.sort-handle")
  120. .trigger("mousedown", { which: 1 })
  121. .trigger("mousemove", {
  122. clientX: targetX,
  123. clientY: targetY,
  124. which: 1 })
  125. .trigger("mouseup", { force: true });
  126.  
  127. cy.wait("@getTemplateNode").then(function(xhr) {
  128. expect(xhr.status).to.eq(200);
  129. });
  130. cy.wait("@updateTemplateNode").then(function(xhr) {
  131. expect(xhr.status).to.eq(204);
  132. });
  133.  
  134. // Wait for loading animation to finish. In the future we might
  135. // wait for an element to appear. Since no XHR call is triggered
  136. // this is the only thing we can do at this point.
  137. cy.wait(500); // eslint-disable-line
  138.  
  139. cy.get(".template-node.paragraph .template-node.paragraph h2")
  140. .then($elements => $elements.map((idx, el) => el.textContent).get())
  141. .then(textContents => {
  142. expect(textContents).eqls([
  143. "1.1paragraph 2",
  144. "1.2paragraph 1",
  145. "1.2.1paragraph 3",
  146. ]);
  147. });
  148.  
  149. // even when the page is reloaded (double check)
  150. cy.reload();
  151.  
  152. cy.wait('@getTemplateNode');
  153. cy.wait('@getComments');
  154.  
  155. cy.get(".template-node.paragraph .template-node.paragraph h2")
  156. .then($elements => $elements.map((idx, el) => el.textContent).get())
  157. .then(textContents => {
  158. expect(textContents).eqls([
  159. "1.1paragraph 2",
  160. "1.2paragraph 1",
  161. "1.2.1paragraph 3",
  162. ]);
  163. });
  164. });
  165.  
  166. it("deletes a chapter from a template", function() {
  167. cy.server();
  168. cy.route("GET", "/api/v1/templates/**/chapters/**/comments.json?*")
  169. .as("getComments");
  170. cy.route("GET", "/template_nodes/**").as("getTemplateNode");
  171. cy.route("GET", "/template_nodes/3?include_children=true")
  172. .as("getTemplateNodeWithChildren");
  173. cy.route("GET", "/chapters/*").as("getChapter");
  174. cy.route("GET", "/template_nodes/3/destroy_confirmation")
  175. .as("deleteTemplateNodeModal");
  176. cy.route("GET", "/templates/1/edit/design").as("getTemplateDesign");
  177.  
  178. cy.route("DELETE", "/template_nodes/*").as("deleteTemplateNode");
  179.  
  180. cy.execRake("specs:seed:templates:with_nested_paragraphs");
  181.  
  182. cy.visit("/templates/1/edit/design/chapters/2");
  183. cy.wait("@getTemplateNode").then(function(xhr) {
  184. expect(xhr.status).to.eq(200);
  185. });
  186. cy.wait("@getComments").then(function(xhr) {
  187. expect(xhr.status).to.eq(200);
  188. });
  189.  
  190. cy.get("#chapter_3")
  191. .contains("chapter 2")
  192. .click();
  193.  
  194. cy.wait("@getChapter").then(function(xhr) {
  195. expect(xhr.status).to.eq(200);
  196. });
  197. cy.wait("@getTemplateNodeWithChildren").then(function(xhr) {
  198. expect(xhr.status).to.eq(200);
  199. });
  200. cy.wait("@getComments").then(function(xhr) {
  201. expect(xhr.status).to.eq(200);
  202. });
  203.  
  204. cy.get('.chapter > :nth-child(1) > .template-node-actions > .btn-group > .dropdown-toggle').click();
  205. cy.get(
  206. ".template-node.chapter > .template-node-content > .template-node-actions a > i.fa-trash",
  207. )
  208. .parent()
  209. .click();
  210. cy.wait("@deleteTemplateNodeModal").then(function(xhr) {
  211. expect(xhr.status).to.eq(200);
  212. });
  213.  
  214. cy.get("#template-node-confirm-delete").click();
  215. cy.wait("@deleteTemplateNode").then(function(xhr) {
  216. expect(xhr.status).to.eq(200);
  217. });
  218.  
  219. cy.wait("@getTemplateDesign").then(function(xhr) {
  220. expect(xhr.status).to.eq(200);
  221. expect(xhr).to.have.property("response");
  222. expect(xhr.response).to.have.property("headers");
  223. expect(xhr.response.headers).to.have.property("turbolinks-location");
  224. expect(xhr.response.headers["turbolinks-location"]).to.contains(
  225. "/templates/1/edit/design/chapters/2",
  226. );
  227. });
  228. });
  229.  
  230. it("creates a chapter filter", function() {
  231. cy.server();
  232. cy.route("GET", "/template_nodes/2/filter*").as("getFilter");
  233. cy.route("GET", "/api/v1/templates/**/chapters/**/comments.json?*")
  234. .as("getComments");
  235. cy.route("GET", "/template_nodes/*").as("getTemplateNode");
  236.  
  237. cy.route("POST", "/template_nodes/2/filter").as("postFilter");
  238.  
  239. cy.execRake("specs:seed:templates:with_nested_paragraphs documents=3");
  240.  
  241. cy.visit("/templates/1/edit/design/chapters/2");
  242. cy.wait("@getTemplateNode").then(function(xhr) {
  243. expect(xhr.status).to.eq(200);
  244. });
  245. cy.wait("@getComments").then(function(xhr) {
  246. expect(xhr.status).to.eq(200);
  247. });
  248.  
  249. cy.get(".chapter").should("not.have.class", "filtered");
  250.  
  251. cy.get('.chapter > :nth-child(1) > .template-node-actions > .btn-group > .dropdown-toggle').click();
  252. cy.get(
  253. ".template-node.chapter > .template-node-content > .template-node-actions a > i.fa-filter",
  254. )
  255. .parent()
  256. .click();
  257.  
  258. cy.wait("@getFilter").then(xhr => {
  259. expect(xhr.status).to.eq(200);
  260. });
  261.  
  262. cy.get(
  263. ".form-group > :nth-child(2) > .btn-group > :nth-child(2)",
  264. ).click();
  265. cy.get(".select2-search__field").click();
  266. cy.get("ul.select2-results__options > li:nth-child(1)").click();
  267. cy.get(".modal-footer [type=\"submit\"]").click();
  268.  
  269. cy.wait("@postFilter").then(xhr => {
  270. expect(xhr.status).to.eq(200);
  271. });
  272.  
  273. cy.wait("@getTemplateNode").then(xhr => {
  274. expect(xhr.status).to.eq(200);
  275. });
  276.  
  277. cy.get(".chapter").find(".triangle-in-corner").should("have.length", 1);
  278. });
  279.  
  280. it("move a node to another template", function() {
  281. cy.server();
  282. cy.route("GET", "/template_nodes/11/move_to_chapter*").as("getMove");
  283. cy.route("GET", "/template_nodes/*?include_children=true").as(
  284. "reloadedChapter",
  285. );
  286. cy.route("GET", "/api/v1/templates/**/chapters/**/comments.json?*")
  287. .as("getComments");
  288.  
  289. cy.route("POST", "/template_nodes/11/move_to_chapter*").as("postMove");
  290.  
  291. cy.execRake("specs:seed:templates:with_nested_paragraphs documents=3");
  292. cy.visit("/templates/1/edit/design/chapters/2");
  293.  
  294. cy.wait("@reloadedChapter").then(function(xhr) {
  295. expect(xhr.status).to.eq(200);
  296. });
  297. cy.wait("@getComments").then(function(xhr) {
  298. expect(xhr.status).to.eq(200);
  299. });
  300.  
  301. cy.get('[data-node-id="11"] > :nth-child(1) > .template-node-actions > :nth-child(2) > .dropdown-toggle').click();
  302. cy.get(
  303. "#chapter-editor [data-node-id=\"11\"] .fa-share-square-o:first",
  304. )
  305. .parent()
  306. .click();
  307.  
  308. cy.wait("@getMove").then(function(xhr) {
  309. expect(xhr.status).to.eq(200);
  310. });
  311.  
  312. cy.get("#target_chapter_id").select("3 - chapter 3");
  313. cy.get(".modal-footer [type=\"submit\"]").click();
  314.  
  315. cy.wait("@postMove").then(function(xhr) {
  316. expect(xhr.status).to.eq(200);
  317. });
  318. cy.wait("@reloadedChapter").then(function(xhr) {
  319. expect(xhr.status).to.eq(200);
  320. });
  321.  
  322. cy.get("#chapter-editor [data-node-id=\"11\"]").should("not.exist");
  323.  
  324. cy.visit("/templates/1/edit/design/chapters/4"); // chapter 3
  325. cy.wait("@reloadedChapter").then(function(xhr) {
  326. expect(xhr.status).to.eq(200);
  327. });
  328. cy.wait("@getComments").then(function(xhr) {
  329. expect(xhr.status).to.eq(200);
  330. });
  331.  
  332. cy.get(".template-node.chapter .template-node.paragraph:first")
  333. .contains("paragraph 3")
  334. });
  335. });
  336.  
  337. describe("duplicate", function() {
  338. it("duplicates a template", function() {
  339. cy.server();
  340. cy.route("GET", "/templates/*/duplicate").as("getDuplicateTemplate");
  341. cy.route("GET", "/templates/*/edit").as("getEditTemplate");
  342. cy.route("GET", "/templates/*/edit/design").as("getDesignTemplate");
  343. cy.route("GET", "/api/v1/templates/**/chapters/**/comments.json?*")
  344. .as("getComments");
  345. cy.route("GET", "/template_nodes/*?include_children=true").as(
  346. "templateNode",
  347. );
  348.  
  349. cy.route("POST", "/templates/*/duplicate").as("duplicateTemplate");
  350.  
  351. cy.execRake("specs:seed:templates:filled");
  352. cy.visit("/templates");
  353.  
  354. cy.get("#main tbody .btn-group:first")
  355. .then($elem => {
  356. $elem.addClass("open");
  357. })
  358. .find(".dropdown-menu a:first")
  359. .contains("Dupliceren")
  360. .click();
  361. cy.get(".modal-dialog input[type=\"submit\"]").click();
  362. cy.wait("@getDuplicateTemplate").then(function(xhr) {
  363. expect(xhr.status).to.eq(200);
  364. });
  365.  
  366. // turbolinks conflicts, so lets trigger a reload
  367. cy.wait("@duplicateTemplate");
  368.  
  369. cy.get("#main tbody td a")
  370. .contains("Kopie van template 1")
  371. .click();
  372. cy.wait("@getEditTemplate").then(function(xhr) {
  373. expect(xhr.status).to.eq(200);
  374. });
  375.  
  376. cy.get(".navbar-sub-menu a")
  377. .contains("Ontwerp")
  378. .click();
  379. cy.wait("@getDesignTemplate").then(function(xhr) {
  380. expect(xhr.status).to.eq(200);
  381. });
  382. cy.wait("@getComments").then(function(xhr) {
  383. expect(xhr.status).to.eq(200);
  384. });
  385. cy.wait("@templateNode").then(function(xhr) {
  386. expect(xhr.status).to.eq(200);
  387. });
  388.  
  389. // contains 2 chapters
  390. cy.get("#chapters-list .sidebar-item.parent").should("have.length", 2);
  391. // first chapter is auto selected
  392. // and contains all content
  393. cy.get(".template-editor .template-node-content").should(
  394. "have.length",
  395. 30,
  396. );
  397. // with 7 headings
  398. cy.get(".template-editor h2")
  399. .should("have.length", 7)
  400. // including nesting
  401. .contains("1.2.2");
  402. // including a regular table and a special content table
  403. cy.get(".template-editor table").should("have.length", 4);
  404. // and an image
  405. cy.get(".template-editor .template-node-content img").should(
  406. "have.length",
  407. 2,
  408. );
  409. });
  410.  
  411. it("creates document with duplicated template", function() {
  412. cy.server();
  413. cy.route("GET", "/documents/new").as("getNewDocument");
  414. cy.route("GET", "/documents/*/activity.json?*").as("getActivity");
  415. cy.route("GET", "/api/v1/documents/*/chapters/*/comments.json?*")
  416. .as("getComments");
  417.  
  418. cy.execRake("specs:seed:templates:duplicated");
  419. cy.visit("/documents");
  420.  
  421. cy.get("#main .row.actions")
  422. .contains(" Nieuw document")
  423. .click();
  424. cy.wait("@getNewDocument").then(function(xhr) {
  425. expect(xhr.status).to.eq(200);
  426. });
  427.  
  428. cy.get("select#document_template_id").contains(/template 1/);
  429. cy.get("select#document_template_id").contains("Kopie van template 1");
  430. cy.get("select#document_template_id").select("Kopie van template 1");
  431.  
  432. // Set programme and trigger document name generation
  433. cy.get("select#document_programme_ids").then($select => {
  434. $select.val(["1"]);
  435. $select.trigger("change.select2");
  436. $select.trigger({
  437. type: "select2:select",
  438. params: {
  439. data: {
  440. id: "1",
  441. text: "Gekopieerd document",
  442. },
  443. },
  444. });
  445. });
  446.  
  447. cy.get("#new_document")
  448. .get("input[type=\"submit\"]")
  449. .click();
  450. cy.wait("@getActivity").then(function(xhr) {
  451. expect(xhr.status).to.eq(200);
  452. });
  453. cy.wait("@getComments").then(function(xhr) {
  454. expect(xhr.status).to.eq(200);
  455. });
  456.  
  457. // Should redirect to the new document
  458. cy.location().should(loc => {
  459. expect(loc.pathname).contains("/documents/");
  460. });
  461.  
  462. // Verify title and chapters
  463. cy.get("h1").contains("Gekopieerd document");
  464. cy.get("#chapter-list").contains("chapter 1");
  465. cy.get("#chapter-list").contains("chapter 2");
  466. });
  467. });
  468.  
  469. describe("workflow", function() {
  470. before(function() {
  471. cy.execRake("specs:seed:documents:with_comment");
  472. cy.login();
  473. Cypress.Cookies.preserveOnce("_forseti_session", "remember_user_token");
  474. });
  475.  
  476. beforeEach(function() {
  477. cy.visit("/templates/1/workflow");
  478. });
  479.  
  480. it("contains 4 initial workflow steps", function() {
  481. cy.get(".workflow-steps-container")
  482. .children()
  483. .should("have.length", 4);
  484. });
  485.  
  486. it("adds a new workflow step", function() {
  487. cy.server();
  488. cy.route("POST", "/templates/*/workflow/").as("postWorkflowStep");
  489.  
  490. cy.get(".options > button").click();
  491.  
  492. cy.get(".workflow-form").should("be.visible");
  493.  
  494. cy.get(".workflow-form input[name=\"name\"]").type("Fifth workflow step");
  495. cy.get(".workflow-form .switch .slider").click();
  496. cy.get(".workflow-form form").submit();
  497. cy.wait("@postWorkflowStep");
  498.  
  499. cy.get(".workflow-steps-container").children().should("have.length", 5);
  500. cy.get(".workflow-step:nth-child(5)").contains("Fifth workflow step");
  501. });
  502.  
  503. it("has a clickable progress bar in the template overview", function() {
  504. cy.server();
  505. cy.route("GET", "/templates/*/edit/publish?*").as("getPublish");
  506.  
  507. cy.visit("/templates");
  508.  
  509. cy.get("td .progress").then($bar => {
  510. const width = $bar.css("width");
  511.  
  512. cy.wrap($bar)
  513. .children()
  514. .should($item => {
  515. expect($item).to.have.length(5);
  516. expect($item[0]).to.not.have.css("width", "0px");
  517. expect($item[0]).to.have.css("width", width);
  518. expect($item[1]).to.have.css("width", "0px");
  519. expect($item[2]).to.have.css("width", "0px");
  520. expect($item[3]).to.have.css("width", "0px");
  521. expect($item[4]).to.have.css("width", "0px");
  522. });
  523.  
  524. cy.wrap($bar)
  525. .children()
  526. .first()
  527. .click();
  528.  
  529. cy.wait("@getPublish");
  530. });
  531.  
  532. cy.get("form button[type=\"button\"]").contains("Wis filters");
  533. });
  534.  
  535. it("can remove a step when multiple steps", function() {
  536. cy.server();
  537. cy.route("DELETE", "/templates/*/workflow/*").as("deleteWorkflowStep");
  538.  
  539. cy.get(".workflow-step:nth-child(5) .options button").scrollIntoView();
  540. cy.get(".workflow-step:nth-child(5) .options button").click();
  541.  
  542. cy.get(".workflow-step:nth-child(5) .options")
  543. .contains("Verwijderen")
  544. .click();
  545. cy.wait("@deleteWorkflowStep");
  546.  
  547. cy.get(".workflow-step:nth-child(5)").should("not.exist");
  548. });
  549.  
  550. it("cannot remove a step when its the only one", function() {
  551. cy.server();
  552. cy.route("DELETE", "/templates/*/workflow/*").as("deleteWorkflowStep");
  553.  
  554. cy.get(".workflow-step:nth-child(4) .options button").scrollIntoView();
  555. cy.get(".workflow-step:nth-child(4) .options button").click();
  556.  
  557. cy.get(".workflow-step:nth-child(4) .options ")
  558. .contains("Verwijderen")
  559. .click();
  560. cy.wait("@deleteWorkflowStep");
  561. cy.get(".workflow-step:nth-child(4)").should("not.exist");
  562.  
  563. cy.get(".workflow-step:nth-child(3) .options button").scrollIntoView();
  564. cy.get(".workflow-step:nth-child(3) .options button").click();
  565.  
  566. cy.get(".workflow-step:nth-child(3) .options ")
  567. .contains("Verwijderen")
  568. .click();
  569. cy.wait("@deleteWorkflowStep");
  570. cy.get(".workflow-step:nth-child(3)").should("not.exist");
  571.  
  572. cy.get(".workflow-step:nth-child(2) .options button").scrollIntoView();
  573. cy.get(".workflow-step:nth-child(2) .options button").click();
  574.  
  575. cy.get(".workflow-step:nth-child(2) .options")
  576. .contains("Verwijderen")
  577. .click();
  578. cy.wait("@deleteWorkflowStep");
  579. cy.get(".workflow-step:nth-child(2)").should("not.exist");
  580.  
  581. cy.get(".workflow-step .fa fa-trash fa-fw").should("not.exist");
  582. });
  583. });
  584.  
  585. describe("deleting", function() {
  586. it("can delete a template", function() {
  587. cy.server();
  588. cy.route("DELETE", "/templates/*").as("deleteTemplate");
  589.  
  590. cy.visit("/templates/1/edit/publish");
  591.  
  592. cy.get("tbody .actions-cell:first button:first").scrollIntoView();
  593. cy.get("tbody .actions-cell:first button:first").click();
  594. cy.get("tbody .actions-cell:first")
  595. .contains("Verwijderen")
  596. .click();
  597.  
  598. cy.get("tbody .actions-cell:first button:first").scrollIntoView();
  599. cy.get("tbody .actions-cell:first button:first").click();
  600. cy.get("tbody .actions-cell:first")
  601. .contains("Verwijderen")
  602. .click();
  603.  
  604. cy.visit("/templates");
  605.  
  606. cy.get("tbody .actions-cell:first button:first").scrollIntoView();
  607. cy.get("tbody .actions-cell:first button:first").click();
  608. cy.get("tbody .actions-cell:first")
  609. .contains("Verwijderen")
  610. .click();
  611. cy.get("#given_confirmation").type("verwijder");
  612. cy.get(".modal-footer input[type=\"submit\"]").click();
  613. cy.wait("@deleteTemplate").then(function(xhr) {
  614. expect(xhr.status).to.eq(200);
  615. });
  616.  
  617. cy.get("tbody .actions-cell").should("not.exist");
  618. });
  619.  
  620. it(
  621. "should be impossible to remove template, when there are documents",
  622. function() {
  623. const TEMPLATE_NAME = "TEMPLATE_NAME";
  624. const TEMPLATE_ACADEMIC_YEAR = "2018";
  625. const CHAPTER_TITLE = "CHAPTER_TITLE";
  626. const DOCUMENT_TITLE = "DOCUMENT_TITLE";
  627. const DOCUMENT_DESIGN_TEXT = "Ontwerp";
  628.  
  629. cy.server();
  630. cy.route(
  631. "GET",
  632. "/api/v1/templates/**/chapters/**/comments.json?resource_type=templates"
  633. ).as("getComments");
  634. cy.route("GET", "/template_nodes/**").as("getTemplateNode");
  635. cy.route("POST", "/templates/*/chapters").as("postChapters");
  636. cy.route("DELETE", "/templates/*").as("deleteTemplate");
  637. cy.route("GET", "/documents/*/activity.json?*").as("getActivities");
  638.  
  639. cy.visit("/templates");
  640.  
  641. cy.get("a.btn[href=\"/templates/new\"]").click();
  642.  
  643. cy.get("#template_name").type(TEMPLATE_NAME);
  644. cy.get("#template_academic_year").type(TEMPLATE_ACADEMIC_YEAR);
  645.  
  646. cy.get("form").submit();
  647.  
  648. cy.get(".chapter-sidebar a[href=\"/templates/2/chapters/new\"").click();
  649. cy.get("#chapter_title").type(CHAPTER_TITLE);
  650. cy.get(".modal-form form").submit();
  651. cy.wait("@postChapters").then(function(xhr) {
  652. expect(xhr.status).to.eq(200);
  653. });
  654. cy.wait("@getTemplateNode").then(function(xhr) {
  655. expect(xhr.status).to.eq(200);
  656. });
  657. cy.wait("@getComments").then(function(xhr) {
  658. expect(xhr.status).to.eq(200);
  659. });
  660.  
  661. cy.get("a[href=\"/documents\"").click();
  662. cy.get("a[href=\"/documents/new\"").click();
  663.  
  664. cy.get("#document_title").type(DOCUMENT_TITLE);
  665. cy.get(".select2-search__field").click();
  666. cy.get("ul.select2-results__options > li:nth-child(1)").click();
  667. cy.get("form").submit();
  668. cy.wait('@getActivities');
  669.  
  670. cy.visit("/templates");
  671. cy.contains(TEMPLATE_NAME)
  672. .parents("tr")
  673. .eq(0)
  674. .get(".actions-cell button")
  675. .click();
  676. cy.get(".dropdown-menu.dropdown-menu-right a[data-method=\"delete\"]")
  677. .click();
  678. cy.get("#given_confirmation").type(CONFIRMATION_WORD);
  679. cy.get(".modal-form form").submit();
  680. cy.wait("@deleteTemplate").then(function(xhr) {
  681. expect(xhr.status).to.eq(200);
  682. });
  683.  
  684. cy.get("div[role=\"alert\"]").should("exist");
  685. cy.contains(TEMPLATE_NAME).should("exist");
  686.  
  687. cy.contains(TEMPLATE_NAME).scrollIntoView();
  688. cy.contains(TEMPLATE_NAME).click();
  689.  
  690. cy.contains(DOCUMENT_DESIGN_TEXT).click();
  691. cy.wait("@getTemplateNode").then(function(xhr) {
  692. expect(xhr.status).to.eq(200);
  693. });
  694. cy.wait("@getComments").then(function(xhr) {
  695. expect(xhr.status).to.eq(200);
  696. });
  697.  
  698. cy.contains(CHAPTER_TITLE).should("exist");
  699.  
  700. cy.get("a[href=\"/documents\"").click();
  701.  
  702. cy.contains(TEMPLATE_NAME).should("exist");
  703. cy.contains(DOCUMENT_TITLE).should("exist");
  704.  
  705. cy.route('/documents/*/introduction').as('getIntroduction');
  706.  
  707. cy.contains(DOCUMENT_TITLE).click();
  708.  
  709. cy.wait('@getIntroduction');
  710. cy.wait("@getActivities").then(function(xhr) {
  711. expect(xhr.status).to.eq(200);
  712. });
  713.  
  714. cy.contains(CHAPTER_TITLE).should("exist");
  715.  
  716. cy.route('GET', '/api/v1/documents/3/chapters/*/comments.json*')
  717. .as('getComments');
  718.  
  719. cy.contains(CHAPTER_TITLE).scrollIntoView();
  720. cy.contains(CHAPTER_TITLE).parent().click();
  721. cy.wait('@getComments');
  722. cy.wait('@getActivities');
  723. cy.get(".paragraph").contains(CHAPTER_TITLE).should("exist");
  724. })
  725. });
  726. });
Add Comment
Please, Sign In to add comment