Force-remove isRequired property on all survey questions

Resolves MS-910 #complete
This commit is contained in:
Ramon Wenger 2024-04-03 09:45:52 +02:00
parent 37b1b44567
commit 5be12bc7ea
3 changed files with 197 additions and 105 deletions

View File

@ -1,104 +0,0 @@
const module = require('../../fixtures/module.json');
describe('Survey', () => {
beforeEach(() => {
cy.setup();
});
it('should display a matrix correctly', () => {
// todo: fix bitbucket hickup and re-enable
let answer = null;
cy.mockGraphqlOps({
operations: {
MeQuery: {
me: {
permissions: [],
},
},
ModuleQuery: (variables) => ({ module }),
SurveyQuery: () => ({
survey: {
id: 'U3VydmV5Tm9kZTox',
title: 'Test',
data: ` {
"title": "Titel Übung",
"logoPosition": "right",
"pages": [
{
"name": "page1",
"elements": [
{
"type": "matrixdropdown",
"name": "question3",
"title": "Frage",
"columns": [
{
"name": "Column 1",
"title": "Spalte A"
},
{
"name": "Column 2",
"title": "Spalte B"
}
],
"choices": [
"Placeholder"
],
"cellType": "checkbox",
"rows": [
{
"value": "Row 1",
"text": "Zeile 1"
},
{
"value": "Row 2",
"text": "Zeile 2"
},
{
"value": "Row 3",
"text": "Zeile 3"
}
]
}
],
"title": "Titel Seite 1"
}
]
}
`,
module: {
id: 'TW9kdWxlTm9kZToxNw==',
__typename: 'ModuleNode',
},
answer,
__typename: 'SurveyNode',
},
}),
UpdateAnswer: (variables) => {
answer = variables.input.answer;
return {
updateAnswer: {
answer,
__typename: 'UpdateAnswerPayload',
},
};
},
ModuleSolutions: {
module: {
solutionsEnabled: false,
},
},
},
});
cy.visit('/survey/U3VydmV5Tm9kZTox');
cy.get('h1').should('contain', 'Titel Übung');
cy.get('.base-input-container__label').should('not.be.visible');
// cy.get('[value="Speichern & Weiter"]').click();
});
});

View File

