Skip to content

Commit

Permalink
refactor(cypress): move hard-coded cypress test data to fixtures (#4465)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjschlapbach authored Jan 16, 2025
1 parent eceb988 commit 39e55ec
Show file tree
Hide file tree
Showing 23 changed files with 2,939 additions and 1,996 deletions.
18 changes: 12 additions & 6 deletions cypress/cypress/e2e/A-login-workflow.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import messages from '../../../packages/i18n/messages/en'
import { AvatarOptions } from '../../../packages/shared-components/src/constants'

describe('Login / Logout workflows for lecturer and students', () => {
beforeEach('Load fixture for this test case', function () {
cy.fixture('A-login.json').then((data) => {
this.data = data
})
})

it('signs in into student account', () => {
cy.clearAllCookies()
cy.visit(Cypress.env('URL_STUDENT_LOGIN'))
Expand Down Expand Up @@ -139,9 +145,7 @@ describe('Login / Logout workflows for lecturer and students', () => {
)
})

it('signs in into student account and modifies the password', () => {
const newPassword = 'NEW PASSWORD'

it('signs in into student account and modifies the password', function () {
cy.clearAllCookies()
cy.visit(Cypress.env('URL_STUDENT_LOGIN'))
cy.viewport('macbook-16')
Expand All @@ -155,8 +159,10 @@ describe('Login / Logout workflows for lecturer and students', () => {
// modify password
cy.get('[data-cy="header-avatar"]').click()
cy.get('[data-cy="edit-profile"]').click()
cy.get('[data-cy="update-account-password"]').type(newPassword)
cy.get('[data-cy="update-account-password-repetition"]').type(newPassword)
cy.get('[data-cy="update-account-password"]').type(this.data.newPassword)
cy.get('[data-cy="update-account-password-repetition"]').type(
this.data.newPassword
)
cy.get('[data-cy="save-account-update"]').click()
cy.wait(1000)

Expand All @@ -167,7 +173,7 @@ describe('Login / Logout workflows for lecturer and students', () => {
cy.reload()
cy.get('[data-cy="login-logo"]').should('exist')
cy.get('[data-cy="username-field"]').type(Cypress.env('STUDENT_USERNAME'))
cy.get('[data-cy="password-field"]').type(newPassword)
cy.get('[data-cy="password-field"]').type(this.data.newPassword)
cy.get('[data-cy="submit-login"]').click()
cy.get('[data-cy="homepage"]').should('exist')

Expand Down
6 changes: 6 additions & 0 deletions cypress/cypress/e2e/B-catalyst-workflow.cy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
describe('Tests the avilability of certain functionalities to catalyst users only', () => {
beforeEach('Load fixture for this test case', function () {
cy.fixture('B-catalyst.json').then((data) => {
this.data = data
})
})

it('Test login for catalyst users and non-catalyst users', () => {
cy.loginLecturer()
cy.wait(1000)
Expand Down
41 changes: 20 additions & 21 deletions cypress/cypress/e2e/C-control-workflow.cy.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,41 @@
import { v4 as uuid } from 'uuid'

const questionTitle = uuid()
const question = uuid()
const quizTitle = uuid()
const quiz = uuid()
describe('Test functionalities of frontend-control applicati functionon', function () {
beforeEach('Load fixture for this test case', function () {
cy.fixture('C-control.json').then((data) => {
this.data = data
})
})

describe('Test functionalities of frontend-control application', () => {
it('Create a new SC question to use it in a live quiz', () => {
it('Create a new SC question to use it in a live quiz', function () {
cy.loginLecturer()

// create single choice question for use in test live quiz
cy.createQuestionSC({
title: questionTitle,
content: question,
title: this.data.questionTitle,
content: this.data.questionContent,
choices: [{ content: '50%' }, { content: '100%' }],
})
})

it('Create a new live quiz with the SC question', () => {
it('Create a new live quiz with the SC question', function () {
cy.loginLecturer()

// create live quiz with single choice question
cy.createLiveQuiz({
name: quizTitle,
displayName: quiz,
name: this.data.quizName,
displayName: this.data.quizDisplayName,
blocks: [
{
elements: [questionTitle],
elements: [this.data.questionTitle],
},
],
})

// check if the creation was successful
cy.get('[data-cy="load-live-quiz-list"]').click()
cy.contains('[data-cy="live-quiz-block"]', quizTitle)
cy.contains('[data-cy="live-quiz-block"]', this.data.quizName)
})

it('Generate a token to log into the control-frontend application, execute quiz', () => {
it('Generate a token to log into the control-frontend application, execute quiz', function () {
cy.loginLecturer()

cy.get('[data-cy="user-menu"]').click()
Expand All @@ -55,9 +54,9 @@ describe('Test functionalities of frontend-control application', () => {

// check ppt links and start the quiz
cy.get('[data-cy="unassigned-live-quizzes"]').click()
cy.get(`[data-cy="ppt-link-${quizTitle}"]`).should('exist').click()
cy.get(`[data-cy="ppt-link-${this.data.quizName}"]`).should('exist').click()
cy.get('[data-cy="close-embedding-modal"]').click()
cy.findByText(quizTitle).click()
cy.findByText(this.data.quizName).click()
cy.get('[data-cy="confirm-start-live-quiz"]').click()

// test the mobile menu of the control app
Expand All @@ -66,16 +65,16 @@ describe('Test functionalities of frontend-control application', () => {
cy.get('[data-cy="close-embedding-modal"]').click()
cy.get('[data-cy="home-button"]').click()
cy.get('[data-cy="unassigned-live-quizzes"]').click()
cy.findByText(quizTitle).click()
cy.findByText(this.data.quizName).click()
cy.get('[data-cy="back-button"]').click()
cy.findByText(quizTitle).click()
cy.findByText(this.data.quizName).click()
cy.viewport('macbook-16')

// open and close block, end the quiz
cy.get('[data-cy="activate-next-block"]').click()
cy.get('[data-cy="deactivate-block"]').click()
cy.get('[data-cy="end-live-quiz"]').click()
cy.findByText(quizTitle).should('not.exist')
cy.findByText(this.data.quizName).should('not.exist')
})

// TODO (later): check if quiz is running correctly / add student answer
Expand Down
Loading

0 comments on commit 39e55ec

Please sign in to comment.