Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- describe("Templates", function() {
- before(function() {
- cy.execRake("specs:seed:templates:base");
- cy.login();
- Cypress.Cookies.preserveOnce("_forseti_session", "remember_user_token");
- });
- const CONFIRMATION_WORD = "verwijder";
- describe("design", function() {
- it("creates a new text node", function() {
- cy.server();
- cy.route("GET", "/api/v1/templates/**/chapters/**/comments.json?*").as("getChapterComments");
- cy.route("GET", "/api/v1/comments.json").as("getComments");
- cy.route("GET", "templates/*/chapters/new").as("newChapter");
- cy.route("GET", "/template_nodes/**").as("getTemplateNode");
- cy.route("GET", "/content_areas/**").as("getContentAreas");
- cy.route("POST", "/templates/*/chapters").as("postChapter");
- cy.route("POST", "/content_areas/*/text_content").as("postTextContent");
- cy.route("POST", "/chapters/*/content_areas/").as("postChapterContentAreas");
- cy.execRake("specs:seed:templates:with_nested_paragraphs");
- cy.visit("/templates/new");
- cy.get("#template_name").type("test template");
- cy.get("#template_academic_year").type("2018");
- cy.get(".new_template [type=\"submit\"]").click();
- cy.get(".chapter-sidebar a[href$=\"/chapters/new\"]").click();
- cy.wait("@newChapter").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- cy.get("#chapter_title").type("hfdst 1 test");
- cy.get("#new_chapter [type=\"submit\"]").click();
- cy.wait("@postChapter").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- cy.get(".template-node-create:first")
- .then($elem => {
- $elem.addClass("hover");
- })
- .click();
- cy.wait("@getTemplateNode").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- cy.get(".add-node-text-uneditable").click();
- cy.wait("@postChapterContentAreas").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- cy.get(".text_content_content .redactor-box").click();
- cy.wait("@getContentAreas").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- cy.get(".text_content_content [contenteditable=\"true\"]")
- .type("some example text")
- .wait(200);
- cy.get("#new_text_content [type=\"submit\"]").click();
- cy.wait("@postTextContent").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- cy.wait("@getTemplateNode").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- cy.get(".template-editor").contains("some example text");
- });
- it("move a sub paragraph", function() {
- cy.server();
- cy.route("GET", "/api/v1/templates/**/chapters/**/comments.json?*")
- .as("getComments");
- cy.route("GET", "/template_nodes/**").as("getTemplateNode");
- cy.route("PATCH", "/template_nodes/*").as("updateTemplateNode");
- cy.execRake("specs:seed:templates:with_nested_paragraphs");
- cy.visit("/templates/1/edit/design/chapters/2");
- cy.wait("@getTemplateNode").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- cy.wait("@getComments").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- cy.get(".template-node.paragraph .template-node.paragraph h2")
- .then($elements => $elements.map((idx, el) => el.textContent).get())
- .then(textContents => {
- expect(textContents).eqls([
- "1.1paragraph 1",
- "1.1.1paragraph 2",
- "1.1.2paragraph 3",
- ]);
- });
- cy.get(
- ".template-node.paragraph .template-node.paragraph .template-node.paragraph > .template-node-content:first",
- )
- .eq(0)
- .as("firstNestedParagraph")
- .then($elem => {
- $elem.addClass("hover");
- })
- .contains("paragraph 2"); // NOTE this contains 2 spaces
- // top drop position
- let targetX = 760;
- let targetY = 300;
- cy.get("@firstNestedParagraph")
- .find(".btn.sort-handle")
- .trigger("mousedown", { which: 1 })
- .trigger("mousemove", {
- clientX: targetX,
- clientY: targetY,
- which: 1 })
- .trigger("mouseup", { force: true });
- cy.wait("@getTemplateNode").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- cy.wait("@updateTemplateNode").then(function(xhr) {
- expect(xhr.status).to.eq(204);
- });
- // Wait for loading animation to finish. In the future we might
- // wait for an element to appear. Since no XHR call is triggered
- // this is the only thing we can do at this point.
- cy.wait(500); // eslint-disable-line
- cy.get(".template-node.paragraph .template-node.paragraph h2")
- .then($elements => $elements.map((idx, el) => el.textContent).get())
- .then(textContents => {
- expect(textContents).eqls([
- "1.1paragraph 2",
- "1.2paragraph 1",
- "1.2.1paragraph 3",
- ]);
- });
- // even when the page is reloaded (double check)
- cy.reload();
- cy.wait('@getTemplateNode');
- cy.wait('@getComments');
- cy.get(".template-node.paragraph .template-node.paragraph h2")
- .then($elements => $elements.map((idx, el) => el.textContent).get())
- .then(textContents => {
- expect(textContents).eqls([
- "1.1paragraph 2",
- "1.2paragraph 1",
- "1.2.1paragraph 3",
- ]);
- });
- });
- it("deletes a chapter from a template", function() {
- cy.server();
- cy.route("GET", "/api/v1/templates/**/chapters/**/comments.json?*")
- .as("getComments");
- cy.route("GET", "/template_nodes/**").as("getTemplateNode");
- cy.route("GET", "/template_nodes/3?include_children=true")
- .as("getTemplateNodeWithChildren");
- cy.route("GET", "/chapters/*").as("getChapter");
- cy.route("GET", "/template_nodes/3/destroy_confirmation")
- .as("deleteTemplateNodeModal");
- cy.route("GET", "/templates/1/edit/design").as("getTemplateDesign");
- cy.route("DELETE", "/template_nodes/*").as("deleteTemplateNode");
- cy.execRake("specs:seed:templates:with_nested_paragraphs");
- cy.visit("/templates/1/edit/design/chapters/2");
- cy.wait("@getTemplateNode").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- cy.wait("@getComments").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- cy.get("#chapter_3")
- .contains("chapter 2")
- .click();
- cy.wait("@getChapter").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- cy.wait("@getTemplateNodeWithChildren").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- cy.wait("@getComments").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- cy.get('.chapter > :nth-child(1) > .template-node-actions > .btn-group > .dropdown-toggle').click();
- cy.get(
- ".template-node.chapter > .template-node-content > .template-node-actions a > i.fa-trash",
- )
- .parent()
- .click();
- cy.wait("@deleteTemplateNodeModal").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- cy.get("#template-node-confirm-delete").click();
- cy.wait("@deleteTemplateNode").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- cy.wait("@getTemplateDesign").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- expect(xhr).to.have.property("response");
- expect(xhr.response).to.have.property("headers");
- expect(xhr.response.headers).to.have.property("turbolinks-location");
- expect(xhr.response.headers["turbolinks-location"]).to.contains(
- "/templates/1/edit/design/chapters/2",
- );
- });
- });
- it("creates a chapter filter", function() {
- cy.server();
- cy.route("GET", "/template_nodes/2/filter*").as("getFilter");
- cy.route("GET", "/api/v1/templates/**/chapters/**/comments.json?*")
- .as("getComments");
- cy.route("GET", "/template_nodes/*").as("getTemplateNode");
- cy.route("POST", "/template_nodes/2/filter").as("postFilter");
- cy.execRake("specs:seed:templates:with_nested_paragraphs documents=3");
- cy.visit("/templates/1/edit/design/chapters/2");
- cy.wait("@getTemplateNode").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- cy.wait("@getComments").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- cy.get(".chapter").should("not.have.class", "filtered");
- cy.get('.chapter > :nth-child(1) > .template-node-actions > .btn-group > .dropdown-toggle').click();
- cy.get(
- ".template-node.chapter > .template-node-content > .template-node-actions a > i.fa-filter",
- )
- .parent()
- .click();
- cy.wait("@getFilter").then(xhr => {
- expect(xhr.status).to.eq(200);
- });
- cy.get(
- ".form-group > :nth-child(2) > .btn-group > :nth-child(2)",
- ).click();
- cy.get(".select2-search__field").click();
- cy.get("ul.select2-results__options > li:nth-child(1)").click();
- cy.get(".modal-footer [type=\"submit\"]").click();
- cy.wait("@postFilter").then(xhr => {
- expect(xhr.status).to.eq(200);
- });
- cy.wait("@getTemplateNode").then(xhr => {
- expect(xhr.status).to.eq(200);
- });
- cy.get(".chapter").find(".triangle-in-corner").should("have.length", 1);
- });
- it("move a node to another template", function() {
- cy.server();
- cy.route("GET", "/template_nodes/11/move_to_chapter*").as("getMove");
- cy.route("GET", "/template_nodes/*?include_children=true").as(
- "reloadedChapter",
- );
- cy.route("GET", "/api/v1/templates/**/chapters/**/comments.json?*")
- .as("getComments");
- cy.route("POST", "/template_nodes/11/move_to_chapter*").as("postMove");
- cy.execRake("specs:seed:templates:with_nested_paragraphs documents=3");
- cy.visit("/templates/1/edit/design/chapters/2");
- cy.wait("@reloadedChapter").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- cy.wait("@getComments").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- cy.get('[data-node-id="11"] > :nth-child(1) > .template-node-actions > :nth-child(2) > .dropdown-toggle').click();
- cy.get(
- "#chapter-editor [data-node-id=\"11\"] .fa-share-square-o:first",
- )
- .parent()
- .click();
- cy.wait("@getMove").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- cy.get("#target_chapter_id").select("3 - chapter 3");
- cy.get(".modal-footer [type=\"submit\"]").click();
- cy.wait("@postMove").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- cy.wait("@reloadedChapter").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- cy.get("#chapter-editor [data-node-id=\"11\"]").should("not.exist");
- cy.visit("/templates/1/edit/design/chapters/4"); // chapter 3
- cy.wait("@reloadedChapter").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- cy.wait("@getComments").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- cy.get(".template-node.chapter .template-node.paragraph:first")
- .contains("paragraph 3")
- });
- });
- describe("duplicate", function() {
- it("duplicates a template", function() {
- cy.server();
- cy.route("GET", "/templates/*/duplicate").as("getDuplicateTemplate");
- cy.route("GET", "/templates/*/edit").as("getEditTemplate");
- cy.route("GET", "/templates/*/edit/design").as("getDesignTemplate");
- cy.route("GET", "/api/v1/templates/**/chapters/**/comments.json?*")
- .as("getComments");
- cy.route("GET", "/template_nodes/*?include_children=true").as(
- "templateNode",
- );
- cy.route("POST", "/templates/*/duplicate").as("duplicateTemplate");
- cy.execRake("specs:seed:templates:filled");
- cy.visit("/templates");
- cy.get("#main tbody .btn-group:first")
- .then($elem => {
- $elem.addClass("open");
- })
- .find(".dropdown-menu a:first")
- .contains("Dupliceren")
- .click();
- cy.get(".modal-dialog input[type=\"submit\"]").click();
- cy.wait("@getDuplicateTemplate").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- // turbolinks conflicts, so lets trigger a reload
- cy.wait("@duplicateTemplate");
- cy.get("#main tbody td a")
- .contains("Kopie van template 1")
- .click();
- cy.wait("@getEditTemplate").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- cy.get(".navbar-sub-menu a")
- .contains("Ontwerp")
- .click();
- cy.wait("@getDesignTemplate").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- cy.wait("@getComments").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- cy.wait("@templateNode").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- // contains 2 chapters
- cy.get("#chapters-list .sidebar-item.parent").should("have.length", 2);
- // first chapter is auto selected
- // and contains all content
- cy.get(".template-editor .template-node-content").should(
- "have.length",
- 30,
- );
- // with 7 headings
- cy.get(".template-editor h2")
- .should("have.length", 7)
- // including nesting
- .contains("1.2.2");
- // including a regular table and a special content table
- cy.get(".template-editor table").should("have.length", 4);
- // and an image
- cy.get(".template-editor .template-node-content img").should(
- "have.length",
- 2,
- );
- });
- it("creates document with duplicated template", function() {
- cy.server();
- cy.route("GET", "/documents/new").as("getNewDocument");
- cy.route("GET", "/documents/*/activity.json?*").as("getActivity");
- cy.route("GET", "/api/v1/documents/*/chapters/*/comments.json?*")
- .as("getComments");
- cy.execRake("specs:seed:templates:duplicated");
- cy.visit("/documents");
- cy.get("#main .row.actions")
- .contains(" Nieuw document")
- .click();
- cy.wait("@getNewDocument").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- cy.get("select#document_template_id").contains(/template 1/);
- cy.get("select#document_template_id").contains("Kopie van template 1");
- cy.get("select#document_template_id").select("Kopie van template 1");
- // Set programme and trigger document name generation
- cy.get("select#document_programme_ids").then($select => {
- $select.val(["1"]);
- $select.trigger("change.select2");
- $select.trigger({
- type: "select2:select",
- params: {
- data: {
- id: "1",
- text: "Gekopieerd document",
- },
- },
- });
- });
- cy.get("#new_document")
- .get("input[type=\"submit\"]")
- .click();
- cy.wait("@getActivity").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- cy.wait("@getComments").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- // Should redirect to the new document
- cy.location().should(loc => {
- expect(loc.pathname).contains("/documents/");
- });
- // Verify title and chapters
- cy.get("h1").contains("Gekopieerd document");
- cy.get("#chapter-list").contains("chapter 1");
- cy.get("#chapter-list").contains("chapter 2");
- });
- });
- describe("workflow", function() {
- before(function() {
- cy.execRake("specs:seed:documents:with_comment");
- cy.login();
- Cypress.Cookies.preserveOnce("_forseti_session", "remember_user_token");
- });
- beforeEach(function() {
- cy.visit("/templates/1/workflow");
- });
- it("contains 4 initial workflow steps", function() {
- cy.get(".workflow-steps-container")
- .children()
- .should("have.length", 4);
- });
- it("adds a new workflow step", function() {
- cy.server();
- cy.route("POST", "/templates/*/workflow/").as("postWorkflowStep");
- cy.get(".options > button").click();
- cy.get(".workflow-form").should("be.visible");
- cy.get(".workflow-form input[name=\"name\"]").type("Fifth workflow step");
- cy.get(".workflow-form .switch .slider").click();
- cy.get(".workflow-form form").submit();
- cy.wait("@postWorkflowStep");
- cy.get(".workflow-steps-container").children().should("have.length", 5);
- cy.get(".workflow-step:nth-child(5)").contains("Fifth workflow step");
- });
- it("has a clickable progress bar in the template overview", function() {
- cy.server();
- cy.route("GET", "/templates/*/edit/publish?*").as("getPublish");
- cy.visit("/templates");
- cy.get("td .progress").then($bar => {
- const width = $bar.css("width");
- cy.wrap($bar)
- .children()
- .should($item => {
- expect($item).to.have.length(5);
- expect($item[0]).to.not.have.css("width", "0px");
- expect($item[0]).to.have.css("width", width);
- expect($item[1]).to.have.css("width", "0px");
- expect($item[2]).to.have.css("width", "0px");
- expect($item[3]).to.have.css("width", "0px");
- expect($item[4]).to.have.css("width", "0px");
- });
- cy.wrap($bar)
- .children()
- .first()
- .click();
- cy.wait("@getPublish");
- });
- cy.get("form button[type=\"button\"]").contains("Wis filters");
- });
- it("can remove a step when multiple steps", function() {
- cy.server();
- cy.route("DELETE", "/templates/*/workflow/*").as("deleteWorkflowStep");
- cy.get(".workflow-step:nth-child(5) .options button").scrollIntoView();
- cy.get(".workflow-step:nth-child(5) .options button").click();
- cy.get(".workflow-step:nth-child(5) .options")
- .contains("Verwijderen")
- .click();
- cy.wait("@deleteWorkflowStep");
- cy.get(".workflow-step:nth-child(5)").should("not.exist");
- });
- it("cannot remove a step when its the only one", function() {
- cy.server();
- cy.route("DELETE", "/templates/*/workflow/*").as("deleteWorkflowStep");
- cy.get(".workflow-step:nth-child(4) .options button").scrollIntoView();
- cy.get(".workflow-step:nth-child(4) .options button").click();
- cy.get(".workflow-step:nth-child(4) .options ")
- .contains("Verwijderen")
- .click();
- cy.wait("@deleteWorkflowStep");
- cy.get(".workflow-step:nth-child(4)").should("not.exist");
- cy.get(".workflow-step:nth-child(3) .options button").scrollIntoView();
- cy.get(".workflow-step:nth-child(3) .options button").click();
- cy.get(".workflow-step:nth-child(3) .options ")
- .contains("Verwijderen")
- .click();
- cy.wait("@deleteWorkflowStep");
- cy.get(".workflow-step:nth-child(3)").should("not.exist");
- cy.get(".workflow-step:nth-child(2) .options button").scrollIntoView();
- cy.get(".workflow-step:nth-child(2) .options button").click();
- cy.get(".workflow-step:nth-child(2) .options")
- .contains("Verwijderen")
- .click();
- cy.wait("@deleteWorkflowStep");
- cy.get(".workflow-step:nth-child(2)").should("not.exist");
- cy.get(".workflow-step .fa fa-trash fa-fw").should("not.exist");
- });
- });
- describe("deleting", function() {
- it("can delete a template", function() {
- cy.server();
- cy.route("DELETE", "/templates/*").as("deleteTemplate");
- cy.visit("/templates/1/edit/publish");
- cy.get("tbody .actions-cell:first button:first").scrollIntoView();
- cy.get("tbody .actions-cell:first button:first").click();
- cy.get("tbody .actions-cell:first")
- .contains("Verwijderen")
- .click();
- cy.get("tbody .actions-cell:first button:first").scrollIntoView();
- cy.get("tbody .actions-cell:first button:first").click();
- cy.get("tbody .actions-cell:first")
- .contains("Verwijderen")
- .click();
- cy.visit("/templates");
- cy.get("tbody .actions-cell:first button:first").scrollIntoView();
- cy.get("tbody .actions-cell:first button:first").click();
- cy.get("tbody .actions-cell:first")
- .contains("Verwijderen")
- .click();
- cy.get("#given_confirmation").type("verwijder");
- cy.get(".modal-footer input[type=\"submit\"]").click();
- cy.wait("@deleteTemplate").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- cy.get("tbody .actions-cell").should("not.exist");
- });
- it(
- "should be impossible to remove template, when there are documents",
- function() {
- const TEMPLATE_NAME = "TEMPLATE_NAME";
- const TEMPLATE_ACADEMIC_YEAR = "2018";
- const CHAPTER_TITLE = "CHAPTER_TITLE";
- const DOCUMENT_TITLE = "DOCUMENT_TITLE";
- const DOCUMENT_DESIGN_TEXT = "Ontwerp";
- cy.server();
- cy.route(
- "GET",
- "/api/v1/templates/**/chapters/**/comments.json?resource_type=templates"
- ).as("getComments");
- cy.route("GET", "/template_nodes/**").as("getTemplateNode");
- cy.route("POST", "/templates/*/chapters").as("postChapters");
- cy.route("DELETE", "/templates/*").as("deleteTemplate");
- cy.route("GET", "/documents/*/activity.json?*").as("getActivities");
- cy.visit("/templates");
- cy.get("a.btn[href=\"/templates/new\"]").click();
- cy.get("#template_name").type(TEMPLATE_NAME);
- cy.get("#template_academic_year").type(TEMPLATE_ACADEMIC_YEAR);
- cy.get("form").submit();
- cy.get(".chapter-sidebar a[href=\"/templates/2/chapters/new\"").click();
- cy.get("#chapter_title").type(CHAPTER_TITLE);
- cy.get(".modal-form form").submit();
- cy.wait("@postChapters").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- cy.wait("@getTemplateNode").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- cy.wait("@getComments").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- cy.get("a[href=\"/documents\"").click();
- cy.get("a[href=\"/documents/new\"").click();
- cy.get("#document_title").type(DOCUMENT_TITLE);
- cy.get(".select2-search__field").click();
- cy.get("ul.select2-results__options > li:nth-child(1)").click();
- cy.get("form").submit();
- cy.wait('@getActivities');
- cy.visit("/templates");
- cy.contains(TEMPLATE_NAME)
- .parents("tr")
- .eq(0)
- .get(".actions-cell button")
- .click();
- cy.get(".dropdown-menu.dropdown-menu-right a[data-method=\"delete\"]")
- .click();
- cy.get("#given_confirmation").type(CONFIRMATION_WORD);
- cy.get(".modal-form form").submit();
- cy.wait("@deleteTemplate").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- cy.get("div[role=\"alert\"]").should("exist");
- cy.contains(TEMPLATE_NAME).should("exist");
- cy.contains(TEMPLATE_NAME).scrollIntoView();
- cy.contains(TEMPLATE_NAME).click();
- cy.contains(DOCUMENT_DESIGN_TEXT).click();
- cy.wait("@getTemplateNode").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- cy.wait("@getComments").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- cy.contains(CHAPTER_TITLE).should("exist");
- cy.get("a[href=\"/documents\"").click();
- cy.contains(TEMPLATE_NAME).should("exist");
- cy.contains(DOCUMENT_TITLE).should("exist");
- cy.route('/documents/*/introduction').as('getIntroduction');
- cy.contains(DOCUMENT_TITLE).click();
- cy.wait('@getIntroduction');
- cy.wait("@getActivities").then(function(xhr) {
- expect(xhr.status).to.eq(200);
- });
- cy.contains(CHAPTER_TITLE).should("exist");
- cy.route('GET', '/api/v1/documents/3/chapters/*/comments.json*')
- .as('getComments');
- cy.contains(CHAPTER_TITLE).scrollIntoView();
- cy.contains(CHAPTER_TITLE).parent().click();
- cy.wait('@getComments');
- cy.wait('@getActivities');
- cy.get(".paragraph").contains(CHAPTER_TITLE).should("exist");
- })
- });
- });
Add Comment
Please, Sign In to add comment