@ -0,0 +1,175 @@
const module = require('../../fixtures/module.json');
const defaultData = ` {
"title": "Titel Übung",
"logoPosition": "right",
"pages": [
{
"name": "page1",
"elements": [
{
"type": "matrixdropdown",
"name": "question3",
"title": "Frage",
"columns": [
{
"name": "Column 1",
"title": "Spalte A"
},
{
"name": "Column 2",
"title": "Spalte B"
}
],
"choices": [
"Placeholder"
],
"cellType": "checkbox",
"rows": [
{
"value": "Row 1",
"text": "Zeile 1"
},
{
"value": "Row 2",
"text": "Zeile 2"
},
{
"value": "Row 3",
"text": "Zeile 3"
}
]
}
],
"title": "Titel Seite 1"
}
]
}
`;
const requiredData = `
{
"pages": [
{
"name": "Übung1",
"title": "Diebstahlversicherung",
"elements": [
{
"name": "Name dem Aufgaben",
"type": "panel",
"title": "question title",
"elements": [
{
"name": "question1",
"type": "comment",
"title": "Welche Faktoren sollten die drei bei der Festlegung der Prämienhöhe berücksichtigen? Begründen Sie Ihre Antwort.",
"isRequired": true,
"correctAnswer": "Die Anzahl Versicherter: Je mehr Lernende mitmachen, desto höher ist die Summe der Prämien und desto mehr Geld steht zur Schadenszahlung zur Verfügung. Die Höhe der maximal auszuzahlenden Schadenssumme: Je höher die maximale Schadenssumme ist, desto höher muss die einzelne Prämie angesetzt sein. Die Höhe der maximalen Schadenssumme hängt ihrerseits vom zu erwartenden Schaden ab. Die Nachfrage nach der Versicherung: Je höher die Prämie ist, desto weniger Lernende werden die Versicherung abschliessen.",
"requiredErrorText": "Bitte beantworten Sie die Frage."
},
{
"name": "question2",
"type": "comment",
"title": "Wie hoch würden Sie die Prämie ansetzen? Begründen Sie Ihre Antwort.",
"isRequired": true,
"correctAnswer": "correct answer",
"requiredErrorText": "Bitte beantworten Sie die Frage."
},
{
"name": "question3",
"type": "comment",
"title": "Wie hoch würden Sie die maximale Schadenssumme ansetzen? Begründen Sie Ihre Antwort.",
"isRequired": true,
"correctAnswer": "Individuelle Antworten, etwa: Nimmt man an, jede sechste Person wird einmal im Jahr bestohlen (50 Bestohlene), sollte man die maximale Schadenssumme auf CHF 180. begrenzen. Bei einer Prämie von CHF 30. würden dann Marion, Mats und Ricarda weder einen Gewinn noch einen Verlust machen. Bei zu knapper Kalkulation laufen die drei Versicherungsanbieter Gefahr, Verluste zu machen. Daher müssen sie periodisch die Schäden nach Häufigkeit und Schadensgrösse analysieren.",
"requiredErrorText": "Bitte beantworten Sie die Frage."
}
]
}
]
},
{ "name": "page2" }
],
"title": "Übung ",
"completeText": "Abschliessen",
"pageNextText": "Weiter",
"pagePrevText": "Zurück",
"requiredText": "",
"completedHtml": "<p>Sie haben die Übung abgeschlossen.</p>",
"showProgressBar": "bottom",
"showQuestionNumbers": "off",
"sendResultOnPageNext": true,
"questionErrorLocation": "bottom"
}
`;
const getOperations = (data) => {
let answer = null;
return {
MeQuery: {
me: {
permissions: [],
},
},
ModuleQuery: (_variables) => ({ module }),
SurveyQuery: () => ({
survey: {
id: 'U3VydmV5Tm9kZTox',
title: 'Test',
data,
module: {
id: 'TW9kdWxlTm9kZToxNw==',
__typename: 'ModuleNode',
},
answer,
__typename: 'SurveyNode',
},
}),
UpdateAnswer: (variables) => {
answer = variables.input.answer;
return {
updateAnswer: {
answer,
__typename: 'UpdateAnswerPayload',
},
};
},
ModuleSolutions: {
module: {
solutionsEnabled: false,
},
},
};
};
describe('Survey', () => {
beforeEach(() => {
cy.setup();
cy.mockGraphqlOps({
operations: getOperations(defaultData),
});
});
it('should display a matrix correctly', () => {
// todo: fix bitbucket hickup and re-enable
cy.visit('/survey/U3VydmV5Tm9kZTox');
cy.get('h1').should('contain', 'Titel Übung');
cy.get('.base-input-container__label').should('not.be.visible');
// cy.get('[value="Speichern & Weiter"]').click();
});
it('should be able to continue without filling out required fields', () => {
cy.mockGraphqlOps({
operations: getOperations(requiredData),
});
cy.visit('/survey/U3VydmV5Tm9kZTox');
cy.get('#sv-nav-complete > .sv-action__content > .button').scrollIntoView().click();
cy.get('.survey__panel-title').should('not.exist');
cy.get('.survey__body > p').should('have.text', 'Sie haben die Übung abgeschlossen.');
});
});

View File

@ -17,7 +17,7 @@
</div> </div>
</template> </template>
<script> <script lang="ts">
import '@/styles/survey.modern.css'; import '@/styles/survey.modern.css';
import '@/styles/survey.reset.css'; import '@/styles/survey.reset.css';
import '@/styles/_survey.scss'; import '@/styles/_survey.scss';
@ -239,6 +239,27 @@ export default {
if (survey.answer && survey.answer.data) { if (survey.answer && survey.answer.data) {
answer = JSON.parse(survey.answer.data); answer = JSON.parse(survey.answer.data);
} }
// we now need to traverse all the `pages` and all the `elements` inside them, which themselves have `elements`,
// and we need to delete their `isRequired` keys
json = {
...json,
pages: json.pages.map((page) => {
return {
...page,
elements: page.elements?.map((element) => {
return {
...element,
elements: element.elements?.map((subElement) => {
return {
...subElement,
isRequired: false,
};
}),
};
}),
};
}),
};
if (!this.completed) { if (!this.completed) {
this.survey = this.initSurvey(json, answer); this.survey = this.initSurvey(json, answer);