diff --git a/src/knockout/templates/question-custom.html b/src/knockout/templates/question-custom.html index 615fdb715a..978abd6b2b 100644 --- a/src/knockout/templates/question-custom.html +++ b/src/knockout/templates/question-custom.html @@ -1,4 +1,10 @@ diff --git a/src/question_custom.ts b/src/question_custom.ts index c77d648621..61c2eb8771 100644 --- a/src/question_custom.ts +++ b/src/question_custom.ts @@ -649,6 +649,12 @@ export class QuestionCustomModel extends QuestionCustomModelBase { super.focus(onError); } } + public afterRender(el: any): void { + super.afterRender(el); + if (!!this.contentQuestion) { + this.contentQuestion.afterRender(el); + } + } public get contentQuestion(): Question { return this.questionWrapper; } diff --git a/testCafe/survey/custom_components.ts b/testCafe/survey/custom_components.ts new file mode 100644 index 0000000000..457457d6b2 --- /dev/null +++ b/testCafe/survey/custom_components.ts @@ -0,0 +1,54 @@ +import { url_test, initSurvey, getSurveyResult, frameworks, explicitErrorHandler } from "../helper"; +import { Selector, ClientFunction } from "testcafe"; +const title = "Custom Components"; +const themeName = "defaultV2"; +const json = { + "elements": [ + { + type: "nps", + name: "q1" + } + ] +}; + +const registerNPSComponet = ClientFunction(() => { + window["Survey"].ComponentCollection.Instance.add({ + //Unique component name. It becomes a new question type. Please note, it should be written in lowercase. + name: "nps", //The text that shows on toolbox + title: "NPS Rating", //The actual question that will do the job + questionJSON: { + type: "rating", + rateValues: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], + minRateDescription: "Very unlikely", + maxRateDescription: "Very likely", + displayMode: "auto" + } + }); +}); + +frameworks.forEach(framework => { + fixture`${framework} ${title}`.page`${url_test}${themeName}/${framework}`.beforeEach( + async t => { + } + ); + test("Show rating in component as dropdown", async t => { + const questionDropdownSelect = Selector(".sd-input.sd-dropdown"); + await explicitErrorHandler(); + await t.resizeWindow(500, 600); + await registerNPSComponet(); + await initSurvey(framework, json); + + await t + .click(questionDropdownSelect) + .pressKey("down") + .pressKey("down") + .pressKey("down") + .pressKey("down") + .pressKey("enter"); + + await t.click(Selector("input[value='Complete']")); + + const surveyResult = await getSurveyResult(); + await t.expect(surveyResult.q1).eql(3); + }); +}); \ No newline at end of file