Skip to content

Commit

Permalink
Fixed TOC corrupted page title
Browse files Browse the repository at this point in the history
  • Loading branch information
tsv2013 committed Sep 19, 2023
1 parent 7595bad commit 0f7f44b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/surveyToc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function createTOCListModel(survey: SurveyModel, onAction?: () => void) {
var items = (pagesSource || []).map(page => {
return new Action({
id: page.name,
locTitle: page.locTitle?.text ? page.locTitle : ((page as PageModel).locNavigationTitle?.text ? (page as PageModel).locNavigationTitle : undefined),
locTitle: (page as PageModel).locNavigationTitle?.text ? (page as PageModel).locNavigationTitle : (page.locTitle?.text ? page.locTitle : undefined),
title: page.renderedNavigationTitle,
action: () => {
if (typeof document !== undefined && !!document.activeElement) {
Expand Down
31 changes: 31 additions & 0 deletions tests/surveyTOCTests.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Action } from "../src/actions/action";
import { PageModel } from "../src/page";
import { SurveyModel } from "../src/survey";
import { createTOCListModel, getTocRootCss } from "../src/surveyToc";

Expand Down Expand Up @@ -274,4 +276,33 @@ QUnit.test("TOC respects markup", function (assert) {
// TODO - eliminate duplicated call
assert.equal(tocListModel.visibleItems[1].locTitle.textOrHtml, "markup markup Text with <em>emphasys text</em>", "Page 2 - nav title");
assert.equal(tocListModel.visibleItems[2].locTitle.textOrHtml, "markup page3", "Page 3");
});

QUnit.test("TOC shouldn't affect page title", function (assert) {
let json: any = {
"pages": [
{
"name": "page1",
"title": "Page 1 title",
"navigationTitle": "Text with <em>emphasys text</em>",
"elements": [
{
"type": "text",
"name": "question2"
}
]
},
]
};
const survey: SurveyModel = new SurveyModel(json);

const page = survey.pages[0];
assert.equal(page.locTitle.textOrHtml, "Page 1 title", "Page 1 title");
assert.equal(page.locNavigationTitle.textOrHtml, "Text with <em>emphasys text</em>", "Page 1 - nav title");

const tocListModel = createTOCListModel(survey);
assert.equal(page.locNavigationTitle.textOrHtml, "Text with <em>emphasys text</em>", "Page 1 - nav title");
assert.equal(tocListModel.visibleItems.length, 1, "2 items is TOC");
assert.equal(tocListModel.visibleItems[0].locTitle.textOrHtml, "Text with <em>emphasys text</em>", "Page 1 - nav title in TOC");
assert.equal(page.locTitle.textOrHtml, "Page 1 title", "Page 1 title");
});

0 comments on commit 0f7f44b

Please sign in to comment.