Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run cypress tests/watch course test #531

Merged
merged 5 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/cypress-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ jobs:
CYPRESS_badoo_partner_admin_password: ${{secrets.CYPRESS_TEST_ACCOUNT_PASSWORD}}
CYPRESS_super_admin_email: ${{secrets.CYPRESS_SUPER_ADMIN_EMAIL}}
CYPRESS_super_admin_password: ${{secrets.CYPRESS_TEST_ACCOUNT_PASSWORD}}
CYPRESS_public_email: ${{secrets.CYPRESS_PUBLIC_EMAIL}}
swetha-charles marked this conversation as resolved.
Show resolved Hide resolved
CYPRESS_public_password: ${{secrets.CYPRESS_PUBLIC_PASSWORD}}
CYPRESS_api_url: ${{secrets.CYPRESS_BLOOM_BACKEND_API_URL}}
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51 changes: 51 additions & 0 deletions cypress/integration/user-course-session-behaviour.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
describe('A logged in user should be able to navigate to a course session and complete it', () => {
const newUserEmail = `cypresstestemail+${Date.now()}@chayn.co`;
const password = 'testpassword';

before(() => {
cy.cleanUpTestState();

cy.createUser({
//create test user
emailInput: newUserEmail,
passwordInput: password,
});
});

it('Should go to courses page and select a course & session', () => {
cy.logInWithEmailAndPassword(newUserEmail, password); //log in to test user

cy.get(`[qa-id=secondary-nav-courses-button]`).should('exist').click(); //navigate to courses

cy.get('a[href*="healing-from-sexual-trauma"]', {
timeout: 4000,
})
.first()
.click(); //click on a course when link load

// cy.getIframeBody().find('button').click(); Attempting to watch the session video. iframe isnt working at the moment

cy.get('a[href*="what-is-sexual-trauma"]', {
timeout: 4000,
})
.first()
.click(); //click on a session when link loads
});

it('Should read activity & bonus content and complete session', () => {
cy.visit('/courses/healing-from-sexual-trauma/what-is-sexual-trauma');
cy.wait(5000);

cy.get('h3').contains('Activity').click(); //open activities

cy.get('h3').contains('Bonus content').click(); //open bonus content

cy.get('button').contains('Session complete').click(); //mark course as complete

cy.deleteUser(); //delete test user
Zahra-8d marked this conversation as resolved.
Show resolved Hide resolved
});

after(() => {
cy.logout();
});
});
18 changes: 17 additions & 1 deletion cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Cypress.Commands.add('createAccessCode', (accessCode) => {

Cypress.Commands.add('deleteUser', () => {
cy.getAuthEmail().then((email) => {
if (email && email.indexOf('cypress') > 0) {
if (email && email.indexOf('cypress') >= 0) {
cy.getAccessToken().then((token) => {
cy.request({
url: `${Cypress.env('api_url')}/user`,
Expand All @@ -84,6 +84,7 @@ Cypress.Commands.add('deleteUser', () => {
}
});
});

Cypress.Commands.add('createUser', ({ codeInput, emailInput, passwordInput, partnerId }) => {
cy.request({
url: `${Cypress.env('api_url')}/user`,
Expand Down Expand Up @@ -173,6 +174,21 @@ const attachCustomCommands = (Cypress, { auth }) => {
}
});
});

//Function to grab iframe needs some work. At the moment it can't see the inner content.
//This will help with test to watch session videos
Cypress.Commands.add('getIframeBody', () => {
return (
cy
.get('iframe')
.its('0.contentDocument')
.should('exist')
// automatically retries until body is loaded
.its('body')
.should('not.be.undefined')
.then(cy.wrap)
);
});
};

attachCustomCommands(Cypress, firebase);
2 changes: 1 addition & 1 deletion cypress/support/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ declare namespace Cypress {
partnerId?: string;
}): Chainable<Element>;

deleteUser(email: string): Chainable<Element>;
deleteUser(): Chainable<Element>;
deleteAccessCode(): Chainable<Element>;
getAccessCode(): Chainable<Element>;
getAuthEmail(): Chainable<Element>;
Expand Down
Loading