From b165fe815b57485a663510409562960b024d326e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Pelay?= <45865185+jpelay@users.noreply.github.com> Date: Thu, 30 May 2024 11:52:29 -0400 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=AA=B2=20Fixes=20accessing=20deleted?= =?UTF-8?q?=20tags=20on=20adventure=20(#5580)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Checks if the tag is different than `None`. Fixes #5579 **How to test** The best way would be to open an adventure, add a tag, and then delete it in the DB. Reload the server and you should be able to keep editing the adventure. --- website/database.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/website/database.py b/website/database.py index ddca0154f52..b6eb0cb0b0e 100644 --- a/website/database.py +++ b/website/database.py @@ -594,7 +594,11 @@ def read_tag(self, tag_name): return TAGS.get({"name": tag_name}) def read_tags(self, tags): - return [self.read_tag(name) for name in tags] + db_tags = [] + for name in tags: + if (db_tag := self.read_tag(name)) is not None: + db_tags.append(db_tag) + return db_tags def read_public_tags(self): """Public tags are tagged within one or more public adventure or those that aren't in use.""" From 4163290a90cf985e57f5d4657f789831e6a3d3db Mon Sep 17 00:00:00 2001 From: Annelein <48122190+Annelein@users.noreply.github.com> Date: Mon, 3 Jun 2024 12:40:25 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=A7=B9=20In=20cypress,=20use=20getByS?= =?UTF-8?q?el("")=20instead=20of=20get('[data-cy=3D""]')=20(#5575)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a lot cleaner to read: `cy.getBySel('view_class_link')` instead of: `cy.get('[data-cy="view_class_link"]')` --- .../return_to_admin_page_button.cy.js | 2 +- .../return_to_admin_page_button.cy.js | 2 +- .../user_overview/return_to_admin_page.cy.js | 2 +- .../user_overview/view_all_users.cy.js | 2 +- .../explore_programs.cy.js | 4 +- .../cypress/e2e/feedback/feedback_modal.cy.js | 22 ++--- .../class_page/add_student_copy_link.cy.js | 10 +-- .../add_student_invite_by_username.cy.js | 34 +++---- .../class_page/class-survey.cy.js | 28 +++--- .../create_accounts.cy.js | 26 +++--- .../create_accounts_second_teachers.cy.js | 24 ++--- .../class_page/customize_class_button.cy.js | 8 +- .../go_back_to_teacher_page_button.cy.js | 8 +- .../class_page/second_teachers_invites.cy.js | 27 +++--- .../customize-adventure_page/autosave.cy.js | 2 +- .../customize_adenture_page.cy.js | 4 +- .../remove_button.cy.js | 10 +-- .../customize_class.cy.js | 88 +++++++++---------- .../customize_class_second_teacher.cy.js | 70 +++++++-------- .../customize_class_page/quiz_parsons.cy.js | 36 ++++---- .../general/click_duplicate_class.cy.js | 32 +++---- .../general/click_new_class.cy.js | 10 +-- .../general/duplicate_class.cy.js | 38 ++++---- .../general/preview-adventure.cy.js | 4 +- .../general/preview-class.cy.js | 16 ++-- .../general/remove_button.cy.js | 4 +- .../hedy_page/developers_mode_switch.cy.js | 2 +- .../e2e/hedy_page/dropdown_level.cy.js | 8 +- tests/cypress/e2e/hedy_page/editor_box.cy.js | 4 +- .../e2e/hedy_page/keyword_language.cy.js | 12 +-- tests/cypress/e2e/hedy_page/quiz.cy.js | 6 +- .../e2e/hedy_page/run_code_button.cy.js | 2 +- .../public_adventures/public_adventures.cy.js | 14 +-- .../e2e/public_programs/programs_page.cy.js | 22 ++--- .../signup_page/create_account_button.cy.js | 2 +- .../cypress/e2e/tools/adventures/adventure.js | 2 +- tests/cypress/e2e/tools/classes/class.js | 30 +++---- tests/cypress/e2e/tools/programs/program.js | 6 +- tests/cypress/support/commands.js | 17 +++- 39 files changed, 325 insertions(+), 315 deletions(-) diff --git a/tests/cypress/e2e/admin_page/achievements_page/return_to_admin_page_button.cy.js b/tests/cypress/e2e/admin_page/achievements_page/return_to_admin_page_button.cy.js index 661cf4a37de..3fd16ac8288 100644 --- a/tests/cypress/e2e/admin_page/achievements_page/return_to_admin_page_button.cy.js +++ b/tests/cypress/e2e/admin_page/achievements_page/return_to_admin_page_button.cy.js @@ -5,7 +5,7 @@ it('should return to admin page button', () => { loginForAdmin(); goToAdminAchievementsPage(); - cy.get('[data-cy="return_to_admin_page_button"]') + cy.getDataCy('return_to_admin_page_button') .should('be.visible') .should('be.not.disabled') .click(); diff --git a/tests/cypress/e2e/admin_page/adventures_page/return_to_admin_page_button.cy.js b/tests/cypress/e2e/admin_page/adventures_page/return_to_admin_page_button.cy.js index ab7b93949fb..52de2188414 100644 --- a/tests/cypress/e2e/admin_page/adventures_page/return_to_admin_page_button.cy.js +++ b/tests/cypress/e2e/admin_page/adventures_page/return_to_admin_page_button.cy.js @@ -5,7 +5,7 @@ it('should return to admin page button', () => { loginForAdmin(); goToAdminAdventuresPage(); - cy.get('[data-cy="return_to_admin_page_button"]') + cy.getDataCy('return_to_admin_page_button') .should('be.visible') .should('be.not.disabled') .click(); diff --git a/tests/cypress/e2e/admin_page/user_overview/return_to_admin_page.cy.js b/tests/cypress/e2e/admin_page/user_overview/return_to_admin_page.cy.js index e2fce82dfb5..ca4b48582fd 100644 --- a/tests/cypress/e2e/admin_page/user_overview/return_to_admin_page.cy.js +++ b/tests/cypress/e2e/admin_page/user_overview/return_to_admin_page.cy.js @@ -3,7 +3,7 @@ import { goToAdminUsersPage } from '../../tools/navigation/nav.js'; it('should return to admin page', () => { goToAdminUsersPage(); - cy.get('[data-cy="return_button"]').should('be.not.disabled').should('be.visible').click(); + cy.getDataCy('return_button').should('be.not.disabled').should('be.visible').click(); cy.location().should((loc) => { expect(loc.pathname).equal(Cypress.env('admin_page')); diff --git a/tests/cypress/e2e/admin_page/user_overview/view_all_users.cy.js b/tests/cypress/e2e/admin_page/user_overview/view_all_users.cy.js index 0bcc7f5d32c..6f05101f9b6 100644 --- a/tests/cypress/e2e/admin_page/user_overview/view_all_users.cy.js +++ b/tests/cypress/e2e/admin_page/user_overview/view_all_users.cy.js @@ -4,7 +4,7 @@ import { goToAdminUsersPage } from '../../tools/navigation/nav.js'; it('should view all users', () => { goToAdminUsersPage(); - cy.get('[data-cy="view_all_button"]').should('be.not.disabled').should('be.visible').click(); + cy.getDataCy('view_all_button').should('be.not.disabled').should('be.visible').click(); cy.location().should((loc) => { console.log(loc); diff --git a/tests/cypress/e2e/explore_programs_page/explore_programs.cy.js b/tests/cypress/e2e/explore_programs_page/explore_programs.cy.js index 529280ddda3..a9638b81670 100644 --- a/tests/cypress/e2e/explore_programs_page/explore_programs.cy.js +++ b/tests/cypress/e2e/explore_programs_page/explore_programs.cy.js @@ -5,7 +5,7 @@ it('When selecting a program as Hedys choice, it should be shown', ()=>{ loginForAdmin(); goToExploreProgramsPage(); // Get the id of the first program in the db - cy.get('[data-cy="explore_page_programs"]') + cy.getDataCy('explore_page_programs') .children() .first() .invoke('attr', 'data-cy') @@ -14,7 +14,7 @@ it('When selecting a program as Hedys choice, it should be shown', ()=>{ cy.get('@program_id').then(program_id => { // mark the program as Hedys choice cy.get(`#${program_id}`).click(); - cy.get('[data-cy="modal_yes_button"]').click(); + cy.getDataCy('modal_yes_button').click(); // reload the page to see the changes cy.reload(); cy.get(`[data-cy="explore_favourite_programs"] > [data-cy=${program_id}]`).should('be.visible'); diff --git a/tests/cypress/e2e/feedback/feedback_modal.cy.js b/tests/cypress/e2e/feedback/feedback_modal.cy.js index 3dd9273bf94..0fa7a28fe6c 100644 --- a/tests/cypress/e2e/feedback/feedback_modal.cy.js +++ b/tests/cypress/e2e/feedback/feedback_modal.cy.js @@ -7,32 +7,32 @@ describe("Test the feedback feature", () => { }) it("should be able to open the modal", () => { goToHedyPage(); - cy.get('[data-cy="feedback_button"]') + cy.getDataCy('feedback_button') .should("be.visible") .click() - cy.get('[data-cy="modal-feedback"]') + cy.getDataCy('modal-feedback') .should("be.visible") }); it("should not submit if the message or category is empty/not selected", () => { goToTeachersPage(); - cy.get('[data-cy="feedback_button"]') + cy.getDataCy('feedback_button') .should("be.visible") .click() - cy.get('[data-cy="modal-feedback-input"]') + cy.getDataCy('modal-feedback-input') .type("should not work without a category") - cy.get('[data-cy="modal-feedback-input"]') + cy.getDataCy('modal-feedback-input') .should("be.visible") - cy.get('[data-cy="modal-feedback-cancel"]') + cy.getDataCy('modal-feedback-cancel') .click() - cy.get('[data-cy="modal-feedback-input"]') + cy.getDataCy('modal-feedback-input') .should("not.be.visible") }); @@ -45,20 +45,20 @@ describe("Test the feedback feature", () => { goToProfilePage(); - cy.get('[data-cy="feedback_button"]') + cy.getDataCy('feedback_button') .should("be.visible") .click() - cy.get('[data-cy="modal-feedback-input"]') + cy.getDataCy('modal-feedback-input') .type("This feature is wonderful! Thanks a lot for making it happen ;)") cy.get("#feedback") .click() - cy.get('[data-cy="modal-feedback-submit"]') + cy.getDataCy('modal-feedback-submit') .click() - cy.get('[data-cy="modal-feedback-input"]') + cy.getDataCy('modal-feedback-input') .should("not.be.visible") cy.wait("@postFeedback").should('have.nested.property', 'response.statusCode', 200) diff --git a/tests/cypress/e2e/for-teacher_page/class_page/add_student_copy_link.cy.js b/tests/cypress/e2e/for-teacher_page/class_page/add_student_copy_link.cy.js index 5d969c7d17d..596c7411eaa 100644 --- a/tests/cypress/e2e/for-teacher_page/class_page/add_student_copy_link.cy.js +++ b/tests/cypress/e2e/for-teacher_page/class_page/add_student_copy_link.cy.js @@ -4,13 +4,13 @@ it('Is able to see copy link to add student to class', () => { loginForTeacher(); cy.wait(500); - cy.get('[data-cy="view_class_link"]').then($viewClass => { + cy.getDataCy('view_class_link').then($viewClass => { if (!$viewClass.is(':visible')) { - cy.get('[data-cy="view_classes"]').click(); + cy.getDataCy('view_classes').click(); } }); - cy.get('[data-cy="view_class_link"]').first().click(); + cy.getDataCy('view_class_link').first().click(); cy.get('body').then($b => $b.find('[data-cy="survey"]')).then($s => $s.length && $s.hide()) - cy.get('[data-cy="add_student"]').click(); - cy.get('[data-cy="copy_join_link"]').should('be.visible').should('be.enabled').click(); + cy.getDataCy('add_student').click(); + cy.getDataCy('copy_join_link').should('be.visible').should('be.enabled').click(); }) diff --git a/tests/cypress/e2e/for-teacher_page/class_page/add_student_invite_by_username.cy.js b/tests/cypress/e2e/for-teacher_page/class_page/add_student_invite_by_username.cy.js index 3d8714de49e..000aa1592ef 100644 --- a/tests/cypress/e2e/for-teacher_page/class_page/add_student_invite_by_username.cy.js +++ b/tests/cypress/e2e/for-teacher_page/class_page/add_student_invite_by_username.cy.js @@ -4,47 +4,47 @@ it('Is able to add student by name', () => { loginForTeacher(); let student = 'student5' - cy.get('[data-cy="view_class_link"]').then($viewClass => { + cy.getDataCy('view_class_link').then($viewClass => { if (!$viewClass.is(':visible')) { - cy.get('[data-cy="view_classes"]').click(); + cy.getDataCy('view_classes').click(); } }); - cy.get('[data-cy="view_class_link"]').first().click(); + cy.getDataCy('view_class_link').first().click(); cy.get('body').then($b => $b.find('[data-cy="survey"]')).then($s => $s.length && $s.hide()) // delete student if in class - cy.get('[data-cy="class_user_table"]').then(($div) => { + cy.getDataCy('class_user_table').then(($div) => { if ($div.text().includes(student)){ - cy.get('[data-cy="remove_student"]').first().click(); - cy.get('[data-cy="modal_yes_button"]').click(); + cy.getDataCy('remove_student').first().click(); + cy.getDataCy('modal_yes_button').click(); } }) cy.wait(500); - cy.get('[data-cy="add_student"]').click(); + cy.getDataCy('add_student').click(); - cy.get('[data-cy="invite_student"]').click(); - cy.get('[data-cy="modal_prompt_input"]').type(student); - cy.get('[data-cy="modal_ok_button"]').click(); + cy.getDataCy('invite_student').click(); + cy.getDataCy('modal_prompt_input').type(student); + cy.getDataCy('modal_ok_button').click(); login(student, "123456"); - cy.get('[data-cy="user_dropdown"]').click(); - cy.get('[data-cy="my_account_button"]').click(); - cy.get('[data-cy="join_link"]').click(); + cy.getDataCy('user_dropdown').click(); + cy.getDataCy('my_account_button').click(); + cy.getDataCy('join_link').click(); logout(); loginForTeacher(); - cy.get('[data-cy="view_class_link"]').then($viewClass => { + cy.getDataCy('view_class_link').then($viewClass => { if (!$viewClass.is(':visible')) { - cy.get('[data-cy="view_classes"]').click(); + cy.getDataCy('view_classes').click(); } }); - cy.get('[data-cy="view_class_link"]').first().click(); + cy.getDataCy('view_class_link').first().click(); - cy.get('[data-cy="student_username_cell"]').should(($div) => { + cy.getDataCy('student_username_cell').should(($div) => { const text = $div.text() expect(text).include('student5'); }) diff --git a/tests/cypress/e2e/for-teacher_page/class_page/class-survey.cy.js b/tests/cypress/e2e/for-teacher_page/class_page/class-survey.cy.js index 63aabe02f48..aabee9895fd 100644 --- a/tests/cypress/e2e/for-teacher_page/class_page/class-survey.cy.js +++ b/tests/cypress/e2e/for-teacher_page/class_page/class-survey.cy.js @@ -6,36 +6,36 @@ let className = "CLASS1" beforeEach(() => { loginForTeacher("teacher4"); goToTeachersPage(); - cy.get('[data-cy="view_class_link"]').then($viewClass => { + cy.getDataCy('view_class_link').then($viewClass => { if (!$viewClass.is(':visible')) { - cy.get('[data-cy="view_classes"]').click(); + cy.getDataCy('view_classes').click(); } }); - cy.get('[data-cy="view_class_link"]').contains(new RegExp(`^${className}$`)).click(); - cy.get('[data-cy="survey_status_button"]').click(); + cy.getDataCy('view_class_link').contains(new RegExp(`^${className}$`)).click(); + cy.getDataCy('survey_status_button').click(); }) describe('Class Survey View', () => { it("Can be cancelled", () => { - cy.get('[data-cy="survey"]').should("be.visible"); - cy.get('[data-cy="cancel_survey"]').click(); - cy.get('[data-cy="survey"]').should("not.be.visible"); + cy.getDataCy('survey').should("be.visible"); + cy.getDataCy('cancel_survey').click(); + cy.getDataCy('survey').should("not.be.visible"); }) it('Can first respond to 1 question, then to last 3 questions', () => { - cy.get('[data-cy="survey"]').should("be.visible"); - cy.get('[data-cy="input_1"]').type("test"); - cy.get('[data-cy="submit"]').click(); - cy.get('[data-cy="survey_status_button"]').click(); + cy.getDataCy('survey').should("be.visible"); + cy.getDataCy('input_1').type("test"); + cy.getDataCy('submit').click(); + cy.getDataCy('survey_status_button').click(); const surveyInputs = Array.from({length:3},(v, k)=> k+1) cy.wrap(surveyInputs).each((index) => { - cy.getBySel("input_" + index) + cy.getDataCy("input_" + index) .type("test") .invoke("val").then((text) => { expect("test").to.equal(text); }); }); - cy.get('[data-cy="submit"]').click(); - cy.get('[data-cy="survey_status_button"]').contains("complete"); + cy.getDataCy('submit').click(); + cy.getDataCy('survey_status_button').contains("complete"); }) }) diff --git a/tests/cypress/e2e/for-teacher_page/class_page/create_accounts_page/create_accounts.cy.js b/tests/cypress/e2e/for-teacher_page/class_page/create_accounts_page/create_accounts.cy.js index 5730568abb2..a355d25cf03 100644 --- a/tests/cypress/e2e/for-teacher_page/class_page/create_accounts_page/create_accounts.cy.js +++ b/tests/cypress/e2e/for-teacher_page/class_page/create_accounts_page/create_accounts.cy.js @@ -11,13 +11,13 @@ beforeEach(() => { describe('Testing a teacher account', () => { it('Is able to add rows to create more accounts', () => { ({classname, students} = createClassAndAddStudents()); - cy.get('[data-cy="add_multiple_rows"]').click(); + cy.getDataCy('add_multiple_rows').click(); cy.get(':nth-child(6) > [data-cy="username"]').should('have.value', ''); }) it('Is able to create new accounts for class', () => { navigateToClass(classname); - cy.get('[data-cy="student_username_cell"]').should(($div) => { + cy.getDataCy('student_username_cell').should(($div) => { const text = $div.text(); expect(text).include(students[0]); }) @@ -30,9 +30,9 @@ describe('Testing a teacher account', () => { it('Is able to generate passwords', () => { navigateToClass(classname); - cy.get('[data-cy="add_student"]').click(); - cy.get('[data-cy="create_accounts"]').click(); - cy.get('[data-cy="toggle_circle"]').click(); //switches the toggle on so that passwords are generated + cy.getDataCy('add_student').click(); + cy.getDataCy('create_accounts').click(); + cy.getDataCy('toggle_circle').click(); //switches the toggle on so that passwords are generated cy.wait(1000); cy.get(':nth-child(2) > [data-cy="password"]').should('have.length.greaterThan', 0); }) @@ -42,9 +42,9 @@ describe('Testing a teacher account', () => { navigateToClass(classname); cy.url().then(url => { currentUrl = url; - cy.get('[data-cy="add_student"]').click(); - cy.get('[data-cy="create_accounts"]').click(); - cy.get('[data-cy="go_back_button"]').click(); + cy.getDataCy('add_student').click(); + cy.getDataCy('create_accounts').click(); + cy.getDataCy('go_back_button').click(); cy.wait(1000); let statsUrl = Cypress.env('class_page') + currentUrl.substring(currentUrl.indexOf('class/')+6); cy.url().should('include', statsUrl); @@ -53,8 +53,8 @@ describe('Testing a teacher account', () => { it('Is able to remove row', () => { navigateToClass(classname); - cy.get('[data-cy="add_student"]').click(); - cy.get('[data-cy="create_accounts"]').click(); + cy.getDataCy('add_student').click(); + cy.getDataCy('create_accounts').click(); //fills in first row cy.get(':nth-child(2) > [data-cy="username"]').type("student10"); cy.get(':nth-child(2) > [data-cy="password"]').type("123456"); @@ -70,13 +70,13 @@ describe('Testing a teacher account', () => { it('Is able to use the reset button', () => { navigateToClass(classname); - cy.get('[data-cy="add_student"]').click(); - cy.get('[data-cy="create_accounts"]').click(); + cy.getDataCy('add_student').click(); + cy.getDataCy('create_accounts').click(); cy.get(':nth-child(2) > [data-cy="username"]').type("student10"); cy.get(':nth-child(2) > [data-cy="password"]').type("123456"); cy.wait(1000); cy.get(':nth-child(2) > [data-cy="username"]').should('have.value', 'student10'); - cy.get('[data-cy="reset_button"]').click(); + cy.getDataCy('reset_button').click(); cy.wait(1000); cy.get(':nth-child(2) > [data-cy="username"]').should('have.value', ''); }) diff --git a/tests/cypress/e2e/for-teacher_page/class_page/create_accounts_page/create_accounts_second_teachers.cy.js b/tests/cypress/e2e/for-teacher_page/class_page/create_accounts_page/create_accounts_second_teachers.cy.js index 05ad79736e5..ded0dd12ca4 100644 --- a/tests/cypress/e2e/for-teacher_page/class_page/create_accounts_page/create_accounts_second_teachers.cy.js +++ b/tests/cypress/e2e/for-teacher_page/class_page/create_accounts_page/create_accounts_second_teachers.cy.js @@ -17,7 +17,7 @@ before(() => { describe('Testing second teacher accounts', () => { it('Is able to create new accounts for class', () => { navigateToClass(classname); - cy.get('[data-cy="student_username_cell"]').should(($div) => { + cy.getDataCy('student_username_cell').should(($div) => { const text = $div.text(); expect(text).include(students[0]); }) @@ -29,9 +29,9 @@ describe('Testing second teacher accounts', () => { it('Is able to generate passwords', () => { navigateToClass(classname); - cy.get('[data-cy="add_student"]').click(); - cy.get('[data-cy="create_accounts"]').click(); - cy.get('[data-cy="toggle_circle"]').click(); //switches the toggle on so that passwords are generated + cy.getDataCy('add_student').click(); + cy.getDataCy('create_accounts').click(); + cy.getDataCy('toggle_circle').click(); //switches the toggle on so that passwords are generated cy.wait(1000); cy.get(':nth-child(2) > [data-cy="password"]').should('have.length.greaterThan', 0); }) @@ -41,9 +41,9 @@ describe('Testing second teacher accounts', () => { navigateToClass(classname); cy.url().then(url => { currentUrl = url; - cy.get('[data-cy="add_student"]').click(); - cy.get('[data-cy="create_accounts"]').click(); - cy.get('[data-cy="go_back_button"]').click(); + cy.getDataCy('add_student').click(); + cy.getDataCy('create_accounts').click(); + cy.getDataCy('go_back_button').click(); cy.wait(1000); let statsUrl = Cypress.env('class_page') + currentUrl.substring(currentUrl.indexOf('class/')+6); cy.url().should('include', statsUrl); @@ -52,8 +52,8 @@ describe('Testing second teacher accounts', () => { it('Is able to remove row', () => { navigateToClass(classname); - cy.get('[data-cy="add_student"]').click(); - cy.get('[data-cy="create_accounts"]').click(); + cy.getDataCy('add_student').click(); + cy.getDataCy('create_accounts').click(); //fills in first row cy.get(':nth-child(2) > [data-cy="username"]').type("student10"); cy.get(':nth-child(2) > [data-cy="password"]').type("123456"); @@ -69,13 +69,13 @@ describe('Testing second teacher accounts', () => { it('Is able to use the reset button', () => { navigateToClass(classname); - cy.get('[data-cy="add_student"]').click(); - cy.get('[data-cy="create_accounts"]').click(); + cy.getDataCy('add_student').click(); + cy.getDataCy('create_accounts').click(); cy.get(':nth-child(2) > [data-cy="username"]').type("student10"); cy.get(':nth-child(2) > [data-cy="password"]').type("123456"); cy.wait(1000); cy.get(':nth-child(2) > [data-cy="username"]').should('have.value', 'student10'); - cy.get('[data-cy="reset_button"]').click(); + cy.getDataCy('reset_button').click(); cy.wait(1000); cy.get(':nth-child(2) > [data-cy="username"]').should('have.value', ''); }) diff --git a/tests/cypress/e2e/for-teacher_page/class_page/customize_class_button.cy.js b/tests/cypress/e2e/for-teacher_page/class_page/customize_class_button.cy.js index ba1d0eb3b46..8f795a84a6c 100644 --- a/tests/cypress/e2e/for-teacher_page/class_page/customize_class_button.cy.js +++ b/tests/cypress/e2e/for-teacher_page/class_page/customize_class_button.cy.js @@ -4,18 +4,18 @@ it('Is able to go to customize class page', () => { loginForTeacher(); cy.wait(500); - cy.get('[data-cy="view_class_link"]').then($viewClass => { + cy.getDataCy('view_class_link').then($viewClass => { if (!$viewClass.is(':visible')) { - cy.get('[data-cy="view_classes"]').click(); + cy.getDataCy('view_classes').click(); } }); - cy.get('[data-cy="view_class_link"]').first().click(); // Press view class button + cy.getDataCy('view_class_link').first().click(); // Press view class button var currentUrl = ''; cy.url().then(url => { currentUrl = url; cy.get('body').then($b => $b.find('[data-cy="survey"]')).then($s => $s.length && $s.hide()) - cy.get('[data-cy="customize_class_button"]').click(); // Press logs button + cy.getDataCy('customize_class_button').click(); // Press logs button let statsUrl = Cypress.env('customize_class_page') + currentUrl.substring(currentUrl.indexOf('class/')+6); cy.url().should('include', statsUrl); // Check if you are in the logs page diff --git a/tests/cypress/e2e/for-teacher_page/class_page/go_back_to_teacher_page_button.cy.js b/tests/cypress/e2e/for-teacher_page/class_page/go_back_to_teacher_page_button.cy.js index 186df68e5ce..87d21cf314c 100644 --- a/tests/cypress/e2e/for-teacher_page/class_page/go_back_to_teacher_page_button.cy.js +++ b/tests/cypress/e2e/for-teacher_page/class_page/go_back_to_teacher_page_button.cy.js @@ -4,15 +4,15 @@ it('Is able to go to logs page', () => { loginForTeacher(); cy.wait(500); - cy.get('[data-cy="view_class_link"]').then($viewClass => { + cy.getDataCy('view_class_link').then($viewClass => { if (!$viewClass.is(':visible')) { - cy.get('[data-cy="view_classes"]').click(); + cy.getDataCy('view_classes').click(); } }); - cy.get('[data-cy="view_class_link"]').first().click(); // Press view class button + cy.getDataCy('view_class_link').first().click(); // Press view class button cy.get('body').then($b => $b.find('[data-cy="survey"]')).then($s => $s.length && $s.hide()) - cy.get('[data-cy="go_back_button"]') + cy.getDataCy('go_back_button') .should('be.visible') .should('not.be.disabled') .click(); diff --git a/tests/cypress/e2e/for-teacher_page/class_page/second_teachers_invites.cy.js b/tests/cypress/e2e/for-teacher_page/class_page/second_teachers_invites.cy.js index 5b38916099c..03efb1728d3 100644 --- a/tests/cypress/e2e/for-teacher_page/class_page/second_teachers_invites.cy.js +++ b/tests/cypress/e2e/for-teacher_page/class_page/second_teachers_invites.cy.js @@ -20,14 +20,14 @@ describe("Second teachers: invitations", () => { navigateToClass(className); for (const teacher of secondTeachers) { - cy.get('[data-cy="add_second_teacher"]').click(); - cy.get('[data-cy="modal_prompt_input"]').type(teacher); - cy.get('[data-cy="modal_ok_button"]').click(); + cy.getDataCy('add_second_teacher').click(); + cy.getDataCy('modal_prompt_input').type(teacher); + cy.getDataCy('modal_ok_button').click(); } // Check that both invited teachers are in the table for (const teacher of secondTeachers) { - cy.get('[data-cy="invites_block"]') + cy.getDataCy('invites_block') .contains(teacher); } }) @@ -36,11 +36,11 @@ describe("Second teachers: invitations", () => { loginForTeacher(); navigateToClass(className); - cy.get('[data-cy="add_second_teacher"]').click(); - cy.get('[data-cy="modal_prompt_input"]').type(secondTeachers[0]); - cy.get('[data-cy="modal_ok_button"]').click(); + cy.getDataCy('add_second_teacher').click(); + cy.getDataCy('modal_prompt_input').type(secondTeachers[0]); + cy.getDataCy('modal_ok_button').click(); - cy.get('[data-cy="modal_alert_container"]') + cy.getDataCy('modal_alert_container') .contains('pending invitation') }) @@ -48,18 +48,17 @@ describe("Second teachers: invitations", () => { loginForTeacher(); navigateToClass(className); - cy.get('[data-cy="invites_block"]') - .get('[data-cy="invite_username_cell"]') + cy.getDataCy('invites_block invite_username_cell') .contains(secondTeachers[1]) .parent('tr') .find('[data-cy="remove_user_invitation"]') .click(); - cy.get('[data-cy="modal_confirm"] [data-cy="modal_yes_button"]').click(); + cy.getDataCy('modal_confirm modal_yes_button').click(); // This needs to come before we accept teacher2's invitation, otherwise // after this there are no invites and so this table isn't rendered at all. - cy.get('[data-cy="invites_block"]') + cy.getDataCy('invites_block') .should("not.contain", secondTeachers[1]); }); @@ -67,7 +66,7 @@ describe("Second teachers: invitations", () => { cy.intercept('class/join/**').as('join'); loginForTeacher(secondTeachers[0]); goToProfilePage(); - cy.get('[data-cy="join_link"]').click(); + cy.getDataCy('join_link').click(); // Give the Ajax request that gets sent as a result of the click enough time to complete cy.wait('@join'); }) @@ -76,6 +75,6 @@ describe("Second teachers: invitations", () => { loginForTeacher(); navigateToClass(className); - cy.get('[data-cy="second_teacher_username_cell"]').contains(secondTeachers[0]); + cy.getDataCy('second_teacher_username_cell').contains(secondTeachers[0]); }) }) diff --git a/tests/cypress/e2e/for-teacher_page/customize-adventure_page/autosave.cy.js b/tests/cypress/e2e/for-teacher_page/customize-adventure_page/autosave.cy.js index ccbb1db9f28..6c23f1cc074 100644 --- a/tests/cypress/e2e/for-teacher_page/customize-adventure_page/autosave.cy.js +++ b/tests/cypress/e2e/for-teacher_page/customize-adventure_page/autosave.cy.js @@ -20,7 +20,7 @@ describe('auto save', () => { cy.wait(1000) cy.wait("@customizeAdventure").should('have.nested.property', 'response.statusCode', 200) - cy.get('[data-cy="modal_alert_container"]') + cy.getDataCy('modal_alert_container') .should('be.visible'); cy.get('#modal_alert_text') .should('be.visible') diff --git a/tests/cypress/e2e/for-teacher_page/customize-adventure_page/customize_adenture_page.cy.js b/tests/cypress/e2e/for-teacher_page/customize-adventure_page/customize_adenture_page.cy.js index aa5d32444eb..9c1c7a4ed9c 100644 --- a/tests/cypress/e2e/for-teacher_page/customize-adventure_page/customize_adenture_page.cy.js +++ b/tests/cypress/e2e/for-teacher_page/customize-adventure_page/customize_adenture_page.cy.js @@ -16,11 +16,11 @@ describe('Test for the Customize Adventure Page', () => { .should('not.be.disabled'); const data = "to"; editor.setData(data); - cy.getBySel('test_warning_message').should('be.visible').and('contain.text', 'to, to_list') + cy.getDataCy('test_warning_message').should('be.visible').and('contain.text', 'to, to_list') // Once we click the close button cy.get('div[data-cy="test_warning_message"] > p[class="close-dialog"]').click() // The alert should not exist anymore - cy.getBySel('test_warning_message').should('not.exist') + cy.getDataCy('test_warning_message').should('not.exist') }) }) }) diff --git a/tests/cypress/e2e/for-teacher_page/customize-adventure_page/remove_button.cy.js b/tests/cypress/e2e/for-teacher_page/customize-adventure_page/remove_button.cy.js index 413724176fe..3972a581756 100644 --- a/tests/cypress/e2e/for-teacher_page/customize-adventure_page/remove_button.cy.js +++ b/tests/cypress/e2e/for-teacher_page/customize-adventure_page/remove_button.cy.js @@ -8,11 +8,11 @@ describe('Preview button test', () => { goToEditAdventure(); // Initially this should not be visible - cy.get('[data-cy="modal_confirm"]') + cy.getDataCy('modal_confirm') .should('not.be.visible'); cy.get('#modal-no-button') .should('not.be.visible'); - cy.get('[data-cy="modal_yes_button"]') + cy.getDataCy('modal_yes_button') .should('not.be.visible'); // Testing not removing adventure (clicking on remove and then on 'no') @@ -22,7 +22,7 @@ describe('Preview button test', () => { .should('have.attr', 'type', 'reset') .click(); - cy.get('[data-cy="modal_confirm"]') + cy.getDataCy('modal_confirm') .should('be.visible'); cy.get('#modal-no-button') @@ -32,7 +32,7 @@ describe('Preview button test', () => { cy.wait(500); - cy.get('[data-cy="modal_confirm"]') + cy.getDataCy('modal_confirm') .should('not.be.visible'); cy.get('#modal-no-button') .should('not.be.visible'); @@ -44,7 +44,7 @@ describe('Preview button test', () => { cy.get('#remove_adventure_button') .click(); - cy.get('[data-cy="modal_yes_button"]') + cy.getDataCy('modal_yes_button') .should('be.visible') .should('not.be.disabled') .click(); diff --git a/tests/cypress/e2e/for-teacher_page/customize_class_page/customize_class.cy.js b/tests/cypress/e2e/for-teacher_page/customize_class_page/customize_class.cy.js index 3b48fca91ac..c206650e58a 100644 --- a/tests/cypress/e2e/for-teacher_page/customize_class_page/customize_class.cy.js +++ b/tests/cypress/e2e/for-teacher_page/customize_class_page/customize_class.cy.js @@ -5,14 +5,14 @@ describe('customize class page', () => { beforeEach(() => { loginForTeacher(); ensureClass(); - cy.get('[data-cy="view_class_link"]').then($viewClass => { + cy.getDataCy('view_class_link').then($viewClass => { if (!$viewClass.is(':visible')) { - cy.get('[data-cy="view_classes"]').click(); + cy.getDataCy('view_classes').click(); } }); - cy.getBySel('view_class_link').first().click(); // Press on view class button + cy.getDataCy('view_class_link').first().click(); // Press on view class button cy.get('body').then($b => $b.find('[data-cy="survey"]')).then($s => $s.length && $s.hide()) - cy.getBySel('customize_class_button').click(); // Press customize class button + cy.getDataCy('customize_class_button').click(); // Press customize class button cy.get("#opening_date_container").should("not.be.visible") cy.get("#opening_date_label").click(); cy.get("#opening_date_container").should("be.visible") @@ -20,8 +20,8 @@ describe('customize class page', () => { // Remove any customizations that already exist to get the class into a predictable state // This always throws up a modal dialog cy.intercept('/for-teachers/restore-customizations*').as('restoreCustomizations'); - cy.getBySel('remove_customizations_button').click(); - cy.getBySel('modal_yes_button').click(); + cy.getDataCy('remove_customizations_button').click(); + cy.getDataCy('modal_yes_button').click(); cy.wait('@restoreCustomizations'); }); @@ -34,7 +34,7 @@ describe('customize class page', () => { }); it('goes back to the view class page', () => { - cy.getBySel('back_to_class') + cy.getDataCy('back_to_class') .should('be.visible') .should('not.be.disabled') .click(); @@ -45,35 +45,35 @@ describe('customize class page', () => { it('level 1 should be visible by default, and the level dropdown changes which adventures are displayed', () => { // Click on level 1 - cy.getBySel('adventures') + cy.getDataCy('adventures') .select('1') .should('have.value', '1'); // level 1 should be visible and level 2 shouldn't exist - cy.getBySel("level-1") + cy.getDataCy("level-1") .should('be.visible'); - cy.getBySel("level-2") + cy.getDataCy("level-2") .should('not.exist'); - cy.getBySel('adventures') + cy.getDataCy('adventures') .select('2') .should('have.value', '2'); - cy.get("*[data-cy='level-2']") + cy.getDataCy("*level-2") .should('be.visible'); - cy.get("*[data-cy='level-1']") + cy.getDataCy("*level-1") .should('not.exist'); }); it('tests if the opening tests are not empty', () => { // The following line has a bug in cypress: - // cy.getBySel("opening_date_level_" + index).type("2023-01-01").should("have.value", "2023-01-01") + // cy.getDataCy("opening_date_level_" + index).type("2023-01-01").should("have.value", "2023-01-01") // The following tests only checks if the field is not empty using a for loop: var levelarray = Array.from({length:18},(v, k)=>k+1) // length reflects how many levels there are cy.wrap(levelarray).each((index) => { - cy.getBySel("opening_date_level_" + index) + cy.getDataCy("opening_date_level_" + index) .type("2023-01-01") .invoke('val').then((text) => { expect('2023-01-01').to.equal(text); @@ -83,23 +83,23 @@ describe('customize class page', () => { it('the quiz score holds the value typed to it', () => { // testing quiz score feature - cy.getBySel('quiz_input').clear().type("50").should("have.value", "50"); + cy.getDataCy('quiz_input').clear().type("50").should("have.value", "50"); }); it('removes the adventure and checks that it is added to the available adventures drop down and removed from the dragger', () => { // Click on level 2 - cy.getBySel("adventures") + cy.getDataCy("adventures") .select('2') .should('have.value', '2'); // Finding this makes sure that level-2 has been loaded - cy.get('[data-cy="level-2"]'); + cy.getDataCy('level-2'); // The available adventures dropdown should only include the default option // but it may also have teacher-specific adventures - cy.getBySel("available_adventures_current_level") + cy.getDataCy("available_adventures_current_level") .children() .then($children => $children.length) .as('startLength') @@ -114,7 +114,7 @@ describe('customize class page', () => { .click(); // The available adventures dropdown should now include the new adventure - cy.getBySel("available_adventures_current_level") + cy.getDataCy("available_adventures_current_level") .children() .should('have.length', startLength + 1); @@ -123,15 +123,15 @@ describe('customize class page', () => { .should('have.value', `${adventure}`); // after selecting the adventure, it shouldn't be among the options - cy.getBySel("available_adventures_current_level") + cy.getDataCy("available_adventures_current_level") .select(`${adventure}`) - cy.getBySel("available_adventures_current_level") + cy.getDataCy("available_adventures_current_level") .children() .should('have.length', startLength); // the adventure should now be last - cy.get(`[data-cy="level-2"] div[data-cy="${adventure}"`) + cy.getDataCy(`level-2 ${adventure}`) .should("exist") }); }); @@ -150,16 +150,16 @@ describe('customize class page', () => { selectLevel('1'); // Now it should be visible - cy.getBySel('level-1').should('be.visible'); + cy.getDataCy('level-1').should('be.visible'); // Get the first and second adventure - cy.getBySel('level-1') + cy.getDataCy('level-1') .children() .eq(0) .invoke('attr', 'value') .as('first_adventure'); - cy.getBySel('level-1') + cy.getDataCy('level-1') .children() .eq(1) .invoke('attr', 'value') @@ -170,24 +170,24 @@ describe('customize class page', () => { cy.get('@second_adventure').then(second_adventure => { // Move the second adventure to the first place - cy.getBySel('level-1') + cy.getDataCy('level-1') .children() .eq(1) .trigger('dragstart') - cy.getBySel('level-1') + cy.getDataCy('level-1') .children() .eq(0) .trigger('drop') .trigger('dragend'); // they should be inverted now - cy.getBySel('level-1') + cy.getDataCy('level-1') .children() .eq(0) .should('have.value', second_adventure); - cy.getBySel('level-1') + cy.getDataCy('level-1') .children() .eq(1) .should('have.value', first_adventure); @@ -199,7 +199,7 @@ describe('customize class page', () => { it('Disabling current level displays a message', () => { cy.intercept('/for-teachers/customize-class/*').as('updateCustomizations'); - cy.getBySel('level-1').should('be.visible'); + cy.getDataCy('level-1').should('be.visible'); cy.get('#state-disabled').should('not.be.visible'); cy.get('#enable_level_1').parent('.switch').click(); @@ -208,19 +208,19 @@ describe('customize class page', () => { cy.wait('@updateCustomizations').should('have.nested.property', 'response.statusCode', 200); }); - it.only('Clicking the Reset button displays a confirm dialog', () => { + it('Clicking the Reset button displays a confirm dialog', () => { /** * At the beggining, the Parrot adventure should be in the level 1's adventures */ selectLevel('1'); cy.get('#htmx-modal').should('not.exist'); - cy.get(`*[data-cy="level-1"] div[data-cy='parrot'] *[data-cy="hide"]`).click(); - cy.getBySel('parrot').should('not.exist'); + cy.getDataCy(`*level-1 parrot *hide`).click(); + cy.getDataCy('parrot').should('not.exist'); - cy.getBySel('reset_adventures').click(); - cy.getBySel('confirm_modal').should('be.visible'); - cy.getBySel('htmx_modal_yes_button').click(); - cy.getBySel('parrot').should('be.visible'); + cy.getDataCy('reset_adventures').click(); + cy.getDataCy('confirm_modal').should('be.visible'); + cy.getDataCy('htmx_modal_yes_button').click(); + cy.getDataCy('parrot').should('be.visible'); }); describe('an adventure that is hidden', () => { @@ -228,7 +228,7 @@ describe('customize class page', () => { beforeEach(() => { selectLevel('1'); - cy.get(`*[data-cy="level-1"] div[data-cy='${hiddenAdventure}'] *[data-cy="hide"]`).click(); + cy.getDataCy(`*level-1 ${hiddenAdventure} *hide`).click(); }); it('disappears from the tab list', () => { @@ -236,11 +236,11 @@ describe('customize class page', () => { }); it('can be re-added from the right dropdown list', () => { - cy.getBySel('available_adventures_current_level').children(`*[value='${hiddenAdventure}']`).should('exist'); + cy.getDataCy('available_adventures_current_level').children(`*[value='${hiddenAdventure}']`).should('exist'); - cy.getBySel('available_adventures_current_level').select(`${hiddenAdventure}`); + cy.getDataCy('available_adventures_current_level').select(`${hiddenAdventure}`); - cy.get(`div[data-cy="${hiddenAdventure}"]`).should('exist'); + cy.getDataCy(hiddenAdventure).should('exist'); }); it('becomes invisible for the student', () => { @@ -253,6 +253,6 @@ describe('customize class page', () => { }); function selectLevel(level) { - cy.getBySel("adventures").select(level); - cy.getBySel("adventures").should('have.value', level); + cy.getDataCy("adventures").select(level); + cy.getDataCy("adventures").should('have.value', level); } \ No newline at end of file diff --git a/tests/cypress/e2e/for-teacher_page/customize_class_page/customize_class_second_teacher.cy.js b/tests/cypress/e2e/for-teacher_page/customize_class_page/customize_class_second_teacher.cy.js index 8237b5c4a88..dac07404c77 100644 --- a/tests/cypress/e2e/for-teacher_page/customize_class_page/customize_class_second_teacher.cy.js +++ b/tests/cypress/e2e/for-teacher_page/customize_class_page/customize_class_second_teacher.cy.js @@ -5,14 +5,14 @@ describe('customize class page', () => { loginForTeacher("teacher4"); // ensureIsSecondTeacher("teacher1", "teacher2") // await ensureClass(); - cy.get('[data-cy="view_class_link"]').then($viewClass => { + cy.getDataCy('view_class_link').then($viewClass => { if (!$viewClass.is(':visible')) { - cy.get('[data-cy="view_classes"]').click(); + cy.getDataCy('view_classes').click(); } }); - cy.getBySel('view_class_link').first().click(); // Press on view class button + cy.getDataCy('view_class_link').first().click(); // Press on view class button cy.get('body').then($b => $b.find('[data-cy="survey"]')).then($s => $s.length && $s.hide()) - cy.getBySel('customize_class_button').click(); // Press customize class button + cy.getDataCy('customize_class_button').click(); // Press customize class button cy.get("#opening_date_container").should("not.be.visible") cy.get("#opening_date_label").click(); cy.get("#opening_date_container").should("be.visible") @@ -20,8 +20,8 @@ describe('customize class page', () => { // Remove any customizations that already exist to get the class into a predictable state // This always throws up a modal dialog cy.intercept('/for-teachers/restore-customizations*').as('restoreCustomizations'); - cy.getBySel('remove_customizations_button').click(); - cy.getBySel('modal_yes_button').click(); + cy.getDataCy('remove_customizations_button').click(); + cy.getDataCy('modal_yes_button').click(); cy.wait('@restoreCustomizations'); }); @@ -34,7 +34,7 @@ describe('customize class page', () => { }); it('goes back to the view class page', () => { - cy.getBySel('back_to_class') + cy.getDataCy('back_to_class') .should('be.visible') .should('not.be.disabled') .click(); @@ -45,35 +45,35 @@ describe('customize class page', () => { it('level 1 should be visible by default, and the level dropdown changes which adventures are displayed', () => { // Click on level 1 - cy.getBySel('adventures') + cy.getDataCy('adventures') .select('1') .should('have.value', '1'); // level 1 should be visible and level 2 shouldn't exist - cy.getBySel("level-1") + cy.getDataCy("level-1") .should('be.visible'); - cy.getBySel("level-2") + cy.getDataCy("level-2") .should('not.exist'); - cy.getBySel('adventures') + cy.getDataCy('adventures') .select('2') .should('have.value', '2'); - cy.get("*[data-cy='level-2']") + cy.getDataCy("*level-2") .should('be.visible'); - cy.get("*[data-cy='level-1']") + cy.getDataCy("*level-1") .should('not.exist'); }); it('tests if the opening tests are not empty', () => { // The following line has a bug in cypress: - // cy.getBySel("opening_date_level_" + index).type("2023-01-01").should("have.value", "2023-01-01") + // cy.getDataCy("opening_date_level_" + index).type("2023-01-01").should("have.value", "2023-01-01") // The following tests only checks if the field is not empty using a for loop: var levelarray = Array.from({length:18},(v, k)=>k+1) // length reflects how many levels there are cy.wrap(levelarray).each((index) => { - cy.getBySel("opening_date_level_" + index) + cy.getDataCy("opening_date_level_" + index) .type("2023-01-01") .invoke('val').then((text) => { expect('2023-01-01').to.equal(text); @@ -83,23 +83,23 @@ describe('customize class page', () => { it('the quiz score holds the value typed to it', () => { // testing quiz score feature - cy.getBySel('quiz_input').clear().type("50").should("have.value", "50"); + cy.getDataCy('quiz_input').clear().type("50").should("have.value", "50"); }); it('removes the adventure and checks that it is added to the available adventures drop down and removed from the dragger', () => { // Click on level 2 - cy.getBySel("adventures") + cy.getDataCy("adventures") .select('2') .should('have.value', '2'); // Finding this makes sure that level-2 has been loaded - cy.get('[data-cy="level-2"]'); + cy.getDataCy('level-2'); // The available adventures dropdown should only include the default option // but it may also have teacher-specific adventures - cy.getBySel("available_adventures_current_level") + cy.getDataCy("available_adventures_current_level") .children() .then($children => $children.length) .as('startLength') @@ -114,7 +114,7 @@ describe('customize class page', () => { .click(); // The available adventures dropdown should now include the new adventure - cy.getBySel("available_adventures_current_level") + cy.getDataCy("available_adventures_current_level") .children() .should('have.length', startLength + 1); @@ -123,15 +123,15 @@ describe('customize class page', () => { .should('have.value', `${adventure}`); // after selecting the adventure, it shouldn't be among the options - cy.getBySel("available_adventures_current_level") + cy.getDataCy("available_adventures_current_level") .select(`${adventure}`) - cy.getBySel("available_adventures_current_level") + cy.getDataCy("available_adventures_current_level") .children() .should('have.length', startLength); // the adventure should now be last - cy.get(`[data-cy="level-2"] div[data-cy="${adventure}"`) + cy.getDataCy(`level-2 ${adventure}`) .should("exist") }); }); @@ -141,7 +141,7 @@ describe('customize class page', () => { it('Disabling current level displays a message', () => { cy.intercept('/for-teachers/customize-class/*').as('updateCustomizations'); - cy.getBySel('level-1').should('be.visible'); + cy.getDataCy('level-1').should('be.visible'); cy.get('#state-disabled').should('not.be.visible'); cy.get('#enable_level_1').parent('.switch').click(); @@ -156,13 +156,13 @@ describe('customize class page', () => { */ selectLevel('1'); cy.get('#htmx-modal').should('not.exist'); - cy.get(`*[data-cy="level-1"] div[data-cy='parrot'] *[data-cy="hide"]`).click(); - cy.getBySel('parrot').should('not.exist'); + cy.getDataCy(`*level-1 parrot *hide`).click(); + cy.getDataCy('parrot').should('not.exist'); - cy.getBySel('reset_adventures').click(); - cy.getBySel('confirm_modal').should('be.visible'); - cy.getBySel('htmx_modal_yes_button').click(); - cy.getBySel('parrot').should('be.visible'); + cy.getDataCy('reset_adventures').click(); + cy.getDataCy('confirm_modal').should('be.visible'); + cy.getDataCy('htmx_modal_yes_button').click(); + cy.getDataCy('parrot').should('be.visible'); }); describe('an adventure that is hidden', () => { @@ -170,7 +170,7 @@ describe('customize class page', () => { beforeEach(() => { selectLevel('1'); - cy.get(`*[data-cy="level-1"] div[data-cy='${hiddenAdventure}'] *[data-cy="hide"]`).click(); + cy.getDataCy(`*level-1 ${hiddenAdventure} *hide`).click(); }); it('disappears from the tab list', () => { @@ -178,18 +178,18 @@ describe('customize class page', () => { }); it('can be re-added from the right dropdown list', () => { - cy.getBySel('available_adventures_current_level').children(`*[value='${hiddenAdventure}']`).should('exist'); + cy.getDataCy('available_adventures_current_level').children(`*[value='${hiddenAdventure}']`).should('exist'); - cy.getBySel('available_adventures_current_level').select(`${hiddenAdventure}`); + cy.getDataCy('available_adventures_current_level').select(`${hiddenAdventure}`); - cy.get(`div[data-cy="${hiddenAdventure}"]`).should('exist'); + cy.getDataCy(`${hiddenAdventure}`).should('exist'); }); }); }); function selectLevel(level) { - cy.getBySel("adventures") + cy.getDataCy("adventures") .select(level) .should('have.value', level); } \ No newline at end of file diff --git a/tests/cypress/e2e/for-teacher_page/customize_class_page/quiz_parsons.cy.js b/tests/cypress/e2e/for-teacher_page/customize_class_page/quiz_parsons.cy.js index a1f4552ea0f..ac55537b6e7 100644 --- a/tests/cypress/e2e/for-teacher_page/customize_class_page/quiz_parsons.cy.js +++ b/tests/cypress/e2e/for-teacher_page/customize_class_page/quiz_parsons.cy.js @@ -5,36 +5,36 @@ describe('customize class page', () => { beforeEach(() => { loginForTeacher(); ensureClass(); - cy.get('[data-cy="view_class_link"]').then($viewClass => { + cy.getDataCy('view_class_link').then($viewClass => { if (!$viewClass.is(':visible')) { - cy.get('[data-cy="view_classes"]').click(); + cy.getDataCy('view_classes').click(); } }); - cy.getBySel('view_class_link').first().click(); // Press on view class button + cy.getDataCy('view_class_link').first().click(); // Press on view class button cy.get('body').then($b => $b.find('[data-cy="survey"]')).then($s => $s.length && $s.hide()) - cy.getBySel('customize_class_button').click(); // Press customize class button + cy.getDataCy('customize_class_button').click(); // Press customize class button // Remove any customizations that already exist to get the class into a predictable state // This always throws up a modal dialog cy.intercept('/for-teachers/restore-customizations*').as('restoreCustomizations'); - cy.getBySel('remove_customizations_button').click(); - cy.getBySel('modal_yes_button').click(); + cy.getDataCy('remove_customizations_button').click(); + cy.getDataCy('modal_yes_button').click(); cy.wait('@restoreCustomizations'); }); it('checks that puzzle and quiz exist in list', () => { // validate and then remove the quiz - cy.get('[data-cy="level-1"] [data-cy="quiz"]') + cy.getDataCy('level-1 quiz') .should("exist") - cy.get('[data-cy="level-1"] [data-cy="parsons"]') + cy.getDataCy('level-1 parsons') .should("exist") }); it('removes the puzzle and quiz from level 2', () => { // Click on level 2 - cy.getBySel("adventures") + cy.getDataCy("adventures") .select('2') .should('have.value', '2'); @@ -45,7 +45,7 @@ describe('customize class page', () => { cy.get('[data-cy="level-2"] div:last [data-cy="hide"]') .click(); - cy.get('[data-cy="level-2"] [data-cy="quiz"]') + cy.getDataCy('level-2 quiz') .should("not.exist") // validate and then remove the puzzle @@ -55,7 +55,7 @@ describe('customize class page', () => { cy.get('[data-cy="level-2"] div:last [data-cy="hide"]') .click(); - cy.get('[data-cy="level-2"] [data-cy="parsons"]') + cy.getDataCy('level-2 parsons') .should("not.exist") }); @@ -67,7 +67,7 @@ describe('customize class page', () => { cy.get('[data-cy="level-1"] div:last [data-cy="hide"]') .click(); - cy.get('[data-cy="level-1"] [data-cy="quiz"]') + cy.getDataCy('level-1 quiz') .should("not.exist") // validate and then remove the puzzle @@ -77,18 +77,18 @@ describe('customize class page', () => { cy.get('[data-cy="level-1"] div:last [data-cy="hide"]') .click(); - cy.get('[data-cy="level-1"] [data-cy="parsons"]') + cy.getDataCy('level-1 parsons') .should("not.exist") // add them from available list - cy.getBySel("available_adventures_current_level") + cy.getDataCy("available_adventures_current_level") .select("quiz") - cy.getBySel("available_adventures_current_level") + cy.getDataCy("available_adventures_current_level") .select("parsons") // Now the order should be quiz as last, then parsons. - cy.get('[data-cy="level-1"] [data-cy="parsons"]') + cy.getDataCy('level-1 parsons') .should("not.exist") cy.get('[data-cy="level-1"] div:last input') @@ -110,7 +110,7 @@ describe('customize class page', () => { cy.reload(); - cy.get('[data-cy="level-1"] [data-cy="quiz"]') + cy.getDataCy('level-1 quiz') .should("not.exist") }); @@ -129,7 +129,7 @@ describe('customize class page', () => { cy.reload(); - cy.get('[data-cy="level-1"] [data-cy="parsons"]') + cy.getDataCy('level-1 parsons') .should("not.exist") }); diff --git a/tests/cypress/e2e/for-teacher_page/general/click_duplicate_class.cy.js b/tests/cypress/e2e/for-teacher_page/general/click_duplicate_class.cy.js index b69bcdab1db..6f9852daa5c 100644 --- a/tests/cypress/e2e/for-teacher_page/general/click_duplicate_class.cy.js +++ b/tests/cypress/e2e/for-teacher_page/general/click_duplicate_class.cy.js @@ -9,20 +9,20 @@ describe('Is able to click on duplicate class', () => { createClass(); // Click on duplicate icon - cy.get('[data-cy="view_class_link"]').then($viewClass => { + cy.getDataCy('view_class_link').then($viewClass => { if (!$viewClass.is(':visible')) { - cy.get('[data-cy="view_classes"]').click(); + cy.getDataCy('view_classes').click(); } }); cy.get('#duplicate_class').first().click(); // Checks for duplicate class name - cy.get('[data-cy="modal_prompt_input"]').should('be.empty'); - cy.get('[data-cy="modal_prompt_input"]').should('be.visible'); - cy.get('[data-cy="modal_prompt_input"]').should('be.enabled'); + cy.getDataCy('modal_prompt_input').should('be.empty'); + cy.getDataCy('modal_prompt_input').should('be.visible'); + cy.getDataCy('modal_prompt_input').should('be.enabled'); - cy.get('[data-cy="modal_ok_button"]').should('be.visible'); - cy.get('[data-cy="modal_ok_button"]').should('be.enabled'); + cy.getDataCy('modal_ok_button').should('be.visible'); + cy.getDataCy('modal_ok_button').should('be.enabled'); cy.get('#modal-cancel-button').should('be.visible'); cy.get('#modal-cancel-button').should('be.enabled'); @@ -34,9 +34,9 @@ describe('Is able to click on duplicate class', () => { goToTeachersPage(); // Take actions only when teacher2 is a second teacher; i.e., having teacher1 as a teacher. - cy.get('[data-cy="view_class_link"]').then($viewClass => { + cy.getDataCy('view_class_link').then($viewClass => { if (!$viewClass.is(':visible')) { - cy.get('[data-cy="view_classes"]').click(); + cy.getDataCy('view_classes').click(); } }); cy.get("#classes_table tbody #teacher_cell") @@ -47,20 +47,20 @@ describe('Is able to click on duplicate class', () => { cy.wait(50) //Checks for Second Teachers duplication - cy.get('[data-cy="modal_yes_button"]').should('be.visible'); - cy.get('[data-cy="modal_yes_button"]').should('be.enabled'); + cy.getDataCy('modal_yes_button').should('be.visible'); + cy.getDataCy('modal_yes_button').should('be.enabled'); cy.get('#modal-no-button').should('be.visible'); cy.get('#modal-no-button').should('be.enabled').click(); // Checks for input field - cy.get('[data-cy="modal_prompt_input"]').should('not.have.value', ''); - cy.get('[data-cy="modal_prompt_input"]').should('be.visible'); - cy.get('[data-cy="modal_prompt_input"]').should('be.enabled'); + cy.getDataCy('modal_prompt_input').should('not.have.value', ''); + cy.getDataCy('modal_prompt_input').should('be.visible'); + cy.getDataCy('modal_prompt_input').should('be.enabled'); // Checks for ok button - cy.get('[data-cy="modal_ok_button"]').should('be.visible'); - cy.get('[data-cy="modal_ok_button"]').should('be.enabled'); + cy.getDataCy('modal_ok_button').should('be.visible'); + cy.getDataCy('modal_ok_button').should('be.enabled'); // Checks for cancel button cy.get('#modal-cancel-button').should('be.visible'); diff --git a/tests/cypress/e2e/for-teacher_page/general/click_new_class.cy.js b/tests/cypress/e2e/for-teacher_page/general/click_new_class.cy.js index ed6513f4ad0..fe93ffd9900 100644 --- a/tests/cypress/e2e/for-teacher_page/general/click_new_class.cy.js +++ b/tests/cypress/e2e/for-teacher_page/general/click_new_class.cy.js @@ -10,12 +10,12 @@ describe('Is able to click on create new class', () => { // Assert that the input field is empty, // the ok button is visible and // the cancel button is visible - cy.get('[data-cy="modal_prompt_input"]').should('be.empty'); - cy.get('[data-cy="modal_prompt_input"]').should('be.visible'); - cy.get('[data-cy="modal_prompt_input"]').should('be.enabled'); + cy.getDataCy('modal_prompt_input').should('be.empty'); + cy.getDataCy('modal_prompt_input').should('be.visible'); + cy.getDataCy('modal_prompt_input').should('be.enabled'); - cy.get('[data-cy="modal_ok_button"]').should('be.visible'); - cy.get('[data-cy="modal_ok_button"]').should('be.enabled'); + cy.getDataCy('modal_ok_button').should('be.visible'); + cy.getDataCy('modal_ok_button').should('be.enabled'); cy.get('#modal-cancel-button').should('be.visible'); cy.get('#modal-cancel-button').should('be.enabled'); diff --git a/tests/cypress/e2e/for-teacher_page/general/duplicate_class.cy.js b/tests/cypress/e2e/for-teacher_page/general/duplicate_class.cy.js index 1809db33448..72fa15361ac 100644 --- a/tests/cypress/e2e/for-teacher_page/general/duplicate_class.cy.js +++ b/tests/cypress/e2e/for-teacher_page/general/duplicate_class.cy.js @@ -13,27 +13,27 @@ describe('Duplicate class tests', () => { // Click on duplicate icon cy.reload(); cy.wait(500); - cy.get('[data-cy="view_class_link"]').then($viewClass => { + cy.getDataCy('view_class_link').then($viewClass => { if (!$viewClass.is(':visible')) { - cy.get('[data-cy="view_classes"]').click(); + cy.getDataCy('view_classes').click(); } }); cy.get('#duplicate_class').first().click(); // Checks for input field - cy.get('[data-cy="modal_prompt_input"]').type(duplicate_class); - cy.get('[data-cy="modal_ok_button"]').click(); + cy.getDataCy('modal_prompt_input').type(duplicate_class); + cy.getDataCy('modal_ok_button').click(); cy.reload(); cy.wait(500); - cy.get('[data-cy="view_class_link"]').then($viewClass => { + cy.getDataCy('view_class_link').then($viewClass => { if (!$viewClass.is(':visible')) { - cy.get('[data-cy="view_classes"]').click(); + cy.getDataCy('view_classes').click(); } }); - cy.get('[data-cy="view_class_link"]').contains(duplicate_class).click(); - cy.get('[data-cy="customize_class_button"]').click(); + cy.getDataCy('view_class_link').contains(duplicate_class).click(); + cy.getDataCy('customize_class_button').click(); cy.get("#opening_date_container").should("not.be.visible") cy.get("#opening_date_label").click(); cy.get("#opening_date_container").should("be.visible") @@ -45,31 +45,31 @@ describe('Duplicate class tests', () => { loginForTeacher(); goToTeachersPage(); - cy.get('[data-cy="view_class_link"]').then($viewClass => { + cy.getDataCy('view_class_link').then($viewClass => { if (!$viewClass.is(':visible')) { - cy.get('[data-cy="view_classes"]').click(); + cy.getDataCy('view_classes').click(); } }); cy.get("tr") // This class has second teachers. - cy.get("[data-cy='duplicate_CLASS1']").click(); + cy.getDataCy("duplicate_CLASS1").click(); - cy.get('[data-cy="modal_yes_button"]').should('be.enabled').click(); + cy.getDataCy('modal_yes_button').should('be.enabled').click(); const duplicate_class = `test class ${Math.random()}`; - cy.get('[data-cy="modal_prompt_input"]').type(duplicate_class); - cy.get('[data-cy="modal_ok_button"]').click(); + cy.getDataCy('modal_prompt_input').type(duplicate_class); + cy.getDataCy('modal_ok_button').click(); cy.reload(); cy.wait(500); - cy.get('[data-cy="view_class_link"]').then($viewClass => { + cy.getDataCy('view_class_link').then($viewClass => { if (!$viewClass.is(':visible')) { - cy.get('[data-cy="view_classes"]').click(); + cy.getDataCy('view_classes').click(); } }); - cy.get('[data-cy="view_class_link"]').contains(duplicate_class).click(); - cy.get('[data-cy="invites_block"]').should('be.visible'); - cy.get('[data-cy="customize_class_button"]').click(); + cy.getDataCy('view_class_link').contains(duplicate_class).click(); + cy.getDataCy('invites_block').should('be.visible'); + cy.getDataCy('customize_class_button').click(); cy.get("#opening_date_container").should("not.be.visible") cy.get("#opening_date_label").click(); cy.get("#opening_date_container").should("be.visible") diff --git a/tests/cypress/e2e/for-teacher_page/general/preview-adventure.cy.js b/tests/cypress/e2e/for-teacher_page/general/preview-adventure.cy.js index 0a6c61c83be..0c57848aed7 100644 --- a/tests/cypress/e2e/for-teacher_page/general/preview-adventure.cy.js +++ b/tests/cypress/e2e/for-teacher_page/general/preview-adventure.cy.js @@ -11,9 +11,9 @@ describe('Is able to preview adventures', () => { } }); // preview adventure3 - cy.get(`[data-cy="preview-${adv}"]`).click(); + cy.getDataCy(`preview-${adv}`).click(); // now it should be visible in code-page. - cy.get(`[data-cy='${adv}']`) + cy.getDataCy(adv) .should("be.visible") .should("contain.text", adv) cy.get("#adventures-tab").should("be.visible") diff --git a/tests/cypress/e2e/for-teacher_page/general/preview-class.cy.js b/tests/cypress/e2e/for-teacher_page/general/preview-class.cy.js index 1fd95765d5a..0a385eeee60 100644 --- a/tests/cypress/e2e/for-teacher_page/general/preview-class.cy.js +++ b/tests/cypress/e2e/for-teacher_page/general/preview-class.cy.js @@ -23,39 +23,39 @@ describe('Is able to preview class', () => { cy.get("#adventures-buttons [data-tab='print_command']"); cy.get("#adventures-buttons [data-tab='ask_command']"); // assert that no preview_class_banner is shown right now - cy.get("[data-cy='preview_class_banner']").should("not.exist"); + cy.getDataCy("preview_class_banner").should("not.exist"); // now we create a custom class let className = createClass(); goToTeachersPage(); // we navigate to our custom class // if this ever fails, it might be due to pagination - cy.get('[data-cy="view_class_link"]').then($viewClass => { + cy.getDataCy('view_class_link').then($viewClass => { if (!$viewClass.is(':visible')) { - cy.get('[data-cy="view_classes"]').click(); + cy.getDataCy('view_classes').click(); } }); cy.get("a.view_class").contains(className).click(); - cy.get('[data-cy="customize_class_button"]').click(); + cy.getDataCy('customize_class_button').click(); cy.get("#levels-dropdown").select("1"); // we remove the print command from our custom class cy.get("div[data-cy='print_command'] span").click(); // we preview the class without the print command - cy.get("a[data-cy='preview_class_link']").click(); + cy.getDataCy("preview_class_link").click(); // check the banner is there - cy.get("[data-cy='preview_class_banner']"); + cy.getDataCy("preview_class_banner"); // check the is_command is there cy.get("#adventures-buttons [data-tab='ask_command']"); // check that the print_command is absent cy.get("#adventures-buttons [data-tab='print_command']").should("not.exist"); // exit preview mode - cy.get("[data-cy='preview_class_banner'] a").click(); + cy.get('[data-cy="preview_class_banner"] a').click(); // we now expect the normal situation to be restored cy.get("#hedybutton").click(); goToLevel(1); cy.get("#adventures-buttons [data-tab='print_command']"); - cy.get("[data-cy='preview_class_banner']").should("not.exist"); + cy.getDataCy("preview_class_banner").should("not.exist"); }) }) diff --git a/tests/cypress/e2e/for-teacher_page/general/remove_button.cy.js b/tests/cypress/e2e/for-teacher_page/general/remove_button.cy.js index f83e70c8dd9..f6aafade7f2 100644 --- a/tests/cypress/e2e/for-teacher_page/general/remove_button.cy.js +++ b/tests/cypress/e2e/for-teacher_page/general/remove_button.cy.js @@ -9,9 +9,9 @@ describe('Remove class test', () => { goToTeachersPage(); cy.reload(); cy.wait(500); - cy.get('[data-cy="view_class_link"]').then($viewClass => { + cy.getDataCy('view_class_link').then($viewClass => { if (!$viewClass.is(':visible')) { - cy.get('[data-cy="view_classes"]').click(); + cy.getDataCy('view_classes').click(); } }); cy.get("#remove-class").first().click() diff --git a/tests/cypress/e2e/hedy_page/developers_mode_switch.cy.js b/tests/cypress/e2e/hedy_page/developers_mode_switch.cy.js index 6a491922a95..6aa42e3f203 100644 --- a/tests/cypress/e2e/hedy_page/developers_mode_switch.cy.js +++ b/tests/cypress/e2e/hedy_page/developers_mode_switch.cy.js @@ -25,7 +25,7 @@ describe('Developers mode', () => { ({classname, students} = createClassAndAddStudents()); navigateToClass(classname); - cy.get('[data-cy="customize_class_button"]').click(); + cy.getDataCy('customize_class_button').click(); cy.get("#developers_mode") .should("not.be.checked") .click() diff --git a/tests/cypress/e2e/hedy_page/dropdown_level.cy.js b/tests/cypress/e2e/hedy_page/dropdown_level.cy.js index d8376d3b746..36df33be447 100644 --- a/tests/cypress/e2e/hedy_page/dropdown_level.cy.js +++ b/tests/cypress/e2e/hedy_page/dropdown_level.cy.js @@ -15,14 +15,14 @@ describe('Go to level dropdown', () => { goToTeachersPage(); cy.wait(500); - cy.get('[data-cy="view_class_link"]').then($viewClass => { + cy.getDataCy('view_class_link').then($viewClass => { if (!$viewClass.is(':visible')) { - cy.get('[data-cy="view_classes"]').click(); + cy.getDataCy('view_classes').click(); } }); - cy.get('[data-cy="view_class_link"]').contains(new RegExp(`^${classname}$`)).click(); + cy.getDataCy('view_class_link').contains(new RegExp(`^${classname}$`)).click(); cy.get('body').then($b => $b.find('[data-cy="survey"]')).then($s => $s.length && $s.hide()); - cy.getBySel('customize_class_button').click(); + cy.getDataCy('customize_class_button').click(); cy.get("#opening_date_container").should("not.be.visible") cy.get("#opening_date_label").click(); cy.get("#opening_date_container").should("be.visible") diff --git a/tests/cypress/e2e/hedy_page/editor_box.cy.js b/tests/cypress/e2e/hedy_page/editor_box.cy.js index aa2916570b9..695f1910fb8 100644 --- a/tests/cypress/e2e/hedy_page/editor_box.cy.js +++ b/tests/cypress/e2e/hedy_page/editor_box.cy.js @@ -68,7 +68,7 @@ describe('Test editor box functionality', () => { cy.get('#errorbox').should('be.visible'); // The error should be about the lonely echo - cy.getBySel('error_details').should('contain.text', 'echo'); + cy.getDataCy('error_details').should('contain.text', 'echo'); }); it ('When making an error the keywords must be highligted', () => { @@ -78,7 +78,7 @@ describe('Test editor box functionality', () => { cy.get('#errorbox').should('be.visible'); // The error should be about the lonely echo - cy.getBySel('error_details').should('contain.text', 'prin'); + cy.getDataCy('error_details').should('contain.text', 'prin'); cy.get('[data-cy="error_details"] span').should('have.class', 'command-highlighted'); }); diff --git a/tests/cypress/e2e/hedy_page/keyword_language.cy.js b/tests/cypress/e2e/hedy_page/keyword_language.cy.js index f89749ef7db..7e5ca439010 100644 --- a/tests/cypress/e2e/hedy_page/keyword_language.cy.js +++ b/tests/cypress/e2e/hedy_page/keyword_language.cy.js @@ -5,12 +5,12 @@ describe('when the user changes their language to Arabic', () => { goToHedyPageWithEnKeywords(); cy.get('#editor > .cm-editor > .cm-scroller > .cm-content').click(); cy.get('#editor').type("print Hallo!'\n"); - cy.getBySel('language-dropdown').click(); - cy.getBySel('switch-lang-ar').click(); + cy.getDataCy('language-dropdown').click(); + cy.getDataCy('switch-lang-ar').click(); // switch back and forth - cy.getBySel('kwlang-switch-btn').click(); - cy.getBySel('kwlang-switch-toggle').click(); + cy.getDataCy('kwlang-switch-btn').click(); + cy.getDataCy('kwlang-switch-toggle').click(); }); it('initially has keywords in Arabic', () => { @@ -19,8 +19,8 @@ describe('when the user changes their language to Arabic', () => { }); it('the keyword language switcher at the top can switch keywords to English', () => { - cy.getBySel('kwlang-switch-btn').click(); - cy.getBySel('kwlang-switch-toggle').click(); + cy.getDataCy('kwlang-switch-btn').click(); + cy.getDataCy('kwlang-switch-toggle').click(); cy.contains('#editor > .cm-editor > .cm-scroller > .cm-content > .cm-line', 'قول').should('not.exist'); cy.contains('#editor > .cm-editor > .cm-scroller > .cm-content > .cm-line', 'print').should('be.visible'); diff --git a/tests/cypress/e2e/hedy_page/quiz.cy.js b/tests/cypress/e2e/hedy_page/quiz.cy.js index 0e2195e1050..73f4a3269e2 100644 --- a/tests/cypress/e2e/hedy_page/quiz.cy.js +++ b/tests/cypress/e2e/hedy_page/quiz.cy.js @@ -24,14 +24,14 @@ beforeEach(() => { * or click a random answer). */ it('can complete the quiz by randomly clicking buttons', () => { - cy.get('*[data-cy="start-quiz"]').click(); + cy.getDataCy('*start-quiz').click(); randomlyClickThroughUntilFinished(0); // We must use a recursive function to loop, because of the async nature of cypress function randomlyClickThroughUntilFinished(expectedCounter) { // This will wait until the page with the counter value has loaded - cy.get(`input[data-cy="ctr:${expectedCounter}"]`); + cy.getDataCy(`ctr:${expectedCounter}`); // Now that the page has loaded, it's safe to inspect it and do a conditional thing // depending on what it looks like. @@ -43,7 +43,7 @@ it('can complete the quiz by randomly clicking buttons', () => { if ($quizpane.find('*[data-cy="advance-quiz"]').length) { // Click "next question" button" - cy.get('*[data-cy="advance-quiz"]').click(); + cy.getDataCy('*advance-quiz').click(); randomlyClickThroughUntilFinished(expectedCounter + 1); return; } diff --git a/tests/cypress/e2e/hedy_page/run_code_button.cy.js b/tests/cypress/e2e/hedy_page/run_code_button.cy.js index 96cee01462d..61cb6c61272 100644 --- a/tests/cypress/e2e/hedy_page/run_code_button.cy.js +++ b/tests/cypress/e2e/hedy_page/run_code_button.cy.js @@ -53,7 +53,7 @@ describe('Is able to run code', () => { cy.get('#runit').click() cy.wait('@parse') - cy.getBySel('quizmaster').click() + cy.getDataCy('quizmaster').click() const program_2 = "name = ask 'what is your name?'" cy.get('#editor > .cm-editor > .cm-scroller > .cm-content').clear() cy.get('#editor > .cm-editor > .cm-scroller > .cm-content').type(program_2) diff --git a/tests/cypress/e2e/public_adventures/public_adventures.cy.js b/tests/cypress/e2e/public_adventures/public_adventures.cy.js index e383f5a69dd..63aed9d0c4a 100644 --- a/tests/cypress/e2e/public_adventures/public_adventures.cy.js +++ b/tests/cypress/e2e/public_adventures/public_adventures.cy.js @@ -68,20 +68,20 @@ describe("Able to browse all public adventures and use filters", () => { }) it("should be able to clone another teacher's adventure", () => { - cy.getBySel("adventure1").should("have.class", "tab-selected") - cy.getBySel("adventure2") + cy.getDataCy("adventure1").should("have.class", "tab-selected") + cy.getDataCy("adventure2") .click() - cy.getBySel("adventure2").should("have.class", "tab-selected") - cy.getBySel("adventure1").should("not.have.class", "tab-selected") + cy.getDataCy("adventure2").should("have.class", "tab-selected") + cy.getDataCy("adventure1").should("not.have.class", "tab-selected") - cy.getBySel("clone_adventure2") + cy.getDataCy("clone_adventure2") .should("be.visible") .click() cy.reload() - cy.getBySel("adventure2") + cy.getDataCy("adventure2") .click() - cy.getBySel("edit_adventure2").should("be.visible") + cy.getDataCy("edit_adventure2").should("be.visible") }) }); \ No newline at end of file diff --git a/tests/cypress/e2e/public_programs/programs_page.cy.js b/tests/cypress/e2e/public_programs/programs_page.cy.js index d538b23823c..55e3feaaa11 100644 --- a/tests/cypress/e2e/public_programs/programs_page.cy.js +++ b/tests/cypress/e2e/public_programs/programs_page.cy.js @@ -14,11 +14,11 @@ describe("General tests for my programs page (with both custom teacher and built it("create adventure, run its code, and see it in my programs", () => { createAdventure(programName); navigateToClass("CLASS1"); - cy.getBySel("customize_class_button").click(); // Press customize class button - cy.getBySel("available_adventures_current_level").select(`${programName}`); + cy.getDataCy("customize_class_button").click(); // Press customize class button + cy.getDataCy("available_adventures_current_level").select(`${programName}`); // Now preview it and run the program - cy.get('[data-cy="preview_class_link"]') + cy.getDataCy('preview_class_link') .click(); executeHelloWorldProgram(programName) cy.get(".programs").should("contain.text", programName); @@ -29,10 +29,10 @@ describe("General tests for my programs page (with both custom teacher and built it("should not be added to my programs when running a program with copied code", () => { cy.visit(`${Cypress.env('hedy_page')}#${adventure}`); // make sure to navigate to the wanted program tab. - cy.get(`[data-cy="${adventure}"]`) + cy.getDataCy(adventure) .click(); // Paste example code - cy.get(`[data-cy="paste-example-code-${adventure}"]`).click(); + cy.getDataCy(`paste-example-code-${adventure}`).click(); cy.get('#runit').click(); cy.wait(500); cy.visit(`${Cypress.env('programs_page')}`); @@ -42,10 +42,10 @@ describe("General tests for my programs page (with both custom teacher and built it("should be added to my programs when running a program with modified code", () => { cy.visit(`${Cypress.env('hedy_page')}#${adventure}`); // make sure to navigate to the wanted program tab. - cy.get(`[data-cy="${adventure}"]`) + cy.getDataCy(adventure) .click(); // Paste example code and modify code - cy.get(`[data-cy="paste-example-code-${adventure}"`).click(); + cy.getDataCy(`paste-example-code-${adventure}`).click(); cy.get('#editor .cm-content').click(); cy.focused().type('print Hello world\nask Hello world?'); cy.get('#runit').click(); @@ -82,12 +82,12 @@ describe("General tests for my programs page (with both custom teacher and built //favourite a program: cy.get(`#favourite_program_container_${programId}`).click(); cy.get(`#modal-confirm-text`).should('contain.text', 'favourite'); - cy.get('[data-cy="modal_yes_button"]').should('be.enabled').click(); + cy.getDataCy('modal_yes_button').should('be.enabled').click(); //unfavourite a program: cy.wait(500); cy.get(`#favourite_program_container_${programId}`).click(); cy.get(`#modal-confirm-text`).should('contain.text', 'unfavourite'); - cy.get('[data-cy="modal_yes_button"]').should('be.enabled').click(); + cy.getDataCy('modal_yes_button').should('be.enabled').click(); }) }); @@ -110,7 +110,7 @@ describe("General tests for my programs page (with both custom teacher and built .should('not.be.visible'); cy.get(`#more_options_${programId}`).click(); cy.get(`#program_options_dropdown_${programId}`).should("be.visible"); - cy.getBySel(`delete_non_submitted_program_${programId}`).should("not.exist"); + cy.getDataCy(`delete_non_submitted_program_${programId}`).should("not.exist"); }) } }) @@ -138,7 +138,7 @@ describe("General tests for my programs page (with both custom teacher and built .each(($tr, i) => { if ($tr.text().includes("teacher1")) { cy.get(`#second_teachers_container tbody :nth-child(${i+1}) [data-cy="programs"]`).click(); - cy.getBySel("no-programs").should("be.visible"); + cy.getDataCy("no-programs").should("be.visible"); } }) diff --git a/tests/cypress/e2e/signup_page/create_account_button.cy.js b/tests/cypress/e2e/signup_page/create_account_button.cy.js index 992d014d1b0..507837bcba2 100644 --- a/tests/cypress/e2e/signup_page/create_account_button.cy.js +++ b/tests/cypress/e2e/signup_page/create_account_button.cy.js @@ -44,7 +44,7 @@ describe('Username field test', () => { goToProfilePage(); cy.get('#personal_settings').click() cy.get('#delete_profile_button').click() - cy.get('[data-cy="modal_yes_button"]').click() + cy.getDataCy('modal_yes_button').click() }) diff --git a/tests/cypress/e2e/tools/adventures/adventure.js b/tests/cypress/e2e/tools/adventures/adventure.js index 60b8cbecb37..722a8cbf69a 100644 --- a/tests/cypress/e2e/tools/adventures/adventure.js +++ b/tests/cypress/e2e/tools/adventures/adventure.js @@ -34,7 +34,7 @@ export function deleteAdventure(name) { cy.get(`tbody :nth-child(${i+1}) [data-cy="delete-adventure"]`).click(); } }) - cy.get('[data-cy="modal_yes_button"]').should('be.enabled').click(); + cy.getDataCy('modal_yes_button').should('be.enabled').click(); cy.get("#adventures_table") .should("be.visible"); } diff --git a/tests/cypress/e2e/tools/classes/class.js b/tests/cypress/e2e/tools/classes/class.js index 5a271f34ae5..d647b40c18b 100644 --- a/tests/cypress/e2e/tools/classes/class.js +++ b/tests/cypress/e2e/tools/classes/class.js @@ -8,8 +8,8 @@ export function createClass() cy.wait(500); cy.get('#create_class_button').click(); - cy.get('[data-cy="modal_prompt_input"]').type(classname); - cy.get('[data-cy="modal_ok_button"]').click(); + cy.getDataCy('modal_prompt_input').type(classname); + cy.getDataCy('modal_ok_button').click(); goToTeachersPage(); cy.wait(500); @@ -33,7 +33,7 @@ export function ensureClass() let classname = `test class ${Math.random()}`; goToTeachersPage(); - cy.getBySel('view_class_link').then(viewClassLink => { + cy.getDataCy('view_class_link').then(viewClassLink => { if (viewClassLink.length === 0) { createClass(); } else { @@ -50,23 +50,23 @@ export function addStudents(classname, count) { goToTeachersPage(); cy.wait(500); - cy.get('[data-cy="view_class_link"]').then($viewClass => { + cy.getDataCy('view_class_link').then($viewClass => { if (!$viewClass.is(':visible')) { - cy.get('[data-cy="view_classes"]').click(); + cy.getDataCy('view_classes').click(); } }); - cy.get('[data-cy="view_class_link"]').contains(new RegExp(`^${classname}$`)).click(); + cy.getDataCy('view_class_link').contains(new RegExp(`^${classname}$`)).click(); cy.wait(500); cy.get('body').then($b => $b.find('[data-cy="survey"]')).then($s => $s.length && $s.hide()) - cy.get('[data-cy="add_student"]').click(); - cy.get('[data-cy="create_accounts"]').click(); + cy.getDataCy('add_student').click(); + cy.getDataCy('create_accounts').click(); cy.wrap(students).each((student, index) => { cy.get(`:nth-child(${(index + 2)}) > #username`).type(student); cy.get(`:nth-child(${(index + 2)}) > #password`).type('123456'); }) cy.get('#create_accounts_button').click(); - cy.get('[data-cy="modal_yes_button"]').click(); + cy.getDataCy('modal_yes_button').click(); return students; } @@ -75,12 +75,12 @@ export function addCustomizations(classname){ cy.intercept('/for-teachers/customize-class/*').as('updateCustomizations'); goToTeachersPage(); - cy.get('[data-cy="view_class_link"]').then($viewClass => { + cy.getDataCy('view_class_link').then($viewClass => { if (!$viewClass.is(':visible')) { - cy.get('[data-cy="view_classes"]').click(); + cy.getDataCy('view_classes').click(); } }); - cy.get('[data-cy="view_class_link"]').contains(classname).click(); + cy.getDataCy('view_class_link').contains(classname).click(); cy.get('#customize-class-button').click(); cy.get("#opening_date_container").should("not.be.visible") cy.get("#opening_date_label").click(); @@ -102,12 +102,12 @@ export function createClassAndAddStudents(){ export function navigateToClass(classname) { goToTeachersPage(); cy.wait(500); - cy.get('[data-cy="view_class_link"]').then($viewClass => { + cy.getDataCy('view_class_link').then($viewClass => { if (!$viewClass.is(':visible')) { - cy.get('[data-cy="view_classes"]').click(); + cy.getDataCy('view_classes').click(); } }); - cy.get('[data-cy="view_class_link"]').contains(new RegExp(`^${classname}$`)).click(); + cy.getDataCy('view_class_link').contains(new RegExp(`^${classname}$`)).click(); cy.wait(500); cy.get('body').then($b => $b.find('[data-cy="survey"]')).then($s => $s.length && $s.hide()) } diff --git a/tests/cypress/e2e/tools/programs/program.js b/tests/cypress/e2e/tools/programs/program.js index 23f6a157bc6..b652f44ca7f 100644 --- a/tests/cypress/e2e/tools/programs/program.js +++ b/tests/cypress/e2e/tools/programs/program.js @@ -28,9 +28,9 @@ export function deleteProgram(name) { const programId = $el[0].getAttribute("data-id"); cy.get(`#more_options_${programId}`).click(); cy.get(`#more_options_${programId}`).should("be.visible"); - cy.getBySel(`delete_non_submitted_program_${programId}`).click(); - cy.getBySel('modal_yes_button').click(); - cy.wait(500) + cy.getDataCy(`delete_non_submitted_program_${programId}`).click(); + cy.getDataCy('modal_yes_button').click(); + cy.wait(500); }) } }) diff --git a/tests/cypress/support/commands.js b/tests/cypress/support/commands.js index 9a5410cf490..42c762e46ce 100644 --- a/tests/cypress/support/commands.js +++ b/tests/cypress/support/commands.js @@ -24,10 +24,21 @@ // -- This will overwrite an existing command -- // Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) -Cypress.Commands.add('getBySel', (selector, ...args) => { - return cy.get(`[data-cy=${selector}]`, ...args) +Cypress.Commands.add('getDataCy', (selector, ...args) => { + let dataSelector = ""; + const selectors = selector.split(" "); + for (let s of selectors) { + if (s.startsWith("*")) { + s = s.slice(1); + dataSelector += `*[data-cy="${s}"] ` + } else { + dataSelector += `[data-cy="${s}"] ` + } + } + + return cy.get(dataSelector, ...args) }) -Cypress.Commands.add('getBySelLike', (selector, ...args) => { +Cypress.Commands.add('getDataCyLike', (selector, ...args) => { return cy.get(`[data-cy*=${selector}]`, ...args) })