From 1e0cf6713b843ae4a3cf722e1c68e0a4a22c96e3 Mon Sep 17 00:00:00 2001 From: Max <53796487+dyedwiper@users.noreply.github.com> Date: Wed, 11 Dec 2024 16:34:58 +0100 Subject: [PATCH 1/2] BC-7909 POC for tldraw test (#269) * Implemented tldraw test * implemented improved pre- and post-condition handling * fixed addDeleteParticipants.feature --------- Co-authored-by: Constantin Bergatt Co-authored-by: bergatco <129839305+bergatco@users.noreply.github.com> Co-authored-by: Christian Spohr --- cypress.config.js | 3 +- .../tldraw/createTLdrawWithContent.feature | 51 ++++++++ cypress/support/pages/course/pageCourses.js | 7 +- .../support/pages/course_board/pageBoard.js | 116 +++++++++--------- cypress/support/pages/room/pageRooms.js | 4 +- cypress/support/pages/tldraw/pageTldraw.js | 34 +++++ .../prePostConditionSteps.spec.js | 43 +++++++ .../course/commonCourseSteps.spec.js | 28 +++-- .../course_board/commonBoardSteps.spec.js | 12 +- .../openDrawingElementOnBoardSteps.spec.js | 4 + .../tldraw/tldrawSteps.spec.js | 28 +++++ package-lock.json | 9 +- package.json | 4 +- 13 files changed, 254 insertions(+), 89 deletions(-) create mode 100644 cypress/e2e/tldraw/createTLdrawWithContent.feature create mode 100644 cypress/support/pages/tldraw/pageTldraw.js create mode 100644 cypress/support/step_definition/common_helper/prePostConditionSteps.spec.js create mode 100644 cypress/support/step_definition/tldraw/tldrawSteps.spec.js diff --git a/cypress.config.js b/cypress.config.js index 5bb80022..40b21a05 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -97,8 +97,7 @@ module.exports = defineConfig({ specPattern: "cypress/e2e/**/*.feature", supportFile: "cypress/support/e2e.js", setupNodeEvents, - // testIsolation is set to false because when testIsolation is set to true or in v12 its anyway by default enabled, then it clears the page again that might be redundant. // we are using cy.session() in login custom command, which is inheriting the testIsolation properties by default as true and clearing the page (cookies, local storage..etc.) in the test. - testIsolation: false, + testIsolation: true, }, }); diff --git a/cypress/e2e/tldraw/createTLdrawWithContent.feature b/cypress/e2e/tldraw/createTLdrawWithContent.feature new file mode 100644 index 00000000..6e4eb159 --- /dev/null +++ b/cypress/e2e/tldraw/createTLdrawWithContent.feature @@ -0,0 +1,51 @@ +@regression_test +@stable_test +Feature: TLDraw - Test tldraw on board + + Scenario: I can create a whiteboard element and draw on it + # pre-condition: creating accounts + Given I am logged in as a '' at '' + Given I am logged in as a '' at '' + Given I am logged in as a '' at '' + + # pre-condition admin creates a course + Given a course with name '' exists with '' as teacher and '' as student + + # pre-condition: teacher creates a board with column and a card + Given I am logged in as a '' at '' + Given a board exists in course '' + Given the board has a column with a card + + # teacher creates a whiteboard element in the card and draws on it + When I click on plus icon to add content into card + When I select whiteboard from the menu + When I click on the whiteboard element + When I click on the pencil tool + When I draw a line on the canvas with startpoint '100', '100' and endpoint '300', '300' + When I click on the text tool + When I type text '' on the canvas on position '200', '500' + Then I should see the line drawn + Then I should see the text '' drawn + + # student can access the whiteboard element and see the drawing + Given I am logged in as a '' at '' + When I go to courses overview + When I go to course '' + When I click on the board + When I click on the whiteboard element + Then I should see the line drawn + Then I should see the text '' drawn + + # post-condition: clean up the created course + Given I am logged in as a '' at '' + Given course with name '' is deleted + + @school_api_test + Examples: + | namespace | admin | teacher | teacher_fullname | student | student_fullname | course_name | board_name | text_to_write | + | dbc | admin1_dbc | teacher1_dbc | cypress teacher_1 | student1_dbc | cypress student_1 | CypressAut TLDraw Course | CypressAut TLDraw Board | Hello World! | + + @staging_test + Examples: + | namespace | admin | teacher | teacher_fullname | student | student_fullname | course_name | board_name | text_to_write | + | brb | admin1_brb | teacher1_brb | Karl Herzog | student1_brb | Herbert Kraft | CypressAut TLDraw Course | CypressAut TLDraw Board | Hello World! | diff --git a/cypress/support/pages/course/pageCourses.js b/cypress/support/pages/course/pageCourses.js index f0f08d33..09fd1e1d 100644 --- a/cypress/support/pages/course/pageCourses.js +++ b/cypress/support/pages/course/pageCourses.js @@ -58,7 +58,7 @@ class Courses { static #courseTimeTableContainer = '[data-timesref="#timesContainer"]'; static #addClassToCourseSelectionBox = '[id="addClassesToCourse_chosen"]'; static #addStudentToCourseSelectionBox = '[id="addStudentsToCourse_chosen"]'; - static #nextButtonToCreateCourseOnParticipationDeatilStep = '[id="nextSection"]'; + static #nextButtonToCreateCourseOnParticipationDetailStep = '[id="nextSection"]'; static #sectionThreeAreaOnCourseCreationPage = '[data-testid="section-3-area"]'; static #sectionOneAreaOnCourseCreationPage = '[data-testid="section-1-area"]'; static #sectionTwoAreaOnCourseCreationPage = '[data-testid="section-2-area"]'; @@ -270,7 +270,8 @@ class Courses { } clickOnNextStepButtonOnCourseParticipationDetail() { - cy.get(Courses.#nextButtonToCreateCourseOnParticipationDeatilStep).click(); + cy.get(Courses.#nextButtonToCreateCourseOnParticipationDetailStep).click(); + cy.wait(500); } seeCourseCreationFinishPageSectionThree() { @@ -297,7 +298,7 @@ class Courses { cy.get(Courses.#courseOverviewNavigationButton).click(); } - navigateToCourseBoard(courseName) { + navigateToCoursePage(courseName) { cy.contains(Courses.#courseTitleInCourseoverview, courseName) .should("be.visible") .then((title) => { diff --git a/cypress/support/pages/course_board/pageBoard.js b/cypress/support/pages/course_board/pageBoard.js index 4ac04c31..9939541b 100644 --- a/cypress/support/pages/course_board/pageBoard.js +++ b/cypress/support/pages/course_board/pageBoard.js @@ -21,7 +21,8 @@ class Board { static #columnPlaceholder = '[placeholder="Spalte 1"]'; static #newColumnBoardFABInCourseDetail = '[data-testid="fab_button_add_board"]'; static #threeDotInCourseBoardTitle = '[data-testid="board-menu-icon"]'; - static #editOptionInThreeDotCourseBoardTitle = '[data-testid="board-menu-action-edit"]'; + static #editOptionInThreeDotCourseBoardTitle = + '[data-testid="board-menu-action-edit"]'; static #draftChipInCourseBoardName = '[data-testid="board-draft-chip"]'; static #addCardInColumnButton = '[data-testid="column-0-add-card-btn"]'; static #addContentIntoCardButton = '[data-testid="add-element-btn"]'; @@ -37,8 +38,8 @@ class Board { static #singleColumnBoardOptionInDialogBox = '[data-testid="dialog-add-single-column-board"]'; static #editButtonInThreeDotMenu = '[data-testid="board-menu-action"]'; - static #externalToolElementAlert = '[data-testid="board-external-tool-element-alert"]'; - + static #externalToolElementAlert = + '[data-testid="board-external-tool-element-alert"]'; clickPlusIconToAddCardInColumn() { cy.get(Board.#addCardInColumnButton).click(); @@ -53,7 +54,7 @@ class Board { } seeWhiteboardOnPage() { - cy.get(Board.#drawingElement).should('exist'); + cy.get(Board.#drawingElement).should("exist"); } selectExternalToolsFromMenu() { @@ -124,6 +125,10 @@ class Board { cy.get(Board.#addColumnTitleInput).should("not.exist"); } + clickOnWhiteboardElement() { + cy.get(Board.#drawingElement).invoke("removeAttr", "target").click(); + } + clickOnOpenTldrawDrawingElement() { let clickSpy; @@ -240,18 +245,19 @@ class Board { } seePreferredExternalToolInMenu(toolName) { - cy.get(`[data-testid="create-element-preferred-element-${toolName}"]`) - .should("be.visible"); + cy.get(`[data-testid="create-element-preferred-element-${toolName}"]`).should( + "be.visible" + ); } selectPreferredExternalToolFromMenu(toolName) { - cy.get(`[data-testid="create-element-preferred-element-${toolName}"]`) - .click(); + cy.get(`[data-testid="create-element-preferred-element-${toolName}"]`).click(); } preferredExternalToolIsNotVisibleInMenu(toolName) { - cy.get(`[data-testid="create-element-preferred-element-${toolName}"]`) - .should("not.exist") + cy.get(`[data-testid="create-element-preferred-element-${toolName}"]`).should( + "not.exist" + ); } clickThreeDotMenuOnExternalToolElementWithTool(toolName) { @@ -260,92 +266,90 @@ class Board { .click(); } - clickEditButtonInThreeDotMenu(){ + clickEditButtonInThreeDotMenu() { cy.get(Board.#editButtonInThreeDotMenu).click(); } - clickDeleteButtonInThreeDotMenu(){ + clickDeleteButtonInThreeDotMenu() { cy.get(Board.#deleteOptionThreeDot).click(); } - seeToolIsNotMarkedAsIncomplete(toolName){ + seeToolIsNotMarkedAsIncomplete(toolName) { cy.get(`[data-testid="board-external-tool-element-${toolName}"]`) .find(Board.#externalToolElementAlert) .children() - .should('have.length', 0); + .should("have.length", 0); } - - seeToolIsMarkedAsIncomplete(toolName){ - cy.get(`[data-testid="board-external-tool-element-${toolName}"]`) - .within(() => { - cy.get(Board.#externalToolElementAlert) - .children(".v-alert.v-theme--light.text-warning") - .should("have.class", "text-warning"); - }); + seeToolIsMarkedAsIncomplete(toolName) { + cy.get(`[data-testid="board-external-tool-element-${toolName}"]`).within(() => { + cy.get(Board.#externalToolElementAlert) + .children(".v-alert.v-theme--light.text-warning") + .should("have.class", "text-warning"); + }); } - seeToolIsMarkedAsIncompleteOperational(toolName){ - cy.get(`[data-testid="board-external-tool-element-${toolName}"]`) - .within(() => { - cy.get(Board.#externalToolElementAlert) - .children(".v-alert.v-theme--light.text-info") - .should("have.class", "text-info"); - }); + seeToolIsMarkedAsIncompleteOperational(toolName) { + cy.get(`[data-testid="board-external-tool-element-${toolName}"]`).within(() => { + cy.get(Board.#externalToolElementAlert) + .children(".v-alert.v-theme--light.text-info") + .should("have.class", "text-info"); + }); } - seeToolIsNotMarkedAsIncompleteOperational(toolName){ + seeToolIsNotMarkedAsIncompleteOperational(toolName) { cy.get(`[data-testid="board-external-tool-element-${toolName}"]`) .find(Board.#externalToolElementAlert) .children() - .should('have.length', 0); + .should("have.length", 0); } - clickExternalToolElementWithTool(toolName){ - cy.get(`[data-testid="board-external-tool-element-${toolName}"]`).click() + clickExternalToolElementWithTool(toolName) { + cy.get(`[data-testid="board-external-tool-element-${toolName}"]`).click(); } - clickOnThreeDotMenuInBoardHeader(){ + clickOnThreeDotMenuInBoardHeader() { cy.get(Board.#draftChipInCourseBoardName) .siblings() .find(Board.#threeDotInCourseBoardTitle) .click(); } - seeToolIsMarkedAsDeactivated(toolName){ - cy.get(`[data-testid="board-external-tool-element-${toolName}"]`) - .within(() => { - cy.get(Board.#externalToolElementAlert) - .children(".v-alert.v-theme--light.text-warning") - .should("have.class", "text-warning"); - }); + seeToolIsMarkedAsDeactivated(toolName) { + cy.get(`[data-testid="board-external-tool-element-${toolName}"]`).within(() => { + cy.get(Board.#externalToolElementAlert) + .children(".v-alert.v-theme--light.text-warning") + .should("have.class", "text-warning"); + }); } - seeToolIsNotMarkedAsDeactivated(toolName){ + seeToolIsNotMarkedAsDeactivated(toolName) { cy.get(`[data-testid="board-external-tool-element-${toolName}"]`) .find(Board.#externalToolElementAlert) .children() - .should('have.length', 0); + .should("have.length", 0); } launchTool(toolName, toolURL) { - const launchedTool = { toolName: toolName, isLaunched: false }; + const launchedTool = { toolName: toolName, isLaunched: false }; cy.window().then((win) => { - cy.stub(win, "open").as("openStub").callsFake((url) => { - expect(url).to.contain(toolURL); - launchedTool.isLaunched = true; - }); + cy.stub(win, "open") + .as("openStub") + .callsFake((url) => { + expect(url).to.contain(toolURL); + launchedTool.isLaunched = true; + }); }); cy.wrap(launchedTool).as("launchedTool"); - cy.get(`[data-testid="board-external-tool-element-${toolName}"]`).click() + cy.get(`[data-testid="board-external-tool-element-${toolName}"]`).click(); - cy.get("@openStub").invoke("restore") + cy.get("@openStub").invoke("restore"); } - toolWasLaunched(toolName){ + toolWasLaunched(toolName) { cy.get("@launchedTool").then((launchedTool) => { expect(launchedTool.toolName).to.equal(toolName); expect(launchedTool.isLaunched).to.be.true; @@ -354,20 +358,20 @@ class Board { cy.wrap({ toolName: "", isLaunched: false }).as("launchedTool"); } - enterTextToTextFieldInCard(textContent){ + enterTextToTextFieldInCard(textContent) { cy.get('[data-testid="ckeditor"]').then((el) => { const editor = el[0].ckeditorInstance; editor.setData(textContent); - }); - cy.get('[data-testid="ckeditor"]').then((el) => { + }); + cy.get('[data-testid="ckeditor"]').then((el) => { const editor = el[0].ckeditorInstance; const editorContent = editor.getData(); const plainText = editorContent.replace(/<\/?[^>]+(>|$)/g, ""); expect(plainText).to.equal(textContent); - }); + }); } - seeTextInTextFieldInCard(textContent){ + seeTextInTextFieldInCard(textContent) { cy.contains(textContent); } diff --git a/cypress/support/pages/room/pageRooms.js b/cypress/support/pages/room/pageRooms.js index 95e30778..628951a2 100644 --- a/cypress/support/pages/room/pageRooms.js +++ b/cypress/support/pages/room/pageRooms.js @@ -90,7 +90,7 @@ class Rooms { } seeRoomEditParticipantsPage() { - cy.get(Rooms.#roomTitle).contains("Teilnehmende verwalten"); + cy.get(Rooms.#roomTitle).contains("Raum-Teilnehmende"); } navigateToRoom(roomName) { @@ -157,7 +157,7 @@ class Rooms { cy.get(Rooms.#participantTable) .contains(participantName) .parent("tr") - .then((removeUser) => cy.wrap(removeUser).find("td").eq(4)) + .then((removeUser) => cy.wrap(removeUser).find("td").eq(5)) .click(); } diff --git a/cypress/support/pages/tldraw/pageTldraw.js b/cypress/support/pages/tldraw/pageTldraw.js new file mode 100644 index 00000000..e39bb520 --- /dev/null +++ b/cypress/support/pages/tldraw/pageTldraw.js @@ -0,0 +1,34 @@ +export class Tldraw { + static #canvas = "#canvas"; + static #pencilButton = "#TD-PrimaryTools-Pencil"; + static #textButton = "#TD-PrimaryTools-Text"; + static #drawShape = '[data-shape="draw"]'; + static #textShape = '[data-shape="text"]'; + + selectPencilTool() { + cy.get(Tldraw.#pencilButton).click(); + } + + selectTextTool() { + cy.get(Tldraw.#textButton).click(); + } + + drawLine(startX, startY, endX, endY) { + cy.get(Tldraw.#canvas) + .realMouseDown({ button: "left", x: startX, y: startY }) + .realMouseMove(endX, endY) + .realMouseUp({ button: "left", x: endX, y: endY }); + } + + typeText(text, x, y) { + cy.get(Tldraw.#canvas).realClick({ x: x, y: y }).realType(text); + } + + checkLine() { + cy.get(Tldraw.#drawShape).should("be.visible"); + } + + checkText(text) { + cy.get(Tldraw.#textShape).should("be.visible").should("contain", text); + } +} diff --git a/cypress/support/step_definition/common_helper/prePostConditionSteps.spec.js b/cypress/support/step_definition/common_helper/prePostConditionSteps.spec.js new file mode 100644 index 00000000..50f3b139 --- /dev/null +++ b/cypress/support/step_definition/common_helper/prePostConditionSteps.spec.js @@ -0,0 +1,43 @@ +import { Given, Then, When } from "@badeball/cypress-cucumber-preprocessor"; +import Board from "../../pages/course_board/pageBoard"; +import Courses from "../../pages/course/pageCourses"; + +const courses = new Courses(); +const board = new Board(); + +Given("a course with name {string} exists with {string} as teacher and {string} as student", (courseName, teacherName, studentName) => { + courses.navigateToCoursesOverview(); + courses.clickOnCreateCourseFAB(); + courses.fillCourseCreationForm(courseName); + courses.selectCourseColour(); + courses.selectTeacherInCourseCreatePage(teacherName); + courses.clickOnNextStepsBtnAfterEnteringCourseDetails(); + courses.selectStudentInCourseCreatePage(studentName); + courses.clickOnNextStepButtonOnCourseParticipationDetail(); +}); + +Given("a board exists in course {string}", (courseName) => { + courses.navigateToCoursesOverview(); + courses.navigateToCoursePage(courseName); + courses.clickOnCreateContentFAB(); + board.clickOnFABToCreateNewColumnBoard(); + board.clickOnMultiColumnBoardOptionInDialogBox(); + board.clickOnThreeDotMenuInCourseBoardTitle(); + board.clickPublishOptionInThreeDotMenuInCourseBoard(); +}); + +Given("the board has a column with a card", (columnName) => { + board.clickOnAddNewColumnButton(); + board.clickOutsideTheColumnToSaveTheColumn(); + board.clickPlusIconToAddCardInColumn(); +}); + +Given("course with name {string} is deleted", (courseName) => { + courses.navigateToCoursesOverview(); + courses.navigateToCoursePage(courseName); + courses.openCourseEditPage(); + courses.clickOnDeleteButtonOnCourseEditPage(); + courses.confirmCourseDeletionOnModal(); + courses.navigateToCoursesOverview(); + courses.courseIsNotVisiblOnOverviewPage(courseName); +}); \ No newline at end of file diff --git a/cypress/support/step_definition/course/commonCourseSteps.spec.js b/cypress/support/step_definition/course/commonCourseSteps.spec.js index bba6e995..a7587878 100644 --- a/cypress/support/step_definition/course/commonCourseSteps.spec.js +++ b/cypress/support/step_definition/course/commonCourseSteps.spec.js @@ -1,7 +1,6 @@ -const { When, Then } = require("@badeball/cypress-cucumber-preprocessor"); -import Management from '../../pages/admin/pageAdministration'; +const { When, Then, Given } = require("@badeball/cypress-cucumber-preprocessor"); +import Management from "../../pages/admin/pageAdministration"; import Courses from "../../pages/course/pageCourses"; -import CourseManagement from '../../pages/course_management/pageCourseManagement'; const courses = new Courses(); const management = new Management(); @@ -32,14 +31,14 @@ Then("I see course search box on the course overview page", () => { When("I go to course administration page", () => { management.navigateToCourseAdministration(); -}) +}); When("I go to courses overview", () => { courses.navigateToCoursesOverview(); }); When("I go to course {string}", (courseName) => { - courses.navigateToCourseBoard(courseName); + courses.navigateToCoursePage(courseName); }); Then("I see the course {string} on the course overview page", (courseName) => { @@ -63,8 +62,8 @@ Then("I see page Edit course", () => { }); Then("I see the course title is {string}", (courseName) => { - courses.isCorrectCourseEditPage(courseName) -}) + courses.isCorrectCourseEditPage(courseName); +}); When("I click on FAB to create a new course depending on sub menu", () => { courses.clickOnCreateCourseFAB(); @@ -244,12 +243,12 @@ Then("I see teacher {string} is selected by default", (defaultTeacherName) => { }); When("I select the teacher {string} in the list", (teacherName) => { - courses.selectTeacherInCourseCreatePage(teacherName) -}) + courses.selectTeacherInCourseCreatePage(teacherName); +}); Then("I see teacher selection box", () => { courses.seeTeacherSelectionBox(); -}) +}); Then("I see substitute teacher selection box", () => { courses.seeSubstituteTeacherSelectionBox(); @@ -263,9 +262,12 @@ Then("I see button to create a course time table container", () => { courses.seeCreateCourseTimeTableContainer(); }); -When("I click on button Next Steps after entering the course detail in section one", () => { - courses.clickOnNextStepsBtnAfterEnteringCourseDetails(); -}); +When( + "I click on button Next Steps after entering the course detail in section one", + () => { + courses.clickOnNextStepsBtnAfterEnteringCourseDetails(); + } +); Then("I see section two area on the course create page", () => { courses.seeSectionTwoAreaOnCourseCreatePage(); diff --git a/cypress/support/step_definition/course_board/commonBoardSteps.spec.js b/cypress/support/step_definition/course_board/commonBoardSteps.spec.js index 1bf3e332..c11655d6 100644 --- a/cypress/support/step_definition/course_board/commonBoardSteps.spec.js +++ b/cypress/support/step_definition/course_board/commonBoardSteps.spec.js @@ -1,8 +1,12 @@ -import { Then, When } from "@badeball/cypress-cucumber-preprocessor"; +import { Given, Then, When } from "@badeball/cypress-cucumber-preprocessor"; import Board from "../../pages/course_board/pageBoard"; const board = new Board(); +When("I click on the board", () => { + board.clickOnCourseBoardCardInCourseDetailPage(); +}); + When("I click on three dot menu in the card", () => { board.clickOnThreeDotOnCard(); }); @@ -66,9 +70,3 @@ Then("I see a whiteboard on the board", () => { Then("I select whiteboard from the menu", () => { board.selectWhiteboardFromMenu(); }); - - - - - - diff --git a/cypress/support/step_definition/course_board/openDrawingElementOnBoardSteps.spec.js b/cypress/support/step_definition/course_board/openDrawingElementOnBoardSteps.spec.js index a71dc550..58982ebd 100644 --- a/cypress/support/step_definition/course_board/openDrawingElementOnBoardSteps.spec.js +++ b/cypress/support/step_definition/course_board/openDrawingElementOnBoardSteps.spec.js @@ -6,3 +6,7 @@ const board = new Board(); When("I click on open Drawing Element", () => { board.clickOnOpenTldrawDrawingElement(); }); + +When("I click on the whiteboard element", () => { + board.clickOnWhiteboardElement(); +}); diff --git a/cypress/support/step_definition/tldraw/tldrawSteps.spec.js b/cypress/support/step_definition/tldraw/tldrawSteps.spec.js new file mode 100644 index 00000000..3ecbd74a --- /dev/null +++ b/cypress/support/step_definition/tldraw/tldrawSteps.spec.js @@ -0,0 +1,28 @@ +import { Then, When } from "@badeball/cypress-cucumber-preprocessor"; +import { Tldraw } from "../../pages/tldraw/pageTldraw"; + +const tldraw = new Tldraw(); + +When("I click on the pencil tool", () => { + tldraw.selectPencilTool(); +}); + +When("I click on the text tool", () => { + tldraw.selectTextTool(); +}); + +When("I draw a line on the canvas with startpoint {string}, {string} and endpoint {string}, {string}", (startX, startY, endX, endY) => { + tldraw.drawLine(startX,startY,endX,endY); +}); + +When("I type text {string} on the canvas on position {string}, {string}", (text, posX, posY) => { + tldraw.typeText(text, posX, posY); +}); + +Then("I should see the line drawn", () => { + tldraw.checkLine(); +}); + +Then("I should see the text {string} drawn", (text) => { + tldraw.checkText(text); +}); diff --git a/package-lock.json b/package-lock.json index 1946ea95..3eab9c97 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,7 @@ "axios": "^1.6.8", "cypress": "^13.2.0", "cypress-file-upload": "^5.0.8", - "cypress-real-events": "^1.11.0", + "cypress-real-events": "^1.13.0", "multiple-cucumber-html-reporter": "^1.21.4", "prettier": "^3.2.5", "webpack": "^5.77.0" @@ -4103,10 +4103,11 @@ } }, "node_modules/cypress-real-events": { - "version": "1.11.0", - "resolved": "https://registry.npmjs.org/cypress-real-events/-/cypress-real-events-1.11.0.tgz", - "integrity": "sha512-4LXVRsyq+xBh5TmlEyO1ojtBXtN7xw720Pwb9rEE9rkJuXmeH3VyoR1GGayMGr+Itqf11eEjfDewtDmcx6PWPQ==", + "version": "1.13.0", + "resolved": "https://registry.npmjs.org/cypress-real-events/-/cypress-real-events-1.13.0.tgz", + "integrity": "sha512-LoejtK+dyZ1jaT8wGT5oASTPfsNV8/ClRp99ruN60oPj8cBJYod80iJDyNwfPAu4GCxTXOhhAv9FO65Hpwt6Hg==", "dev": true, + "license": "MIT", "peerDependencies": { "cypress": "^4.x || ^5.x || ^6.x || ^7.x || ^8.x || ^9.x || ^10.x || ^11.x || ^12.x || ^13.x" } diff --git a/package.json b/package.json index 13253640..57777374 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "cy:headless:only:local": "cypress run --browser edge -e tags=@only,environmentName=local", "cy:headless:unstable:local": "cypress run --browser edge -e tags=@unstable_test,environmentName=local", "cy:gui:stable:regression_test:school_api_test:ci": "cypress open --browser edge -e tags=\"@stable_test and @regression_test and @school_api_test\",environmentName=ci", - "cy:headless:stable:schedule_run:school_api_test:ci":"xvfb-run cypress run --browser edge -e tags=\"@stable_test and @school_api_test and @schedule_run\",environmentName=ci,parallelGroup=scheduled", + "cy:headless:stable:schedule_run:school_api_test:ci": "xvfb-run cypress run --browser edge -e tags=\"@stable_test and @school_api_test and @schedule_run\",environmentName=ci,parallelGroup=scheduled", "cy:headless:stable:regression_test:school_api_test:ci": "xvfb-run cypress run --browser edge -e tags=\"@stable_test and @regression_test and @school_api_test\",environmentName=ci,parallelGroup=automatic", "cy:headless:stable:pr:school_api_test:ci": "xvfb-run cypress run --browser edge -e tags=\"@pr and @stable_test and @school_api_test\",environmentName=ci", "cy:headless:stable:groupA:school_api_test:ci": "xvfb-run cypress run --browser edge -e tags=\"@group-A and @stable_test and @school_api_test\",environmentName=ci,parallelGroup=group-A", @@ -45,7 +45,7 @@ "axios": "^1.6.8", "cypress": "^13.2.0", "cypress-file-upload": "^5.0.8", - "cypress-real-events": "^1.11.0", + "cypress-real-events": "^1.13.0", "multiple-cucumber-html-reporter": "^1.21.4", "prettier": "^3.2.5", "webpack": "^5.77.0" From 046782e48661e6da61a51a2b451d27fa06f4d88c Mon Sep 17 00:00:00 2001 From: Christian Spohr <105202075+csp175@users.noreply.github.com> Date: Thu, 12 Dec 2024 07:42:37 +0100 Subject: [PATCH 2/2] Bc 3505 news with time options (#272) * created news tests with time options * added team news test with time options * implemented news in advance --- .../showGroupsAndClassesInTable.feature | 4 +- .../addSubstituteTeacherToCourse.feature | 4 +- cypress/e2e/dashboard/dashboard.feature | 42 +++---- cypress/e2e/news/createReadDeleteNews.feature | 32 +++--- ...reateReadDeleteSchoolNewsInAdvance.feature | 49 ++++++++ ...ateReadDeleteSchoolNewsTimeOptions.feature | 54 +++++++++ ...reateReadDeleteTeamNewsTimeOptions.feature | 63 +++++++++++ cypress/e2e/topics/accessH5PEditor.feature | 4 +- .../e2e/topics/createEditDeleteTopic.feature | 4 +- .../support/pages/dashboard/pageDashboard.js | 6 +- cypress/support/pages/news/pageNews.js | 106 +++++++++++++++++- .../news/commonNewsSteps.spec.js | 37 ++++++ .../news/createReadDeleteNewsSteps.spec.js | 2 +- 13 files changed, 355 insertions(+), 52 deletions(-) create mode 100644 cypress/e2e/news/createReadDeleteSchoolNewsInAdvance.feature create mode 100644 cypress/e2e/news/createReadDeleteSchoolNewsTimeOptions.feature create mode 100644 cypress/e2e/news/createReadDeleteTeamNewsTimeOptions.feature diff --git a/cypress/e2e/class_management/showGroupsAndClassesInTable.feature b/cypress/e2e/class_management/showGroupsAndClassesInTable.feature index c6023e5f..633e2e09 100644 --- a/cypress/e2e/class_management/showGroupsAndClassesInTable.feature +++ b/cypress/e2e/class_management/showGroupsAndClassesInTable.feature @@ -63,8 +63,8 @@ Feature: Group - To show groups and classes in one table with respective functio When I click the confirmation button on the cancel modal Then I see the new class administration page When I click the create successor button - And I confirm creating the successor - And I confirm managing the class + When I confirm creating the successor + When I confirm managing the class Then I see the new class administration page Then I can see the disabled create successor button of the original class diff --git a/cypress/e2e/course/addSubstituteTeacherToCourse.feature b/cypress/e2e/course/addSubstituteTeacherToCourse.feature index 055a041f..6fd57658 100644 --- a/cypress/e2e/course/addSubstituteTeacherToCourse.feature +++ b/cypress/e2e/course/addSubstituteTeacherToCourse.feature @@ -32,8 +32,8 @@ Feature: Course - Add substitute teacher to course When I go to course '' When I open page Edit course Then I see page Edit course - And I clear substitute teacher field - And I add substitute teacher '' + When I clear substitute teacher field + When I add substitute teacher '' When I click on button Save changes in page Edit course Given I am logged in as a '' at '' When I go to courses overview diff --git a/cypress/e2e/dashboard/dashboard.feature b/cypress/e2e/dashboard/dashboard.feature index b7e05ef9..c543b5df 100644 --- a/cypress/e2e/dashboard/dashboard.feature +++ b/cypress/e2e/dashboard/dashboard.feature @@ -59,13 +59,13 @@ Feature: Dashboard - To check contents on the dashboard # pre-condition: teacher creates school news When I go to news overview - And I click on add news button + When I click on add news button Then I see news creation page - And I enter news title 'CypressAut Dashboard - school news' - And I enter news description 'test school news description' - And I see date input field - And I see time input field - And I click on save button + When I enter news title 'CypressAut Dashboard - school news' + When I enter news description 'test school news description' + Then I see date input field + Then I see time input field + When I click on save button Then I see news is created successfully with title 'CypressAut Dashboard - school news' and with description 'test school news description' # pre-condition: teacher creates a team @@ -79,24 +79,24 @@ Feature: Dashboard - To check contents on the dashboard When I go to teams overview When I go to a team 'CypressAut - News Team' When I click on news tab on the team detail page - And I click on create news button + When I click on create news button Then I see news creation page - And I enter news title 'CypressAut Dashboard - team news' - And I enter news description 'test team news description' - And I see date input field - And I see time input field - And I click on save button + When I enter news title 'CypressAut Dashboard - team news' + When I enter news description 'test team news description' + Then I see date input field + Then I see time input field + When I click on save button Then I see news is created successfully with title 'CypressAut Dashboard - team news' and with description 'test team news description' # pre-condition: teacher adds student as team member When I go to teams overview When I go to a team 'CypressAut - News Team' When I click on three dot menu on the team title - And I click on manage team members option + When I click on manage team members option Then I see team participants overview page - And I click on add internal attendees button - And new dialog opens to select student '' from the drop down list - And I click on add user button + When I click on add internal attendees button + Then new dialog opens to select student '' from the drop down list + When I click on add user button Then I see the student named '' on the team members table # student arrives on dashboard @@ -118,16 +118,16 @@ Feature: Dashboard - To check contents on the dashboard # teacher deletes the school news When I arrive on the dashboard - And I click on the news teaser 'CypressAut Dashboard - school news' + When I click on the news teaser 'CypressAut Dashboard - school news' When I click on delete button - And I confirm the deletion on confirmation dialog box + When I confirm the deletion on confirmation dialog box Then I do not see the news 'CypressAut Dashboard - school news' # teacher deletes the team news When I arrive on the dashboard - And I click on the news teaser 'CypressAut Dashboard - team news' + When I click on the news teaser 'CypressAut Dashboard - team news' When I click on delete button - And I confirm the deletion on confirmation dialog box + When I confirm the deletion on confirmation dialog box Then I do not see the news 'CypressAut Dashboard - team news' # student does not see news anymore on dashboard @@ -141,7 +141,7 @@ Feature: Dashboard - To check contents on the dashboard When I go to teams overview When I go to a team 'CypressAut - News Team' When I click on three dot menu on the team title - And I click on manage team members option + When I click on manage team members option Then I see team participants overview page When I select the student '' and click on delete icon Then I see '' is not visible on the table diff --git a/cypress/e2e/news/createReadDeleteNews.feature b/cypress/e2e/news/createReadDeleteNews.feature index a05d2003..ea40ab6f 100644 --- a/cypress/e2e/news/createReadDeleteNews.feature +++ b/cypress/e2e/news/createReadDeleteNews.feature @@ -13,13 +13,13 @@ Feature: News - To read a news on the respective dashboards # teacher creates school news Given I am logged in as a '' at '' When I go to news overview - And I click on add news button + When I click on add news button Then I see news creation page - And I enter news title '' - And I enter news description '' - And I see date input field - And I see time input field - And I click on save button + When I enter news title '' + When I enter news description '' + Then I see date input field + Then I see time input field + When I click on save button Then I see news is created successfully with title '' and with description '' # teacher creates a team @@ -33,13 +33,13 @@ Feature: News - To read a news on the respective dashboards When I go to teams overview When I go to a team '' When I click on news tab on the team detail page - And I click on create news button + When I click on create news button Then I see news creation page - And I enter news title '' - And I enter news description '' - And I see date input field - And I see time input field - And I click on save button + When I enter news title '' + When I enter news description '' + Then I see date input field + Then I see time input field + When I click on save button Then I see news is created successfully with title '' and with description '' # teacher reads a school news on news overview page @@ -60,16 +60,16 @@ Feature: News - To read a news on the respective dashboards # teacher deletes the school news Given I am logged in as a '' at '' When I arrive on the dashboard - And I click on the news teaser '' + When I click on the news teaser '' When I click on delete button - And I confirm the deletion on confirmation dialog box + When I confirm the deletion on confirmation dialog box Then I do not see the news '' # teacher deletes the team news When I arrive on the dashboard - And I click on the news teaser '' + When I click on the news teaser '' When I click on delete button - And I confirm the deletion on confirmation dialog box + When I confirm the deletion on confirmation dialog box Then I do not see the news '' # teacher deletes the team diff --git a/cypress/e2e/news/createReadDeleteSchoolNewsInAdvance.feature b/cypress/e2e/news/createReadDeleteSchoolNewsInAdvance.feature new file mode 100644 index 00000000..29cb51a1 --- /dev/null +++ b/cypress/e2e/news/createReadDeleteSchoolNewsInAdvance.feature @@ -0,0 +1,49 @@ +@stable_test +@regression_test +Feature: News - To read a news on the respective dashboards + + As a teacher I want to read the news shown on the dashboard so that I'm informed about the latest news + + Scenario: User creates news with time options, reads them and deletes them + # as a pre-condition create users for author and reader + Given I am logged in as a '' at '' + Given I am logged in as a '' at '' + + # first user creates school news with different time options + When I go to news overview + When I click on add news button + Then I see news creation page + When I enter news title '' + When I enter news description '' + When I set news-visibility-start-date to '' days at '' + Then I see time input field + When I click on save button + When I go to news overview + Then I do not see the unpublished news '' + When I click on tab for unpublished news + Then I see the unpublished news '' + + # second user reads a school news on news overview page, then second user opens news and reads news detail page + Given I am logged in as a '' at '' + When I go to news overview + Then I do not see the news '' + When I wait '' seconds and reload + Then I can read the news '' with description '' + When I click on the news teaser '' + Then I can read the news '' with description '' on news detail page + + # first user deletes the school news + Given I am logged in as a '' at '' + When I arrive on the dashboard + When I go to news overview + Then I can read the news '' with description '' + When I click on the news teaser '' + When I click on delete button + When I confirm the deletion on confirmation dialog box + Then I do not see the news '' + + @school_api_test + @staging_test + Examples: + | news_author | news_reader | namespace | news_title | news_description | news_day_from_today | news_time | news_waiting_time | + | teacher1_brb | student1_brb | brb | CypressAut - school news in advance | Remember Examination date | 0 | +2minutes | 120 | \ No newline at end of file diff --git a/cypress/e2e/news/createReadDeleteSchoolNewsTimeOptions.feature b/cypress/e2e/news/createReadDeleteSchoolNewsTimeOptions.feature new file mode 100644 index 00000000..dc4e4549 --- /dev/null +++ b/cypress/e2e/news/createReadDeleteSchoolNewsTimeOptions.feature @@ -0,0 +1,54 @@ +@stable_test +@regression_test +Feature: News - To read a news on the respective dashboards + + As a teacher I want to read the news shown on the dashboard so that I'm informed about the latest news + + Scenario: User creates news with time options, reads them and deletes them + # as a pre-condition create users for author and reader + Given I am logged in as a '' at '' + Given I am logged in as a '' at '' + + # first user creates school news with different time options + When I go to news overview + When I click on add news button + Then I see news creation page + When I enter news title '' + When I enter news description '' + When I set news-visibility-start-date to '' days at '' + Then I see time input field + When I click on save button + Then I see news is created successfully with title '' and with description '' + + # first user reads a school news on news overview page, then teacher opens news and reads news detail page + When I go to news overview + Then I can read the news '' with description '' + Then I can see the publishing time info '' on overview page + When I click on the news teaser '' + Then I can read the news '' with description '' on news detail page + Then I can see the publishing time info '' on news detail page + + # second user reads a school news on news overview page, then second user opens news and reads news detail page + Given I am logged in as a '' at '' + When I go to news overview + Then I can read the news '' with description '' + Then I can see the publishing time info '' on overview page + When I click on the news teaser '' + Then I can read the news '' with description '' on news detail page + Then I can see the publishing time info '' on news detail page + + # first user deletes the school news + Given I am logged in as a '' at '' + When I arrive on the dashboard + When I click on the news teaser '' + When I click on delete button + When I confirm the deletion on confirmation dialog box + Then I do not see the news '' + + @school_api_test + @staging_test + Examples: + | news_author | news_reader | namespace | news_title | news_description | news_day_from_today | news_time | news_time_info_overviewpage | news_time_info_detailpage | + | teacher1_brb | student1_brb | brb | CypressAut - school news at current time | Remember Examination date | 0 | currentTime | vor ein | vor ein | + | admin1_brb | student1_brb | brb | CypressAut - school news without time | New member of the teaching staff | notselected | none | vor ein | vor ein | + | admin1_brb | teacher1_brb | brb | CypressAut - school news 7 days ago | New member of the teaching staff | -7 | currentTime | vor 7 Tage | -7 | \ No newline at end of file diff --git a/cypress/e2e/news/createReadDeleteTeamNewsTimeOptions.feature b/cypress/e2e/news/createReadDeleteTeamNewsTimeOptions.feature new file mode 100644 index 00000000..b9a80d11 --- /dev/null +++ b/cypress/e2e/news/createReadDeleteTeamNewsTimeOptions.feature @@ -0,0 +1,63 @@ +@stable_test +@regression_test +Feature: News - To read a news on the respective dashboards + + As a teacher I want to read the news shown on the dashboard so that I'm informed about the latest news + + Scenario: User creates news with time options, reads them and deletes them + # as a pre-condition create users for author and reader + Given I am logged in as a '' at '' + Given I am logged in as a '' at '' + + # first user creates a team + When I go to teams overview + When I click on button Add Team on the teams overview page + Then I see new team creation page + When I enter in the title '' + When I click on button Create Team on the team creation page + + # first user creates a team news + When I go to teams overview + When I go to a team '' + When I click on news tab on the team detail page + When I click on create news button + Then I see news creation page + When I enter news title '' + When I enter news description '' + When I set news-visibility-start-date to '' days at '' + Then I see time input field + When I click on save button + Then I see news is created successfully with title '' and with description '' + + # first user reads a team news on teams news overview page + When I go to teams overview + When I go to a team '' + When I click on news tab on the team detail page + Then I can read the news '' with description '' + Then I can see the publishing time info '' on overview page + When I click on the news teaser '' + Then I can read the news '' with description '' on news detail page + Then I can see the publishing time info '' on news detail page + + # first user deletes the team news + When I arrive on the dashboard + When I click on the news teaser '' + When I click on delete button + When I confirm the deletion on confirmation dialog box + Then I do not see the news '' + + # first user deletes the team + When I go to teams overview + When I go to a team '' + When I click on team settings + When I click on delete option + Then I see dialog box and click on delete button to confirm the deletion + Then I do not see the team '' + + @school_api_test + @staging_test + Examples: + | news_author | news_reader | namespace | news_day_from_today | news_time | news_time_info_overviewpage | news_time_info_detailpage | team_name | team_news_title | team_news_description | + | teacher1_brb | student1_brb | nbc | 0 | currentTime | vor ein | vor ein | CypressAut - News Team | CypressAut - this is a team news | test team news description | + #| admin1_brb | student1_brb | nbc | notselected | none | vor ein | vor ein | CypressAut - News Team | CypressAut - this is a team news | test team news description | + #| admin1_brb | teacher1_brb | nbc | -7 | currentTime | vor 7 Tage | -7 | CypressAut - News Team | CypressAut - this is a team news | test team news description | \ No newline at end of file diff --git a/cypress/e2e/topics/accessH5PEditor.feature b/cypress/e2e/topics/accessH5PEditor.feature index e6f1ba01..e3955bb0 100644 --- a/cypress/e2e/topics/accessH5PEditor.feature +++ b/cypress/e2e/topics/accessH5PEditor.feature @@ -36,8 +36,8 @@ Feature: Topics - To access the H5P editor as a teacher. Given I am logged in as a '' at '' When I go to courses overview When I go to course '' - And I click on FAB to create new content - And I click on New Topic FAB + When I click on FAB to create new content + When I click on New Topic FAB Then I can see edit topic page '-' When I enter topic title '' When I click on button Add Text to topic diff --git a/cypress/e2e/topics/createEditDeleteTopic.feature b/cypress/e2e/topics/createEditDeleteTopic.feature index 560b1367..0cca242d 100644 --- a/cypress/e2e/topics/createEditDeleteTopic.feature +++ b/cypress/e2e/topics/createEditDeleteTopic.feature @@ -39,8 +39,8 @@ Feature: Topics - To create, edit and delete topics by the teacher. Given I am logged in as a '' at '' When I go to courses overview When I go to course '' - And I click on FAB to create new content - And I click on New Topic FAB + When I click on FAB to create new content + When I click on New Topic FAB Then I can see edit topic page '-' When I enter topic title 'CypressAut Topic Creating and Deleting Test' When I click on button Add Text to topic diff --git a/cypress/support/pages/dashboard/pageDashboard.js b/cypress/support/pages/dashboard/pageDashboard.js index 40fcce07..1990149b 100644 --- a/cypress/support/pages/dashboard/pageDashboard.js +++ b/cypress/support/pages/dashboard/pageDashboard.js @@ -14,7 +14,7 @@ class Dashboard { static #dashboardTasksTitle = '[data-testid="dashboard-tasks-title"]'; static #dashboardTaskCourseName = '[data-testid="task-course-name"]'; static #dashboardTaskName = '[data-testid="task-name"]'; - static #pageTitle = '[data-testid="title_of_an_element"]'; + static #elementTitle = '[data-testid="title_of_an_element"]'; static #newsText = '[data-testid="body_of_element"]'; static #newsSection = '[data-testid="news-section"]'; static #dashboardLink = 'a[data-testid="Übersicht"]'; @@ -134,13 +134,13 @@ class Dashboard { seeSchoolNews(newsTitle, newsDesc) { cy.get(Dashboard.#newsSection).should("be.visible"); - cy.get(Dashboard.#pageTitle).contains(newsTitle); + cy.get(Dashboard.#elementTitle).contains(newsTitle); cy.get(Dashboard.#newsText).contains(newsDesc); } seeTeamsNews(newsTitle, newsDesc) { cy.get(Dashboard.#newsSection).should("be.visible"); - cy.get(Dashboard.#pageTitle).contains(newsTitle); + cy.get(Dashboard.#elementTitle).contains(newsTitle); cy.get(Dashboard.#newsText).contains(newsDesc); } diff --git a/cypress/support/pages/news/pageNews.js b/cypress/support/pages/news/pageNews.js index a6653668..af021d9f 100644 --- a/cypress/support/pages/news/pageNews.js +++ b/cypress/support/pages/news/pageNews.js @@ -1,7 +1,11 @@ "use strict"; class News { - static #pageTitle = '[data-testid="title_of_an_element"]'; + static #elementTitle = '[data-testid="title_of_an_element"]'; + static #elementHeader = '[data-testid="header-of-element"]'; + static #pageTitle = '[id="page-title"]'; + static #enDateFormat = "en-CA"; + static #deDateFormat = "de-DE"; static #newsText = '[data-testid="body_of_element"]'; static #newsOverviewNavigationButton = '[data-testid="Neuigkeiten"]'; static #createNewNews = '[data-testid="create-news-btn"]'; @@ -16,6 +20,26 @@ class News { static #deleteNews = '[data-testid="btn-delete-news"]'; static #deleteNewsConfirmation = '[data-testid="delete-article-btn"]'; static #titlebarNewsOverviewPage = '[id="titlebar"]'; + static #newsContent = '[id="main-content"]'; + static #newsOverviewTabUnpublished = '[data-tab="b"]' + + doNotSeeNewsWhenNewsNotYetPublished(newsTitle) { + cy.get("span", { timeout: 20000 }).then(($span) => { + if ($span.find(News.#newsName)) { + cy.contains(newsTitle).should("not.be.visible"); + } else { + cy.contains( + "Keine aktuellen Einträge vorhanden." || "Bisher gibt es keine News." + ).should("exist"); + } + }); + } + + seeNewsWhenNewsNotYetPublished(newsTitle) { + cy.get("span", { timeout: 20000 }).then(($span) => { + cy.contains(newsTitle).should("be.visible"); + }); + } doNotSeeNews(newsTitle) { cy.get("span", { timeout: 20000 }).then(($span) => { @@ -29,6 +53,10 @@ class News { }); } + clickOnTabUnpublishedNews() { + cy.get(News.#newsOverviewTabUnpublished).click(); + } + confirmDeletionOnDialogBox() { cy.get(News.#deleteNewsConfirmation).click(); } @@ -86,9 +114,81 @@ class News { cy.get(News.#titlebarNewsOverviewPage).should("exist"); } - teacherReadsNewsOnOverviewPage(titleOfNews, descriptionOfNews) { - cy.get(News.#pageTitle).contains(titleOfNews).should("exist"); + seeNewsOnOverviewPage(titleOfNews, descriptionOfNews) { + cy.get(News.#elementTitle).contains(titleOfNews).should("exist"); cy.get(News.#newsText).contains(descriptionOfNews).should("exist"); } + + seeNewsOnNewsDetailPage(titleOfNews, descriptionOfNews) { + cy.get(News.#pageTitle).contains(titleOfNews).should("exist"); + cy.get(News.#newsContent).contains(descriptionOfNews).should("exist"); + } + + setNewsStartDate(newsStartDateDifference, newsStartTime) { + if (newsStartDateDifference != 'notselected'){ + const today = new Date(); + let startDate = new Date(today); + let startTime; + let startTimeText; + let daysFromNow = parseInt(newsStartDateDifference); + startDate.setDate(startDate.getDate() + daysFromNow); + + let startDateText = startDate.toLocaleString(News.#enDateFormat, { + year: "numeric", + day: "2-digit", + month: "2-digit" + }); + cy.get(News.#newsDateInput).eq(1).type( + `${startDateText}` + ); + + if (newsStartTime === "currentTime") { + startTime = new Date(today); + startTimeText = startTime.toLocaleString(News.#deDateFormat, { + hour: "2-digit", + minute: "2-digit" + }); + } else if (newsStartTime === "+2minutes") { + startTime = new Date(today); + startTime.setMinutes(startTime.getMinutes() + 2); + startTimeText = startTime.toLocaleString(News.#deDateFormat, { + hour: "2-digit", + minute: "2-digit" + }); + } else { + startTimeText = newsStartTime; + } + cy.get(News.#newsTimeInput).eq(1).type( + `${startTimeText}` + ); + + } + } + + seeNewsTimeInfoOnNewsDetailPage(newsTimeInfo) { + if (newsTimeInfo === 'vor ein'){ + cy.get(News.#newsContent).contains(newsTimeInfo).should("exist"); + }else { + let daysFromNow = parseInt(newsTimeInfo); + let startDate = new Date(); + startDate.setDate(startDate.getDate() + daysFromNow); + let newsDateInfo = startDate.toLocaleString(News.#deDateFormat, { + year: "numeric", + day: "2-digit", + month: "2-digit" + }); + cy.get(News.#newsContent).contains(newsDateInfo).should("exist"); + } + } + + seeNewsTimeInfoOnOverviewPage(newsTimeInfo) { + cy.get(News.#elementHeader).contains(newsTimeInfo).should("exist"); + } + + waitBeforeReload(timeInSeconds) { + timeInSeconds = parseInt(timeInSeconds); + cy.wait(timeInSeconds*1000).reload(); + } + } export default News; diff --git a/cypress/support/step_definition/news/commonNewsSteps.spec.js b/cypress/support/step_definition/news/commonNewsSteps.spec.js index b1ccd107..1ee0ba3c 100644 --- a/cypress/support/step_definition/news/commonNewsSteps.spec.js +++ b/cypress/support/step_definition/news/commonNewsSteps.spec.js @@ -57,3 +57,40 @@ When("I confirm the deletion on confirmation dialog box", () => { Then("I do not see the news {string}", (newsName) => { news.doNotSeeNews(newsName); }); + +Then("I do not see the unpublished news {string}", (newsName) => { + news.doNotSeeNewsWhenNewsNotYetPublished(newsName); +}); + +When("I set news-visibility-start-date to {string} days at {string}", (newsDayDifference, newsTime) => { + news.setNewsStartDate(newsDayDifference, newsTime); +}); + +When("I can see the publishing time info {string} on overview page", (newsTimeInfo) => { + news.seeNewsTimeInfoOnOverviewPage(newsTimeInfo); +}); + +When("I can see the publishing time info {string} on news detail page", (newsTimeInfo) => { + news.seeNewsTimeInfoOnNewsDetailPage(newsTimeInfo); +}); + +Then( + "I can read the news {string} with description {string} on news detail page", + (titleOfNews, descriptionOfNews) => { + news.seeNewsOnNewsDetailPage(titleOfNews, descriptionOfNews); + } +); + +When("I wait {string} seconds and reload", (timeInSeconds) => { + news.waitBeforeReload(timeInSeconds) +}); + +When("I click on tab for unpublished news", () => { + news.clickOnTabUnpublishedNews() +}); + +Then("I see the unpublished news {string}", (newsTitle) => { + news.seeNewsWhenNewsNotYetPublished(newsTitle) +}); + + diff --git a/cypress/support/step_definition/news/createReadDeleteNewsSteps.spec.js b/cypress/support/step_definition/news/createReadDeleteNewsSteps.spec.js index 5c1115a2..9e39d985 100644 --- a/cypress/support/step_definition/news/createReadDeleteNewsSteps.spec.js +++ b/cypress/support/step_definition/news/createReadDeleteNewsSteps.spec.js @@ -14,6 +14,6 @@ const news = new News(); Then( "I can read the news {string} with description {string}", (titleOfNews, descriptionOfNews) => { - news.teacherReadsNewsOnOverviewPage(titleOfNews, descriptionOfNews); + news.seeNewsOnOverviewPage(titleOfNews, descriptionOfNews); } );