Skip to content

Commit 91742bb

Browse files
authored
When firstPageIsStartPage is enabled, the page navigator in the Previ… (#6640)
* When firstPageIsStartPage is enabled, the page navigator in the Preview tab behaves weird fix #6624 * Remove import
1 parent 5afa3f7 commit 91742bb

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

packages/survey-creator-core/src/components/tabs/preview.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,10 @@ export class PreviewViewModel extends Base {
224224
this.updatePageList();
225225
this.show();
226226
}
227-
227+
private isSurveyRunning(): boolean {
228+
const state = this.survey?.state;
229+
return state === "running" || state === "starting";
230+
}
228231
public buildActions() {
229232
const pageActions: Array<Action> = [];
230233
const setNearPage: (isNext: boolean) => void = (isNext: boolean) => {
@@ -246,7 +249,7 @@ export class PreviewViewModel extends Base {
246249

247250
if (this.prevPageAction) {
248251
this.prevPageAction.visible = <any>new ComputedUpdater<boolean>(() => {
249-
const isRunning = this.survey.state === "running";
252+
const isRunning = this.isSurveyRunning();
250253
const isActiveTab = this.getTabName() === this.surveyProvider.activeTab;
251254
return notShortCircuitAnd(this.isRunning, isActiveTab, this.pageListItems.length > 1) && isRunning;
252255
});
@@ -279,11 +282,11 @@ export class PreviewViewModel extends Base {
279282
});
280283
pageActions.push(this.selectPageAction);
281284
this.selectPageAction.visible = <any>new ComputedUpdater<boolean>(() => {
282-
return this.survey.state === "running";
285+
return this.isSurveyRunning();
283286
});
284287
if (this.nextPageAction) {
285288
this.nextPageAction.visible = <any>new ComputedUpdater<boolean>(() => {
286-
const isRunning = this.survey.state === "running";
289+
const isRunning = this.isSurveyRunning();
287290
const isActiveTab = this.getTabName() === this.surveyProvider.activeTab;
288291
return notShortCircuitAnd(this.isRunning, isActiveTab, this.pageListItems.length > 1) && isRunning;
289292
});

packages/survey-creator-core/tests/tabs/test.tests.ts

+24
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,30 @@ test("Prev/Next actions enabled/disabled", (): any => {
695695
expect(model.prevPageAction.enabled).toBeTruthy();
696696
expect(model.nextPageAction.enabled).toBeFalsy();
697697
});
698+
test("isPageToolbarVisible & firstPage is started, #6624", (): any => {
699+
const creator: CreatorTester = new CreatorTester();
700+
creator.JSON = {
701+
pages: [
702+
{ elements: [{ type: "text", name: "q1" }] },
703+
{ elements: [{ type: "text", name: "q2" }] },
704+
{ elements: [{ type: "text", name: "q3" }] }
705+
],
706+
firstPageIsStartPage: true
707+
};
708+
const testPlugin: TabTestPlugin = <TabTestPlugin>creator.getPlugin("test");
709+
testPlugin.activate();
710+
const model: TestSurveyTabViewModel = testPlugin.model;
711+
expect(model.pageListItems).toHaveLength(3);
712+
expect(model.survey.state).toBe("starting");
713+
expect(model.isPageToolbarVisible).toBeTruthy();
714+
expect(model.nextPageAction.enabled).toBeTruthy();
715+
expect(model.prevPageAction.enabled).toBeFalsy();
716+
(<any>model.selectPageAction.popupModel).onSelectionChanged(model.pageListItems[1]);
717+
expect(model.survey.state).toBe("running");
718+
expect(model.isPageToolbarVisible).toBeTruthy();
719+
expect(model.nextPageAction.enabled).toBeTruthy();
720+
expect(model.prevPageAction.enabled).toBeTruthy();
721+
});
698722

699723
test("Default mobile orientation", (): any => {
700724
const creator: CreatorTester = new CreatorTester();

0 commit comments

Comments
 (0)