Skip to content

Commit

Permalink
Fix: Started page is not rendered in react in versions: v1.8.66-67 in…
Browse files Browse the repository at this point in the history
… react #3348
  • Loading branch information
andrewtelnov committed Sep 18, 2021
1 parent e713d57 commit e5f2b92
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 9 deletions.
7 changes: 1 addition & 6 deletions src/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,7 @@ export class PageModel extends PanelModelBase implements IPage {
.append(this.cssClasses.page.title)
.toString();
}

getIsPageVisible(exceptionQuestion: IQuestion): boolean {
if (this.isStarted) return false;
return super.getIsPageVisible(exceptionQuestion);
}
public get num() {
public get num(): number {
return this.getPropertyValue("num", -1);
}
public set num(val: number) {
Expand Down
2 changes: 1 addition & 1 deletion src/survey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2458,7 +2458,7 @@ export class SurveyModel extends SurveyElementCore
if (this.isDesignMode) return this.pages;
var result = new Array<PageModel>();
for (var i = 0; i < this.pages.length; i++) {
if (this.pages[i].isVisible) {
if (this.pages[i].isVisible && !this.pages[i].isStarted) {
result.push(this.pages[i]);
}
}
Expand Down
36 changes: 36 additions & 0 deletions testCafe/survey/startedPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { frameworks, url, initSurvey, getSurveyResult } from "../helper";
import { Selector } from "testcafe";
const assert = require("assert");
const title = `First Page is Started`;

const json = {
pages: [
{ elements: [{ type: "text", name: "name" }] },
{
elements: [
{ type: "text", name: "address" },
],
}
],
firstPageIsStarted: true
};

frameworks.forEach((framework) => {
fixture`${framework} ${title}`.page`${url}${framework}`.beforeEach(
async (t) => {
await initSurvey(framework, json);
}
);

test(`Enter data on first question`, async (t) => {
await t.typeText(Selector(`input[type=text]`), "Jon Snow");
await t.click(`input[value=Start]`);
await t.typeText(Selector(`input[type=text]`), "Winterfell");
await t.click(`input[value=Complete]`);
const surveyResult = await getSurveyResult();
assert.deepEqual(surveyResult, {
name: "Jon Snow",
address: "Winterfell"
});
});
});
32 changes: 30 additions & 2 deletions tests/surveytests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6055,7 +6055,8 @@ QUnit.test("firstPageIsStarted = true", function (assert) {
assert.equal(survey.pages[0].isVisible, true, "The first page is visible");
assert.equal(survey.state, "running", "Survey is running");
survey.firstPageIsStarted = true;
assert.equal(survey.pages[0].isVisible, false, "The first page is invisible");
assert.equal(survey.pages[0].isVisible, true, "The first page is visible");
assert.equal(survey.pages[0].isStarted, true, "The first page is started");
assert.equal(survey.visiblePages.length, 2, "There are 2 visible pages");
assert.equal(survey.state, "starting", "Survey is showing the start page");
survey.firstPageIsStarted = false;
Expand All @@ -6080,7 +6081,8 @@ QUnit.test("firstPageIsStarted = true, load from JSON, the flow", function (
survey.onStarted.add(function (sender) {
startCounter++;
});
assert.equal(survey.pages[0].isVisible, false, "The first page is invisible");
assert.equal(survey.pages[0].isVisible, true, "The first page is visible");
assert.equal(survey.pages[0].isStarted, true, "The first page is visible");
assert.equal(survey.visiblePages.length, 1, "There is one visible page");
assert.equal(survey.state, "starting", "Survey is showing the start page");
assert.equal(startCounter, 0, "onStarted event was not called yet");
Expand Down Expand Up @@ -13949,3 +13951,29 @@ QUnit.test("page.fromJSON() doesn't work correctly, Bug#3331", assert => {
const question = <QuestionCheckboxModel>survey.getAllQuestions()[0];
assert.equal(question.visibleChoices.length, 3, "Visible choices are set");
});
QUnit.test("start page is invisible", assert => {
const survey = new SurveyModel({
pages: [
{
elements: [
{
type: "text",
name: "name1",
},
],
},
{
elements: [
{
type: "text",
name: "name2",
},
],
},
],
firstPageIsStarted: true,
});
const startedPage = survey.startedPage;
assert.ok(startedPage);
assert.equal(startedPage.isVisible, true, "started page is visible");
});

0 comments on commit e5f2b92

Please sign in to comment.