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

Cypress Tests for Multilingual Apps #430

Merged
merged 2 commits into from
Mar 19, 2024
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 cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ module.exports = defineConfig({
testRoarAppsAdministrationId: 'f3UMHUpR8NGLdmACLw9o',
testOptionalRoarAppsAdministration: 'zzzCypressTestOptionalRoarAppsAdministration',
testOptionalRoarAppsAdministrationId: 'E4fPspL3xNZxhL9F1L3m',
testSpanishRoarAppsAdministration: 'zzzCypressTestSpanishRoarAppsAdministration',
testSpanishRoarAppsAdministrationId: 'dOTQdv6ef2dyNgoTzp42',
testUserList: [
'zzzCypressTestStudent0',
'zzzCypressTestStudent1',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { playFluency } from '../../../../support/helper-functions/roam-fluency/fluencyHelpers';

const timeout = Cypress.env('timeout');
const administration = Cypress.env('testSpanishRoarAppsAdministration');
const endText = 'Has terminado.';

describe('Test playthrough of Fluency ARF ES as a participant', () => {
it('Fluency Playthrough Test', () => {
Cypress.on('uncaught:exception', () => {
return false;
});

cy.login(Cypress.env('participantUsername'), Cypress.env('participantPassword'));
cy.visit('/');

cy.selectAdministration(administration);

cy.get('.p-tabview').contains('ROAM - Un Dígito');
cy.visit(`/game/fluency-arf-es`);

// Click jspsych button to begin
cy.get('.jspsych-btn', { timeout: 5 * timeout })
.should('be.visible')
.click();

playFluency(endText);

// Check if game is marked as complete on the dashboard
cy.visit('/');
cy.wait(0.2 * timeout);
cy.selectAdministration(administration);
cy.get('.tabview-nav-link-label').contains('ROAM - Un Dígito').should('exist');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { playFluency } from '../../../../support/helper-functions/roam-fluency/fluencyHelpers';

const timeout = Cypress.env('timeout');
const administration = Cypress.env('testSpanishRoarAppsAdministration');
const endText = 'Has terminado.';

describe('Test playthrough of Fluency ARF ES as a participant', () => {
it('Fluency Playthrough Test', () => {
Cypress.on('uncaught:exception', () => {
return false;
});

cy.login(Cypress.env('participantUsername'), Cypress.env('participantPassword'));
cy.visit('/');

cy.selectAdministration(administration);

cy.get('.p-tabview').contains('ROAM - Varios Dígitos');
cy.visit(`/game/fluency-calf-es`);

// Click jspsych button to begin
cy.get('.jspsych-btn', { timeout: 5 * timeout })
.should('be.visible')
.click();

playFluency(endText);

// Check if game is marked as complete on the dashboard
cy.visit('/');
cy.wait(0.2 * timeout);
cy.selectAdministration(administration);
cy.get('.tabview-nav-link-label').contains('ROAM - Varios Dígitos').should('exist');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { playLetter } from '../../../../support/helper-functions/roar-letter/letterHelpers';

const administration = Cypress.env('testSpanishRoarAppsAdministration');
const language = 'es';
const gameCompleteText = '¡Has terminado! ¡Gracias por ayudarme a encontrar esas letras!';

describe('ROAR - Letra Play Through', () => {
it('Plays Letra', () => {
playLetter(administration, language, gameCompleteText);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { playSRE } from '../../../../support/helper-functions/roar-sre/sreHelpers';

const administration = Cypress.env('testSpanishRoarAppsAdministration');
const language = 'es';

describe('ROAR - Sentence Play Through', () => {
it('Plays SRE', () => {
playSRE(administration, language);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { playSWR } from '../../../../support/helper-functions/roar-swr/swrHelpers.js';

const administration = Cypress.env('testSpanishRoarAppsAdministration');
const language = 'es';

describe('ROAR - Palabra Play Through', () => {
it('Plays Word', () => {
playSWR(administration, language);
});
});
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { optionalGames } from '../../../fixtures/optionalGamesList';

const administration = Cypress.env('testOptionalRoarAppsAdministration');
const language = 'en';

function playOptionalGame(game, administration, optional) {
game.testSpec(administration, optional);
function playOptionalGame(game, administration, language, optional) {
game.testSpec(administration, language, optional);
}

describe('Play Optional Games', () => {
optionalGames.forEach((game) => {
it(`Plays ${game.name}`, () => {
playOptionalGame(game, administration, true);
playOptionalGame(game, administration, language, true);
});
});
});
5 changes: 4 additions & 1 deletion cypress/e2e/participant/default-tests/playSRE.cy.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { playSRE } from '../../../support/helper-functions/roar-sre/sreHelpers';

const administration = Cypress.env('testRoarAppsAdministration');
const language = 'en';

describe('ROAR - Sentence Play Through', () => {
it('Plays SRE', () => {
playSRE(Cypress.env('testRoarAppsAdministration'));
playSRE(administration, language);
});
});
5 changes: 4 additions & 1 deletion cypress/e2e/participant/default-tests/playSWR.cy.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { playSWR } from '../../../support/helper-functions/roar-swr/swrHelpers.js';

const administration = Cypress.env('testRoarAppsAdministration');
const language = 'en';

describe('ROAR - Word Play Through', () => {
it('Plays Word', () => {
playSWR(Cypress.env('testRoarAppsAdministration'));
playSWR(administration, language);
});
});
10 changes: 10 additions & 0 deletions cypress/support/helper-functions/roar-letter/languageOptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const languageOptions = {
en: {
gameTab: 'ROAR - Letter',
url: '/game/letter',
},
es: {
gameTab: 'ROAR - Letra',
url: '/game/letter-es',
},
};
79 changes: 79 additions & 0 deletions cypress/support/helper-functions/roar-letter/letterHelpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { languageOptions } from './languageOptions';

const timeout = Cypress.env('timeout');

function clickButton(selector) {
cy.get(selector).then(($btn) => {
if ($btn.length > 0) {
$btn.click();
}
});
}

function checkGameTab(language) {
cy.get('.p-tabview', { timeout: timeout }).contains(languageOptions[language].gameTab).should('exist');
}

function makeChoiceOrContinue(gameCompleteText) {
cy.wait(0.2 * timeout);
cy.get('body').then((body) => {
const text = body.text().replace(/\s\s+/g, ' ').trim();
cy.log('Found text: ', text);
if (text.includes(gameCompleteText)) {
cy.log('Game is complete.').then(() => true);
} else {
if (body.find('.go-button').length > 0) {
clickButton('.go-button');
} else if (body.find('.glowingButton').length > 0) {
clickButton('.glowingButton');
} else {
clickButton('button:first');
}
cy.log('Making choice or continuing.');
makeChoiceOrContinue(gameCompleteText);
}
});
}

export function startGame(administration, language, optional) {
Cypress.on('uncaught:exception', () => false);
cy.login(Cypress.env('participantUsername'), Cypress.env('participantPassword'));

cy.visit('/', { timeout: 2 * timeout });
cy.selectAdministration(administration);

if (optional) {
cy.switchToOptionalAssessments();
}

checkGameTab(language);
cy.visit(languageOptions[language].url);

cy.get('.jspsych-btn', { timeout: 3 * timeout })
.should('be.visible')
.click();

cy.wait(0.1 * timeout);
Cypress.on('uncaught:exception', () => {
return false;
});

cy.get('.go-button', { timeout: timeout }).should('be.visible').click();
}

export function playLetter(administration, language, gameCompleteText, optional = false) {
startGame(administration, language, optional);
makeChoiceOrContinue(gameCompleteText);
cy.log('Game finished successfully.');

cy.visit('/');
cy.wait(0.2 * timeout);
cy.selectAdministration(administration);

if (optional) {
cy.switchToOptionalAssessments();
}

checkGameTab(language);
cy.log('Test completed successfully.');
}
10 changes: 10 additions & 0 deletions cypress/support/helper-functions/roar-sre/languageOptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const languageOptions = {
en: {
gameTab: 'ROAR - Sentence',
url: '/game/sre',
},
es: {
gameTab: 'ROAR - Frase',
url: '/game/sre-es',
},
};
12 changes: 8 additions & 4 deletions cypress/support/helper-functions/roar-sre/sreHelpers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { languageOptions } from './languageOptions';

const timeout = Cypress.env('timeout');

export const playSRE = (administration, optional = false) => {
export const playSRE = (administration, language, optional = false) => {
Cypress.on('uncaught:exception', () => {
return false;
});
Expand All @@ -13,8 +15,10 @@ export const playSRE = (administration, optional = false) => {
cy.switchToOptionalAssessments();
}

cy.get('.p-tabview').contains('ROAR - Sentence');
cy.visit(`/game/sre`);
cy.get('.p-tabview', { timeout: 2 * timeout })
.contains(languageOptions[language].gameTab)
.should('exist');
cy.visit(languageOptions[language].url);

cy.get('.jspsych-btn', { timeout: 5 * timeout })
.should('be.visible')
Expand All @@ -39,7 +43,7 @@ export const playSRE = (administration, optional = false) => {
cy.switchToOptionalAssessments();
}

cy.get('.tabview-nav-link-label').contains('ROAR - Sentence').should('exist');
cy.get('.tabview-nav-link-label').contains(languageOptions[language].gameTab).should('exist');
};

function playSREGame() {
Expand Down
28 changes: 28 additions & 0 deletions cypress/support/helper-functions/roar-swr/languageOptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export const languageOptions = {
en: {
gameTab: 'ROAR - Word',
url: '/game/swr',
continue: 'Continue',
introText: 'Welcome to the world of Lexicality!',
blockTerminationPhraseOne: 'You are halfway through the first block',
blockTerminationPhraseTwo: 'You have completed the first block',
blockTerminationPhraseThree: 'You are halfway through the second block',
blockTerminationPhraseFour: 'You have completed the second block',
blockTerminationPhraseFive: 'You are halfway through the third block',
blockTerminationPhraseSix:
'You say farewell to your new friends and leave the land of Lexicality. Until next time!',
},
es: {
gameTab: 'ROAR - Palabra',
url: '/game/swr-es',
continue: 'Continuar',
introText: '¡Bienvenidos al mundo de Lexicalidad!',
blockTerminationPhraseOne: 'Estás a la mitad del primer bloque.',
blockTerminationPhraseTwo: 'Has completado el primer bloque.',
blockTerminationPhraseThree: 'Estás a la mitad del segundo bloque.',
blockTerminationPhraseFour: 'Has completado el segundo bloque',
blockTerminationPhraseFive: 'Estás a la mitad del tercer bloque',
blockTerminationPhraseSix:
'Te despides de tus nuevos amigos y dejas la tierra de Lexicalidad. ¡Hasta una próxima ocasión!',
},
};
Loading
Loading