Skip to content

Commit

Permalink
Merge pull request #3089 from ONSdigital/EAR-2296-fix-collection-list…
Browse files Browse the repository at this point in the history
…s-with-introduction

EAR-2296 and EAR-2299 fix collection lists without introduction page
  • Loading branch information
Farhanam76 authored Jan 17, 2024
2 parents 8176a2c + 536699b commit 66ff27a
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 4 deletions.
6 changes: 4 additions & 2 deletions eq-author-api/src/businessLogic/createList.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const { v4: uuidv4 } = require("uuid");

const createList = (ctx) => {
ctx.questionnaire.introduction.previewQuestions = false;
ctx.questionnaire.introduction.disallowPreviewQuestions = true;
if (ctx.questionnaire.introduction) {
ctx.questionnaire.introduction.previewQuestions = false;
ctx.questionnaire.introduction.disallowPreviewQuestions = true;
}
return {
id: uuidv4(),
listName: null,
Expand Down
38 changes: 38 additions & 0 deletions eq-author-api/src/businessLogic/createList.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const createList = require("./createList");

describe("createList", () => {
let ctx;
beforeEach(() => {
ctx = {
questionnaire: {
id: "questionnaire-1",
introduction: {
id: "introduction-1",
title: "introduction 1",
previewQuestions: true,
disallowPreviewQuestions: false,
},
collectionLists: {
id: "collection-list",
lists: [
{
id: "list-1",
ListName: "list 1",
answers: [],
},
],
},
},
};
});

it("Should change the introduction's disallowPreviewQuestion to true when collection list is created", () => {
createList(ctx);
expect(ctx.questionnaire.introduction.disallowPreviewQuestions).toBe(true);
});

it("Should change the introduction's previewQuestions to false when the collection list is created", () => {
createList(ctx);
expect(ctx.questionnaire.introduction.previewQuestions).toBe(false);
});
});
5 changes: 3 additions & 2 deletions eq-author-api/src/businessLogic/onListDeleted.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ module.exports = (ctx, list) => {
}

if (
ctx.questionnaire.lists === undefined ||
ctx.questionnaire.lists.length === 0
ctx.questionnaire.introduction &&
(ctx.questionnaire.lists === undefined ||
ctx.questionnaire.collectionLists.lists.length === 0)
) {
ctx.questionnaire.introduction.disallowPreviewQuestions = false;
}
Expand Down
74 changes: 74 additions & 0 deletions eq-author-api/src/businessLogic/onListDeleted.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
const onListDeleted = require("./onListDeleted");
const onAnswerDeleted = require("./onAnswerDeleted");

jest.mock("./onAnswerDeleted");

describe("onListDeleted", () => {
let ctx;
const list = {
id: "id-1",
answers: [{ id: "answer-1", type: "TextField" }],
};
beforeEach(() => {
ctx = {
questionnaire: {
id: "questionnaire-1",
introduction: {
id: "introduction-1",
title: "introduction 1",
disallowPreviewQuestions: true,
},
collectionLists: {
id: "collectionList-1",
lists: [list],
},
sections: [
{
repeatingSectionListId: "id-1",
folders: [{ pages: [{}] }],
},
],
},
};
});

afterEach(() => {
onAnswerDeleted.mockClear();
});

it("should change the section's page.listId to null when it is the same as the list's id", () => {
ctx.questionnaire.sections[0].folders[0].pages[0] = {
id: "page-1",
listId: "id-1",
};
onListDeleted(ctx, list);
expect(ctx.questionnaire.sections[0].folders[0].pages[0].listId).toBeNull();
});

it("should change the introduction's disallowPreviewQuestion to false when there is no collection lists", () => {
onListDeleted(ctx, {});

expect(ctx.questionnaire.introduction.disallowPreviewQuestions).toBe(false);
});

it("should change the section's repeatingSectionListId to null when it is the same as the list's id", () => {
onListDeleted(ctx, list);
expect(ctx.questionnaire.sections[0].repeatingSectionListId).toBeNull();
});

it("should call onAnswerDeleted when list with answers is deleted", () => {
onListDeleted(ctx, list);
expect(ctx.questionnaire.sections[0].repeatingSectionListId).toBeNull();
});

it("should call onAnswerDeleted when list has answers", () => {
onListDeleted(ctx, list);
expect(onAnswerDeleted).toHaveBeenCalledTimes(1);
expect(onAnswerDeleted).toHaveBeenCalledWith(
ctx,
list,
list.answers[0],
ctx.questionnaire.sections[0].folders[0].pages
);
});
});

0 comments on commit 66ff27a

Please sign in to comment.