Skip to content

Commit

Permalink
Implemented #5380 - Introduce an option to hide the Survey Results se…
Browse files Browse the repository at this point in the history
…ction within the Preview tab (#5383)

* Implemented #5380 - Introduce an option to hide the Survey Results section within the Preview tab

* Update the description

---------

Co-authored-by: tsv2013 <tsv2013@noreply.github.com>
Co-authored-by: RomanTsukanov <sergeich16@gmail.com>
  • Loading branch information
3 people committed Apr 4, 2024
1 parent cb1d810 commit a33faa5
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/survey-creator-core/src/components/tabs/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class TestSurveyTabViewModel extends Base {
return this.surveyProvider.isMobileView;
}
public get showResults() {
return !this.isRunning && !this.isMobileView;
return this.surveyProvider.previewShowResults && !this.isRunning && !this.isMobileView;
}

public updateSimulatorSurvey(json: any, theme: any) {
Expand Down Expand Up @@ -128,7 +128,7 @@ export class TestSurveyTabViewModel extends Base {
this.updatePageItem(options.page);
this.updatePrevNextPageActionState();
});
if(hasSurveyBefore) {
if (hasSurveyBefore) {
this.show();
}
}
Expand Down
8 changes: 7 additions & 1 deletion packages/survey-creator-core/src/creator-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ export class SurveyCreatorModel extends Base
* @see showObjectTitles
*/
@property({ defaultValue: false }) inplaceEditForValues: boolean;
/**
* Specifies whether to display a table with survey results after completing a survey in the Preview tab.
*
* Default value: `true`
*/
@property({ defaultValue: true }) previewShowResults: boolean;
get allowEditSurveyTitle(): boolean {
return this.getPropertyValue("allowEditSurveyTitle", true);
}
Expand Down Expand Up @@ -1552,7 +1558,7 @@ export class SurveyCreatorModel extends Base
parentObj: Base,
parentProperty: JsonObjectProperty
): boolean {
if(!property) return false;
if (!property) return false;
const proposedValue = this.readOnly || readOnly;
if (this.onGetPropertyReadOnly.isEmpty) return proposedValue;
const options = {
Expand Down
2 changes: 2 additions & 0 deletions packages/survey-creator-core/src/creator-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ export interface ISurveyCreatorOptions {
enableLinkFileEditor: boolean;
inplaceEditForValues: boolean;
rootElement?: HTMLElement;
previewShowResults: boolean;
getObjectDisplayName(obj: Base, area: string, reason: string, displayName: string): string;
onCanShowPropertyCallback(
object: any,
Expand Down Expand Up @@ -331,6 +332,7 @@ export interface ISurveyCreatorOptions {
}

export class EmptySurveyCreatorOptions implements ISurveyCreatorOptions {
previewShowResults: boolean;
rootElement: HTMLElement;
enableLinkFileEditor: boolean;
getProcessedTranslationItemText(locale: string, locString: ILocalizableString, newText: string, obj: any): string {
Expand Down
45 changes: 43 additions & 2 deletions packages/survey-creator-core/tests/tabs/test.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { editorLocalization } from "../../src/editorLocalization";
import "survey-core/survey.i18n";

function getTestModel(creator: CreatorTester): TestSurveyTabViewModel {
if(creator.activeTab !== "test") {
if (creator.activeTab !== "test") {
creator.activeTab = "test";
}
const testPlugin: TabTestPlugin = <TabTestPlugin>creator.getPlugin("test");
Expand Down Expand Up @@ -839,7 +839,7 @@ test("Update theme in active test/preview tab", (): any => {
previewBodyCss = options.survey.css.body;
});
creator.onSurveyInstanceCreated.add((sender, options) => {
if(options.reason === "test") {
if (options.reason === "test") {
instanceBodyCss = options.survey.css.body;
instanceArea = options.area;
}
Expand All @@ -854,3 +854,44 @@ test("Update theme in active test/preview tab", (): any => {
expect(instanceArea).toEqual("preview-tab");
});

test("showResults default behavior", (): any => {
const creator: CreatorTester = new CreatorTester();
creator.JSON = {
questions: [
{
type: "text",
name: "q1",
}
]
};
expect(creator.previewShowResults).toBeTruthy();
const testPlugin: TabTestPlugin = <TabTestPlugin>creator.getPlugin("test");
testPlugin.activate();

const model: TestSurveyTabViewModel = testPlugin.model;
expect(model.showResults).toBeFalsy();

model.survey.doComplete();
expect(model.showResults).toBeTruthy();
});

test("showResults with previewShowResults false", (): any => {
const creator: CreatorTester = new CreatorTester({ previewShowResults: false });
creator.JSON = {
questions: [
{
type: "text",
name: "q1",
}
]
};
expect(creator.previewShowResults).toBeFalsy();
const testPlugin: TabTestPlugin = <TabTestPlugin>creator.getPlugin("test");
testPlugin.activate();

const model: TestSurveyTabViewModel = testPlugin.model;
expect(model.showResults).toBeFalsy();

model.survey.doComplete();
expect(model.showResults).toBeFalsy();
});

0 comments on commit a33faa5

Please sign in to comment.