forked from hedyorg/hedy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TESTING] Adding new tests to customize class page (hedyorg#3972)
**Description** Recently, the customize class page has gone through a lot of changes, and ever since a handful of bugs emerged. In order to prevent this from happening in the future, this PR adds a handful of tests for the following behaviors: * Clicking the 'go back' button. * Clicking the 'save' and 'remove customizations' buttons * Reordering the adventures through drags and drops. * Deleting an adventure and adding it again. * Switching through levels. Also, minor changes: * A debug print was removed. * Added ids to some buttons in order to query them more easily in the tests.
- Loading branch information
Showing
10 changed files
with
232 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
206 changes: 206 additions & 0 deletions
206
tests/cypress/e2e/for-teacher_page/customize_class_page/customize_class.cy.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
import {loginForTeacher} from '../../tools/login/login.js' | ||
import { createClass } from "../../tools/classes/class"; | ||
|
||
describe('customize class page', () => { | ||
beforeEach(() => { | ||
loginForTeacher(); | ||
createClass(); | ||
cy.getBySel('view_class_link').first().click(); // Press on view class button | ||
cy.getBySel('customize_class_button').click(); // Press customize class button | ||
}); | ||
|
||
it('checks the option checkboxes', () => { | ||
// following code checks every single checkbox on the current page: | ||
cy.get('[type="checkbox"]').check({force:true}) | ||
cy.get('[type="checkbox"]').should('be.checked') | ||
cy.get('[type="checkbox"]').uncheck() | ||
cy.get('[type="checkbox"]').should('be.not.checked') | ||
}); | ||
|
||
it('goes back to the view class page', () => { | ||
cy.getBySel('back_to_class') | ||
.should('be.visible') | ||
.should('not.be.disabled') | ||
.click(); | ||
// We should be in the view class page | ||
cy.url() | ||
.should('include', Cypress.config('baseUrl') + Cypress.env('class_page')); | ||
}); | ||
|
||
it('the adventure dragger is hidden and the level dropdown changes which adventures are displayed', () => { | ||
// Click on level 1 | ||
cy.getBySel('adventures') | ||
.select('1') | ||
.should('have.value', '1'); | ||
|
||
// level 1 should be visible and level 2 not | ||
cy.getBySel("level-1") | ||
.should('be.visible'); | ||
|
||
cy.getBySel("level-2") | ||
.should('not.be.visible'); | ||
|
||
// after selecting level 2 it should be visible and level 1 not | ||
cy.getBySel('adventures') | ||
.select('2') | ||
.should('have.value', '2'); | ||
|
||
cy.getBySel("level-1") | ||
.should('not.be.visible'); | ||
|
||
cy.getBySel("level-2") | ||
.should('be.visible'); | ||
}); | ||
|
||
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") | ||
// 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).type("2023-01-01").should("not.be.empty"); | ||
}); | ||
}); | ||
|
||
it('the quiz score holds the value typed to it', () => { | ||
// testing quiz score feature | ||
cy.getBySel('quiz_input').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', () => { | ||
|
||
cy.getBySel('sortadventures') | ||
.children() | ||
.should('not.be.visible'); | ||
|
||
// Click on level 2 | ||
cy.getBySel("adventures") | ||
.select('2') | ||
.should('have.value', '2'); | ||
|
||
// The available adventures dropdown should only include the default option | ||
cy.getBySel("available_adventures_current_level") | ||
.children() | ||
.should('have.length', 1) | ||
|
||
// store the name of the adventure we're going to delete | ||
cy.get('[data-cy="level-2"] div:first') | ||
.invoke('attr', 'adventure') | ||
.as('adventure') | ||
.then(adventure => { | ||
// Get the first adventure, and click its remove button | ||
cy.get('[data-cy="level-2"] div:first span') | ||
.click(); | ||
|
||
// The available adventures dropdown should now include the new adventure | ||
cy.getBySel("available_adventures_current_level") | ||
.children() | ||
.should('have.length', 2); | ||
|
||
// the added option should be the last | ||
cy.get('[data-cy="available_adventures_current_level"] option:last') | ||
.should('have.id', `remove-${adventure}`); | ||
|
||
// after selecting the adventure, it shouldn't be among the options | ||
cy.getBySel("available_adventures_current_level") | ||
.select(1) | ||
.children() | ||
.should('have.length', 1); | ||
|
||
// the adventure should now be last | ||
cy.get('[data-cy="level-2"] div:last') | ||
.should('have.attr', 'adventure') | ||
.and('eq', adventure); | ||
}); | ||
}); | ||
|
||
it('saves the customizations and then removes them, checking that the remove button hides accordingly', () => { | ||
// Since this class is new it shouldn't have customizations | ||
cy.getBySel('remove_customizations_button') | ||
.should('not.be.visible'); | ||
|
||
// We save the customizations first | ||
cy.getBySel("save_customizations") | ||
.should('be.visible') | ||
.should('not.be.disabled') | ||
.click(); | ||
|
||
cy.getBySel('modal_alert_text') | ||
.should('be.visible'); | ||
|
||
// Now that it has customizations we can remove them | ||
cy.getBySel('remove_customizations_button') | ||
.should('be.visible') | ||
.should('not.be.disabled') | ||
.click(); | ||
|
||
cy.getBySel('modal_yes_button') | ||
.should('be.visible') | ||
.click(); | ||
|
||
// It shouldn't have the button again | ||
cy.getBySel('remove_customizations_button') | ||
.should('not.be.visible'); | ||
}); | ||
|
||
it('selects two adventures and swaps them using drag and drop', () => { | ||
cy.getBySel('sortadventures') | ||
.children() | ||
.should('not.be.visible'); | ||
|
||
// Click on level 1 | ||
cy.getBySel("adventures") | ||
.select('1') | ||
.should('have.value', '1'); | ||
|
||
// Now it should be visible | ||
cy.getBySel('level-1').should('be.visible'); | ||
|
||
// Get the first and second adventure | ||
cy.getBySel('level-1') | ||
.children() | ||
.eq(0) | ||
.invoke('attr', 'adventure') | ||
.as('first_adventure'); | ||
|
||
cy.getBySel('level-1') | ||
.children() | ||
.eq(1) | ||
.invoke('attr', 'adventure') | ||
.as('second_adventure'); | ||
|
||
// Getting their values first, and then moving them around | ||
cy.get('@first_adventure').then(first_adventure => { | ||
cy.get('@second_adventure').then(second_adventure => { | ||
|
||
// Move the second adventure to the first place | ||
cy.getBySel('level-1') | ||
.children() | ||
.eq(1) | ||
.trigger('dragstart') | ||
.siblings() | ||
.should('have.attr', 'class') | ||
.and('contain', 'drop-adventures-hint'); | ||
|
||
cy.getBySel('level-1') | ||
.children() | ||
.eq(0) | ||
.trigger('drop') | ||
.trigger('dragend'); | ||
|
||
// they should be inverted now | ||
cy.getBySel('level-1') | ||
.children() | ||
.eq(0) | ||
.should('have.attr', 'adventure') | ||
.and('eq', second_adventure); | ||
|
||
cy.getBySel('level-1') | ||
.children() | ||
.eq(1) | ||
.should('have.attr', 'adventure') | ||
.and('eq', first_adventure); | ||
}) | ||
}) | ||
}); | ||
}); |
26 changes: 0 additions & 26 deletions
26
tests/cypress/e2e/for-teacher_page/customize_class_page/opening_dates.cy.js
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
tests/cypress/e2e/for-teacher_page/customize_class_page/quiz_score.cy.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.