From 2700c6972167a5e4cd04663c3ae2f78d6ed59b7d Mon Sep 17 00:00:00 2001 From: Andrew Telnov Date: Mon, 10 Apr 2023 14:30:58 +0300 Subject: [PATCH 1/4] Add functional tests #5977 --- .../questions/component_single_question.ts | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 testCafe/questions/component_single_question.ts diff --git a/testCafe/questions/component_single_question.ts b/testCafe/questions/component_single_question.ts new file mode 100644 index 0000000000..6dc52dc7a1 --- /dev/null +++ b/testCafe/questions/component_single_question.ts @@ -0,0 +1,56 @@ +import { frameworks, url, initSurvey, getListItemByText, completeButton, getSurveyResult } from "../helper"; +import { Selector, ClientFunction } from "testcafe"; +const title = "component_single_question"; +const questionDropdownSelect = Selector(".sv_q_dropdown_control"); +const json_question = { + elements: [ + { + type: "newquestion", + name: "q1" + }, + ], +}; +const json_matrix = { + elements: [ + { + type: "matrixdynamic", + name: "matrix", + columns: [{ name: "col1", cellType: "newquestion" }], + rowCount: 1, + }, + ], +}; +const createComponent = ClientFunction(() => { + window["Survey"].ComponentCollection.Instance.add({ + name: "newquestion", + questionJSON: { + type: "dropdown", + choices: ["a", "b", "c"], + }, + }); +}); + +frameworks.forEach((framework) => { + fixture`${framework} ${title}`.page`${url}${framework}.html`; + + test("Component as a single question", async (t) => { + await createComponent(); + await initSurvey(framework, json_question); + await t + .click(questionDropdownSelect) + .click(getListItemByText("b")) + .click(completeButton); + const surveyResult = await getSurveyResult(); + await t.expect(surveyResult.q1).eql("b"); + }); + test("Component as a cell question", async (t) => { + await createComponent(); + await initSurvey(framework, json_matrix); + await t + .click(questionDropdownSelect) + .click(getListItemByText("b")) + .click(completeButton); + const surveyResult = await getSurveyResult(); + await t.expect(surveyResult.matrix[0].col1).eql("b"); + }); +}); \ No newline at end of file From 3deaae3087aeb599fc555ce2bf41787f443cdd70 Mon Sep 17 00:00:00 2001 From: Andrew Telnov Date: Mon, 10 Apr 2023 16:32:06 +0300 Subject: [PATCH 2/4] Fix functional test #5977 --- packages/survey-angular-ui/src/question.component.ts | 9 ++------- packages/survey-angular-ui/src/question.ts | 8 ++++++++ .../src/questions/custom.component.ts | 9 ++------- .../src/questions/matrixcell.component.ts | 10 +++------- src/react/reactSurvey.tsx | 5 +---- src/vue/custom.vue | 7 ++----- src/vue/element.vue | 11 ++++------- src/vue/flowpanelelement.vue | 6 ++---- src/vue/matrixcell.vue | 6 ++---- src/vue/multipletextitem.vue | 6 ++---- src/vue/question.ts | 6 ++++++ 11 files changed, 34 insertions(+), 49 deletions(-) diff --git a/packages/survey-angular-ui/src/question.component.ts b/packages/survey-angular-ui/src/question.component.ts index 9a702a3f82..716ad2b2fb 100644 --- a/packages/survey-angular-ui/src/question.component.ts +++ b/packages/survey-angular-ui/src/question.component.ts @@ -2,6 +2,7 @@ import { Component, ElementRef, Input, ViewChild } from "@angular/core"; import { Question } from "survey-core"; import { AngularComponentFactory } from "./component-factory"; import { EmbeddedViewContentComponent } from "./embedded-view-content.component"; +import { getComponentName } from "./question"; @Component({ selector: "sv-ng-question", @@ -18,13 +19,7 @@ export class QuestionComponent extends EmbeddedViewContentComponent { this.model.afterRender(this.rootEl?.nativeElement); } } - public getComponentName(): string { - if (this.model.customWidget) return "survey-customwidget"; - if (this.model.isDefaultRendering()) { - return this.model.getTemplate() + "-question"; - } - return this.model.getComponentName(); - } + public getComponentName(): string { return getComponentName(this.model); } public getQuestionContentWrapperComponentName(): string { return (this.model.survey).getQuestionContentWrapperComponentName(this.model) || this.getComponentName(); } diff --git a/packages/survey-angular-ui/src/question.ts b/packages/survey-angular-ui/src/question.ts index 3df34bd224..dbcdc59995 100644 --- a/packages/survey-angular-ui/src/question.ts +++ b/packages/survey-angular-ui/src/question.ts @@ -25,4 +25,12 @@ export class QuestionAngular extends BaseAngular< } super.ngOnDestroy(); } +} + +export function getComponentName(question: Question): string { + if (question.customWidget) return "survey-customwidget"; + if (question.isDefaultRendering()) { + return question.getTemplate() + "-question"; + } + return question.getComponentName(); } \ No newline at end of file diff --git a/packages/survey-angular-ui/src/questions/custom.component.ts b/packages/survey-angular-ui/src/questions/custom.component.ts index 6e88b40020..2614f9b75c 100644 --- a/packages/survey-angular-ui/src/questions/custom.component.ts +++ b/packages/survey-angular-ui/src/questions/custom.component.ts @@ -1,7 +1,7 @@ import { Question } from "survey-core"; import { QuestionCustomModel } from "survey-core"; import { Component } from "@angular/core"; -import { QuestionAngular } from "../question"; +import { QuestionAngular, getComponentName } from "../question"; import { AngularComponentFactory } from "../component-factory"; @Component({ @@ -12,12 +12,7 @@ export class CustomQuestionComponent extends QuestionAngular { @Input() question!: QuestionMatrixDropdownModelBase; @Input() cell!: QuestionMatrixDropdownRenderedCell; @@ -54,12 +55,7 @@ export class MatrixCellComponent extends BaseAngular { }; } - getComponentName(element: Question) { - if (element.customWidget) { - return "survey-customwidget"; - } - return element.getType()+"-question"; - } + getComponentName(element: Question) { return getComponentName(element); } getHeaders(): string { return this.cell.headers; } diff --git a/src/react/reactSurvey.tsx b/src/react/reactSurvey.tsx index 2cc3d2f407..88db173ddd 100644 --- a/src/react/reactSurvey.tsx +++ b/src/react/reactSurvey.tsx @@ -275,10 +275,7 @@ export class Survey extends SurveyElementBase //ISurveyCreator public createQuestionElement(question: Question): JSX.Element | null { - return ReactQuestionFactory.Instance.createQuestion( - !question.isDefaultRendering || question.isDefaultRendering() - ? question.getTemplate() - : question.getComponentName(), + return ReactQuestionFactory.Instance.createQuestion(question.isDefaultRendering() ? question.getTemplate() : question.getComponentName(), { question: question, isDisplayMode: question.isInputReadOnly, diff --git a/src/vue/custom.vue b/src/vue/custom.vue index 79c12617f1..0c345f113b 100644 --- a/src/vue/custom.vue +++ b/src/vue/custom.vue @@ -9,7 +9,7 @@