Skip to content

Commit

Permalink
Fix unit test in Creator master
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov committed Oct 25, 2024
1 parent c0d258b commit fed5b70
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 20 deletions.
7 changes: 7 additions & 0 deletions packages/survey-core/src/localizablestring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ export class LocalizableString implements ILocalizableString {
}
public setLocaleText(loc: string, value: string): void {
loc = this.getValueLoc(loc);
if(!!loc && value === undefined) {
const oldValue = this.getValue(loc);
if(oldValue !== undefined) {
this.deleteValue(loc);
this.fireStrChanged(loc, oldValue);
}
}
if (!this.storeDefaultText && this.isLocaleTextEqualsWithDefault(loc, value)) {
if (!this.isValueEmpty(value) || !!loc && loc !== this.defaultLoc) return;
let dl = surveyLocalization.defaultLocale;
Expand Down
2 changes: 1 addition & 1 deletion packages/survey-core/src/question_matrixdynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ export class QuestionMatrixDynamicModel extends QuestionMatrixDropdownModelBase
const nextRenderedRowIndex = this.renderedTable.getRenderedRowIndex(nextRow);
row2Focus = this.renderedTable.rows[nextRenderedRowIndex];
}
row2Focus.focusCell(this.getActionCellIndex(nextRow));
row2Focus?.focusCell(this.getActionCellIndex(nextRow));
} else {
this.focusAddBUtton();
}
Expand Down
8 changes: 8 additions & 0 deletions packages/survey-core/tests/localizablestringtests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -905,3 +905,11 @@ QUnit.test("allowLineBreaks check", function (assert) {
assert.notOk(tester.locText.allowLineBreaks);
assert.ok(testerText.locText.allowLineBreaks);
});
QUnit.test("Remove locale for en empty string", function (assert) {
const owner = new LocalizableOwnerTester("");
const locStr = new LocalizableString(owner, true);
locStr.setJson({ default: "str", de: "" }, true);
assert.deepEqual(locStr.getJson(), { default: "str", de: "" }, "getJson #1");
locStr.clearLocale("de");
assert.deepEqual(locStr.getJson(), "str", "getJson #2");
});
35 changes: 16 additions & 19 deletions packages/survey-core/tests/surveyLocalizationTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,27 +255,24 @@ QUnit.test(
assert.equal(question.getLocale(), "de", "question has Deutsch locale right now");
}
);
QUnit.test(
"Clear localization locale value if it equals to default and it is not empty and default is empty",
function(assert) {
let survey = new SurveyModel({ title: { de: "Hallo" } });
surveyLocalization.defaultLocale = "de";
assert.equal(survey.title, "Hallo", "Get the correct value");
let counter = 0;
survey.locTitle.onChanged = () => { counter++; };
survey.title = "";
assert.equal(survey.title, "", "Value is cleared");
assert.equal(counter, 1, "str changed is fired");
QUnit.test("Clear localization locale value if it equals to default and it is not empty and default is empty", function(assert) {
let survey = new SurveyModel({ title: { de: "Hallo" } });
surveyLocalization.defaultLocale = "de";
assert.equal(survey.title, "Hallo", "Get the correct value");
let counter = 0;
survey.locTitle.onChanged = () => { counter++; };
survey.title = "";
assert.equal(survey.title, "", "Value is cleared");
assert.equal(counter, 1, "str changed is fired");

survey = new SurveyModel({ title: { de: "Hallo" } });
surveyLocalization.defaultLocale = "de";
assert.equal(survey.title, "Hallo", "Get the correct value, #2");
survey.title = "Hello";
assert.equal(survey.title, "Hello", "Value set correctly, #3");
survey = new SurveyModel({ title: { de: "Hallo" } });
surveyLocalization.defaultLocale = "de";
assert.equal(survey.title, "Hallo", "Get the correct value, #2");
survey.title = "Hello";
assert.equal(survey.title, "Hello", "Value set correctly, #3");

surveyLocalization.defaultLocale = "en";
}
);
surveyLocalization.defaultLocale = "en";
});

QUnit.test("Support language dialect", function(assert) {
assert.equal(surveyLocalization.getString("pagePrevText", "pt-br"), "Anterior", "get from pt");
Expand Down

0 comments on commit fed5b70

Please sign in to comment.