Skip to content

Commit

Permalink
#2525 Fix issue with copy modal, description, add cypress tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dwalizer committed Oct 16, 2024
1 parent 57813f5 commit da59980
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 1 deletion.
2 changes: 2 additions & 0 deletions dashboard/src/components/quiz/QuizDefinitions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,13 @@ function deleteQuiz() {
const showUpdateModal = (quizDef, isEdit = true) => {
editQuizInfo.value.quizDef = quizDef;
editQuizInfo.value.isEdit = isEdit;
editQuizInfo.value.isCopy = false;
editQuizInfo.value.showDialog = true;
};
const showCopyModal = (quizDef, isCopy = true) => {
editQuizInfo.value.quizDef = quizDef;
editQuizInfo.value.isCopy = isCopy;
editQuizInfo.value.isEdit = false;
editQuizInfo.value.showDialog = true;
};
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/components/quiz/testCreation/EditQuiz.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const schema = object({
const asyncLoadData = () => {
const loadDescription = () => {
if(props.isEdit) {
if(props.isEdit || props.isCopy) {
return QuizService.getQuizDef(props.quiz.quizId).then((data) => {
initialQuizData.value.description = data.description ? data.description : ''
initialQuizData.value = { ...initialQuizData.value }
Expand Down
116 changes: 116 additions & 0 deletions e2e-tests/cypress/e2e/quiz/quiz_creation_and_management_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,5 +563,121 @@ describe('Quiz CRUD Tests', () => {
], 5);
});

it('copy an empty quiz and an empty survey', function () {
cy.createQuizDef(1, { name: 'Quiz 1' });
cy.createSurveyDef(2, { name: 'Survey 1' });

cy.visit('/administrator/quizzes/')

cy.get('[data-cy="copyQuizButton_quiz1"]').click()
cy.get('[data-cy="quizName"]').should('have.value', 'Copy of Quiz 1')

cy.get('[data-cy="saveDialogBtn"]').click()

cy.validateTable(quizTableSelector, [
[{ colIndex: 0, value: 'Quiz 1' }, { colIndex: 1, value: 'Quiz' }],
[{ colIndex: 0, value: 'Survey 1' }, { colIndex: 1, value: 'Survey' }],
[{ colIndex: 0, value: 'Copy of Quiz 1' }, { colIndex: 1, value: 'Quiz' }],
], 5);

cy.get('[data-cy="copyQuizButton_quiz2"]').click()
cy.get('[data-cy="quizName"]').should('have.value', 'Copy of Survey 1')

cy.get('[data-cy="saveDialogBtn"]').click()

cy.validateTable(quizTableSelector, [
[{ colIndex: 0, value: 'Quiz 1' }, { colIndex: 1, value: 'Quiz' }],
[{ colIndex: 0, value: 'Survey 1' }, { colIndex: 1, value: 'Survey' }],
[{ colIndex: 0, value: 'Copy of Quiz 1' }, { colIndex: 1, value: 'Quiz' }],
[{ colIndex: 0, value: 'Copy of Survey 1' }, { colIndex: 1, value: 'Survey' }],
], 5);
});

it('copy a quiz and a survey with questions', function () {
cy.createQuizDef(1, { name: 'Quiz 1' });
cy.createSurveyDef(2, { name: 'Survey 1' });

cy.createQuizQuestionDef(1, 1);
cy.createQuizQuestionDef(1, 2);
cy.createSurveyMultipleChoiceQuestionDef(2, 1);
cy.createTextInputQuestionDef(2, 2);
cy.createRatingQuestionDef(2, 3);

cy.visit('/administrator/quizzes/')

cy.get('[data-cy="copyQuizButton_quiz1"]').click()
cy.get('[data-cy="quizName"]').should('have.value', 'Copy of Quiz 1')

cy.get('[data-cy="saveDialogBtn"]').click()

cy.validateTable(quizTableSelector, [
[{ colIndex: 0, value: 'Quiz 1' }, { colIndex: 1, value: 'Quiz' }],
[{ colIndex: 0, value: 'Survey 1' }, { colIndex: 1, value: 'Survey' }],
[{ colIndex: 0, value: 'Copy of Quiz 1' }, { colIndex: 1, value: 'Quiz' }],
], 5);

cy.get('[data-cy="copyQuizButton_quiz2"]').click()
cy.get('[data-cy="quizName"]').should('have.value', 'Copy of Survey 1')

cy.get('[data-cy="saveDialogBtn"]').click()

cy.validateTable(quizTableSelector, [
[{ colIndex: 0, value: 'Quiz 1' }, { colIndex: 1, value: 'Quiz' }],
[{ colIndex: 0, value: 'Survey 1' }, { colIndex: 1, value: 'Survey' }],
[{ colIndex: 0, value: 'Copy of Quiz 1' }, { colIndex: 1, value: 'Quiz' }],
[{ colIndex: 0, value: 'Copy of Survey 1' }, { colIndex: 1, value: 'Survey' }],
], 5);

cy.get('[data-cy="managesQuizLink_Copyofquiz1"]').click()
cy.get('[data-cy="questionDisplayCard-1"]').contains('This is a question # 1')
cy.get('[data-cy="questionDisplayCard-2"]').contains('This is a question # 2')

cy.visit('/administrator/quizzes/')
cy.get('[data-cy="managesQuizLink_Copyofquiz2"]').click()

cy.get('[data-cy="questionDisplayCard-1"]').contains('This is a question # 1')
cy.get('[data-cy="questionDisplayCard-2"]').contains('This is a question # 2')
cy.get('[data-cy="questionDisplayCard-3"]').contains('This is a question # 3')
cy.get('[data-cy="questionDisplayCard-2"] [data-cy="textAreaPlaceHolder"]').should('exist')
cy.get('[data-cy="questionDisplayCard-3"] [data-pc-name="rating"]').should('exist')

});

it('copy a quiz and a survey with settings', function () {
cy.createQuizDef(1, { name: 'Quiz 1' });
cy.createSurveyDef(2, { name: 'Survey 1' });

cy.setQuizMaxNumAttempts(1, 3);
cy.setQuizMultipleTakes(1, true);
cy.setQuizShowCorrectAnswers(1, true);

cy.setQuizMultipleTakes(2, true);

cy.visit('/administrator/quizzes/')

cy.get('[data-cy="copyQuizButton_quiz1"]').click()
cy.get('[data-cy="quizName"]').should('have.value', 'Copy of Quiz 1')
cy.get('[data-cy="saveDialogBtn"]').click()

cy.get('[data-cy="copyQuizButton_quiz2"]').click()
cy.get('[data-cy="quizName"]').should('have.value', 'Copy of Survey 1')
cy.get('[data-cy="saveDialogBtn"]').click()

cy.validateTable(quizTableSelector, [
[{ colIndex: 0, value: 'Quiz 1' }, { colIndex: 1, value: 'Quiz' }],
[{ colIndex: 0, value: 'Survey 1' }, { colIndex: 1, value: 'Survey' }],
[{ colIndex: 0, value: 'Copy of Quiz 1' }, { colIndex: 1, value: 'Quiz' }],
[{ colIndex: 0, value: 'Copy of Survey 1' }, { colIndex: 1, value: 'Survey' }],
], 5);

cy.visit('/administrator/quizzes/Copyofquiz1/settings')
cy.get('[data-cy="numAttemptsInput"] input').should('have.value', 3);
cy.get('[data-cy="multipleTakesSwitch"] input').should('be.checked');
cy.get('[data-cy="alwaysShowCorrectAnswersSwitch"] input').should('be.checked');

cy.visit('/administrator/quizzes/Copyofquiz2/settings')
cy.get('[data-cy="multipleTakesSwitch"] input').should('be.checked');

});
});

0 comments on commit da59980

Please sign in to comment.