-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3089 from ONSdigital/EAR-2296-fix-collection-list…
…s-with-introduction EAR-2296 and EAR-2299 fix collection lists without introduction page
- Loading branch information
Showing
4 changed files
with
119 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
}); | ||
}); |