Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rewrite dropdown list model init in unit test #6386

Merged
merged 3 commits into from
Oct 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions tests/dropdown_list_model_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function getVisibleActionByIndex(list: ListModel, index: number) {
QUnit.test("DropdownListModel with ListModel", (assert) => {
const survey = new SurveyModel(jsonDropdown);
const question = <QuestionDropdownModel>survey.getAllQuestions()[0];
const dropdownListModel = new DropdownListModel(question);
const dropdownListModel = question.dropdownListModel;
assert.ok(dropdownListModel.popupModel.contentComponentData.model instanceof ListModel);

const list: ListModel = dropdownListModel.popupModel.contentComponentData.model as ListModel;
Expand All @@ -74,7 +74,7 @@ QUnit.test("DropdownListModel with ListModel", (assert) => {
QUnit.test("DropdownListModel focusFirstInputSelector", (assert) => {
const survey = new SurveyModel(jsonDropdown);
const question = <QuestionDropdownModel>survey.getAllQuestions()[0];
const dropdownListModel = new DropdownListModel(question);
const dropdownListModel = question.dropdownListModel;
const popupModel = dropdownListModel.popupModel;
const list: ListModel = dropdownListModel.popupModel.contentComponentData.model as ListModel;
list.showFilter = true;
Expand Down Expand Up @@ -123,7 +123,7 @@ QUnit.test("DropdownListModel focusFirstInputSelector mobile", (assert) => {
_setIsTouch(true);
const survey = new SurveyModel(jsonDropdown);
const question = <QuestionDropdownModel>survey.getAllQuestions()[0];
const dropdownListModel = new DropdownListModel(question);
const dropdownListModel = question.dropdownListModel;
const popupModel = dropdownListModel.popupModel;
const list: ListModel = dropdownListModel.popupModel.contentComponentData.model as ListModel;

Expand Down Expand Up @@ -192,7 +192,7 @@ QUnit.test("DropdownListModel with ListModel & searchEnabled false", (assert) =>
QUnit.test("filterString test", function (assert) {
const survey = new SurveyModel(jsonDropdown);
const question = <QuestionDropdownModel>survey.getAllQuestions()[0];
const dropdownListModel = new DropdownListModel(question);
const dropdownListModel = question.dropdownListModel;
const list: ListModel = dropdownListModel.popupModel.contentComponentData.model as ListModel;

assert.equal(dropdownListModel.inputMode, "text");
Expand All @@ -215,7 +215,7 @@ QUnit.test("filterString test", function (assert) {
QUnit.test("open/hide dropdown popup after start/end filtration", function (assert) {
const survey = new SurveyModel(jsonDropdown);
const question = <QuestionDropdownModel>survey.getAllQuestions()[0];
const dropdownListModel = new DropdownListModel(question);
const dropdownListModel = question.dropdownListModel;
const popup = dropdownListModel.popupModel;
const list: ListModel = dropdownListModel.popupModel.contentComponentData.model as ListModel;

Expand All @@ -238,7 +238,7 @@ QUnit.test("open/hide dropdown popup after start/end filtration", function (asse
QUnit.test("hide dropdown on clear", function (assert) {
const survey = new SurveyModel(jsonDropdown);
const question = <QuestionDropdownModel>survey.getAllQuestions()[0];
const dropdownListModel = new DropdownListModel(question);
const dropdownListModel = question.dropdownListModel;
const popup = dropdownListModel.popupModel;

popup.isVisible = true;
Expand All @@ -249,7 +249,7 @@ QUnit.test("hide dropdown on clear", function (assert) {
QUnit.test("hide component on input entering symbols", function (assert) {
const survey = new SurveyModel(jsonDropdown);
const question = <QuestionDropdownModel>survey.getAllQuestions()[0];
const dropdownListModel = new DropdownListModel(question);
const dropdownListModel = question.dropdownListModel;
question.inputFieldComponent = "component-name";
question.value = "Ford";
assert.ok(question.showInputFieldComponent);
Expand Down Expand Up @@ -277,7 +277,7 @@ QUnit.test("Check list classes with onUpdateQuestionCssClasses", function (asser
};
});
const question = <QuestionDropdownModel>survey.getAllQuestions()[0];
const dropdownListModel = new DropdownListModel(question);
const dropdownListModel = question.dropdownListModel;
question.dropdownListModel = dropdownListModel;
question.onFirstRendering();
const list: ListModel = dropdownListModel.popupModel.contentComponentData.model as ListModel;
Expand All @@ -289,7 +289,7 @@ QUnit.test("Check overlay popup when IsTouch is true", function (assert) {
_setIsTouch(true);
const survey = new SurveyModel(jsonDropdown);
const question = <QuestionDropdownModel>survey.getAllQuestions()[0];
const dropdownListModel = new DropdownListModel(question);
const dropdownListModel = question.dropdownListModel;
const popup: PopupModel = dropdownListModel.popupModel;
const list: ListModel = dropdownListModel.popupModel.contentComponentData.model as ListModel;
assert.equal(dropdownListModel.inputMode, "none");
Expand All @@ -307,7 +307,7 @@ QUnit.test("Check overlay popup when IsTouch is true", function (assert) {
QUnit.test("Check dropdown list model is updated from value", function (assert) {
const survey = new SurveyModel(jsonDropdown);
const question = <QuestionDropdownModel>survey.getAllQuestions()[0];
const dropdownListModel = new DropdownListModel(question);
const dropdownListModel = question.dropdownListModel;
const list: ListModel = dropdownListModel.popupModel.contentComponentData.model as ListModel;
question.value = "item1";
assert.ok(list.isItemSelected(list.actions.filter(item => item.id === "item1")[0]));
Expand All @@ -318,7 +318,7 @@ QUnit.test("Check dropdown list model is updated from value", function (assert)
QUnit.test("filterString and focusedItem", function (assert) {
const survey = new SurveyModel(jsonDropdown);
const question = <QuestionDropdownModel>survey.getAllQuestions()[0];
const dropdownListModel = new DropdownListModel(question);
const dropdownListModel = question.dropdownListModel;
const list: ListModel = dropdownListModel.popupModel.contentComponentData.model as ListModel;

assert.equal(dropdownListModel.inputMode, "text");
Expand All @@ -337,7 +337,7 @@ QUnit.test("filterString and focusedItem", function (assert) {
QUnit.test("hintString test", function (assert) {
const survey = new SurveyModel(jsonDropdown);
const question = <QuestionDropdownModel>survey.getAllQuestions()[0];
const dropdownListModel = new DropdownListModel(question);
const dropdownListModel = question.dropdownListModel;
const list: ListModel = dropdownListModel.popupModel.contentComponentData.model as ListModel;

assert.equal(dropdownListModel.inputMode, "text");
Expand Down Expand Up @@ -381,7 +381,7 @@ QUnit.test("showHintString for zero values", function (assert) {
]
});
const question = <QuestionDropdownModel>survey.getAllQuestions()[0];
const dropdownListModel = new DropdownListModel(question);
const dropdownListModel = question.dropdownListModel;
const list: ListModel = dropdownListModel.popupModel.contentComponentData.model as ListModel;
dropdownListModel.inputStringRendered = "1";
question.value = 0;
Expand All @@ -391,7 +391,7 @@ QUnit.test("showHintString for zero values", function (assert) {
QUnit.test("hintString test - no search", function (assert) {
const survey = new SurveyModel(jsonDropdown);
const question = <QuestionDropdownModel>survey.getAllQuestions()[0];
const dropdownListModel = new DropdownListModel(question);
const dropdownListModel = question.dropdownListModel;
const list: ListModel = dropdownListModel.popupModel.contentComponentData.model as ListModel;
question.searchEnabled = false;

Expand All @@ -415,7 +415,7 @@ QUnit.test("hintString test - clear, see nothing", function (assert) {
QUnit.test("dropdown keyboard tests", function (assert) {
const survey = new SurveyModel(jsonDropdown);
const question = <QuestionDropdownModel>survey.getAllQuestions()[0];
const dropdownListModel = new DropdownListModel(question);
const dropdownListModel = question.dropdownListModel;
const list: ListModel = dropdownListModel.popupModel.contentComponentData.model as ListModel;

const event = {
Expand Down Expand Up @@ -498,7 +498,7 @@ QUnit.test("dropdown incorrect popup open test", function (assert) {
const survey = new SurveyModel(jsonDropdown);
const question = <QuestionDropdownModel>survey.getAllQuestions()[0];
question.defaultValue = "item22";
const dropdownListModel = new DropdownListModel(question);
const dropdownListModel = question.dropdownListModel;
const list: ListModel = dropdownListModel.popupModel.contentComponentData.model as ListModel;

const event = {
Expand Down Expand Up @@ -634,7 +634,7 @@ QUnit.test("dropdown incorrect popup open test: lazy load, many items", function
QUnit.test("dropdown keyboard tests - empty question, search disabled", function (assert) {
const survey = new SurveyModel(jsonDropdown);
const question = <QuestionDropdownModel>survey.getAllQuestions()[0];
const dropdownListModel = new DropdownListModel(question);
const dropdownListModel = question.dropdownListModel;
const list: ListModel = dropdownListModel.popupModel.contentComponentData.model as ListModel;

const event = {
Expand Down Expand Up @@ -685,7 +685,7 @@ QUnit.test("dropdown keyboard tests - empty question, search disabled", function
QUnit.test("always show invisible hint part", function (assert) {
const survey = new SurveyModel(jsonDropdown);
const question = <QuestionDropdownModel>survey.getAllQuestions()[0];
const dropdownListModel = new DropdownListModel(question);
const dropdownListModel = question.dropdownListModel;
const list: ListModel = dropdownListModel.popupModel.contentComponentData.model as ListModel;

question.value = "item1";
Expand All @@ -705,7 +705,7 @@ QUnit.test("always show invisible hint part", function (assert) {
QUnit.test("change selection on keyboard", function (assert) {
const survey = new SurveyModel(jsonDropdown);
const question = <QuestionDropdownModel>survey.getAllQuestions()[0];
const dropdownListModel = new DropdownListModel(question);
const dropdownListModel = question.dropdownListModel;
const list: ListModel = dropdownListModel.popupModel.contentComponentData.model as ListModel;

dropdownListModel.onClick(null);
Expand Down Expand Up @@ -740,7 +740,7 @@ QUnit.test("change selection on keyboard", function (assert) {
QUnit.test("filtering on question with value", function (assert) {
const survey = new SurveyModel(jsonDropdown);
const question = <QuestionDropdownModel>survey.getAllQuestions()[0];
const dropdownListModel = new DropdownListModel(question);
const dropdownListModel = question.dropdownListModel;
const list: ListModel = dropdownListModel.popupModel.contentComponentData.model as ListModel;

question.value = "item1";
Expand Down Expand Up @@ -774,7 +774,7 @@ QUnit.test("hintString letter case", function (assert) {
}]
});
const question = <QuestionDropdownModel>survey.getAllQuestions()[0];
const dropdownListModel = new DropdownListModel(question);
const dropdownListModel = question.dropdownListModel;

dropdownListModel.inputStringRendered = "Ab";
assert.equal(dropdownListModel.hintString, "AbcAbc");
Expand All @@ -801,7 +801,7 @@ QUnit.test("Survey Markdown - dropdown and other option", function (assert) {
});

q1.value = 2;
const dropdownListModel = new DropdownListModel(q1);
const dropdownListModel = q1.dropdownListModel;

dropdownListModel.changeSelectionWithKeyboard(false);
assert.equal(dropdownListModel.hintString, "", "no hint on start");
Expand Down Expand Up @@ -833,7 +833,7 @@ QUnit.test("lazy loading clear value", function (assert) {
stopPropagation: () => { }
};
const question = <QuestionDropdownModel>survey.getAllQuestions()[0];
const dropdownListModel = new DropdownListModel(question);
const dropdownListModel = question.dropdownListModel;
assert.equal(question.showSelectedItemLocText, true, "showSelectedItemLocText");
event.keyCode = 13;
dropdownListModel.keyHandler(event);
Expand Down