Skip to content

Commit

Permalink
firstPageIsStarted = true breaks TOC navigation fix #6192 (#6235)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov committed May 23, 2023
1 parent 98f4865 commit 4deb164
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/survey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6894,7 +6894,7 @@ export class SurveyModel extends SurveyElementCore
containerLayoutElements.push(layoutElement);
}
}
} else if(!this.isShowingPreview && isStrCiEqual(layoutElement.id, "toc-navigation") && this.showTOC) {
} else if(this.state === "running" && isStrCiEqual(layoutElement.id, "toc-navigation") && this.showTOC) {
if(container === "left") {
if(["left", "both"].indexOf(this.tocLocation) !== -1) {
containerLayoutElements.push(layoutElement);
Expand Down
2 changes: 1 addition & 1 deletion src/surveyToc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function createTOCListModel(survey: SurveyModel) {
}
return tryNavigateToPage(survey, index);
},
visible: <any>new ComputedUpdater(() => page.isVisible)
visible: <any>new ComputedUpdater(() => page.isVisible && !page.isStartPage)
});
});
var listModel = new ListModel(
Expand Down
42 changes: 42 additions & 0 deletions tests/surveyTOCTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,46 @@ QUnit.test("TOC pages visibility", function(assert) {
survey.pages[0].visible = false;
assert.equal(tocListModel.visibleItems.length, 2, "only 2 pages are visible");
assert.equal(tocListModel.visibleItems[0].id, survey.pages[1].name, "Page 1 is invisible, page 2 is the first");
});
QUnit.test("TOC pages visibility, do not include start page into TOC, bug#6192", function(assert) {
let json: any = {
"firstPageIsStarted": true,
"pages": [
{
"name": "page1",
"elements": [
{
"type": "text",
"name": "question1"
}
]
},
{
"name": "page2",
"elements": [
{
"type": "text",
"name": "question2"
}
]
},
{
"name": "page3",
"elements": [
{
"type": "text",
"name": "question3"
}
]
}
]
};
let survey: SurveyModel = new SurveyModel(json);
let tocListModel = createTOCListModel(survey);

assert.equal(tocListModel.visibleItems.length, 2, "First page is not visible");
assert.equal(tocListModel.visibleItems[0].id, survey.pages[1].name, "Page 1 is invisible, page 2 is the first");
survey.firstPageIsStarted = false;
assert.equal(tocListModel.visibleItems.length, 3, "First page is visible");
assert.equal(tocListModel.visibleItems[0].id, survey.pages[0].name, "Page 1 is visible, page 1 is the first");
});
62 changes: 62 additions & 0 deletions tests/surveytests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16582,6 +16582,68 @@ QUnit.test("getContainerContent - do not show TOC on preview", function (assert)
assert.deepEqual(getContainerContent("left"), [], "do not show toc left");
assert.deepEqual(getContainerContent("right"), [], "");
});
QUnit.test("getContainerContent - do not show TOC on start page", function (assert) {
const json = {
showTOC: true,
firstPageIsStarted: true,
pages: [
{
"elements": [
{
"type": "text",
"name": "q1",
},
]
},
{
"elements": [
{
"type": "text",
"name": "q2",
},
]
},
{
"elements": [
{
"type": "text",
"name": "q3",
},
]
}
]
};

let survey = new SurveyModel(json);
function getContainerContent(container: LayoutElementContainer) {
let result = survey.getContainerContent(container);
result.forEach(item => delete item["data"]);
return result;
}

assert.deepEqual(getContainerContent("header"), [], "");
assert.deepEqual(getContainerContent("footer"), [], "");
assert.deepEqual(getContainerContent("contentTop"), [], "");
assert.deepEqual(getContainerContent("contentBottom"), [{
"component": "sv-action-bar",
"id": "navigationbuttons"
}], "");
assert.deepEqual(getContainerContent("left"), [], "empty on the start page");

survey.start();
assert.deepEqual(getContainerContent("header"), [], "");
assert.deepEqual(getContainerContent("footer"), [], "");
assert.deepEqual(getContainerContent("contentTop"), [], "");
assert.deepEqual(getContainerContent("contentBottom"), [{
"component": "sv-action-bar",
"id": "navigationbuttons"
}], "");
assert.deepEqual(getContainerContent("left"), [{
"component": "sv-progress-toc",
"id": "toc-navigation"
}], "show toc left");
assert.deepEqual(getContainerContent("right"), [], "");
});

const structedDataSurveyJSON = {
pages: [
Expand Down

0 comments on commit 4deb164

Please sign in to comment.