Skip to content

Commit

Permalink
Vue3: fix selected item's loc strings conflict in dropdown (#9120)
Browse files Browse the repository at this point in the history
* Vue3: fix selected item's  loc strings are conflicting in dropdown

* Remove test.only

* Fix functional tests

* Fix js ui functional tests
  • Loading branch information
dk981234 authored Dec 3, 2024
1 parent 18f2790 commit fbf8a87
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/survey-vue3-ui/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,29 +148,29 @@ export function useQuestion<T extends Question>(
props.question.beforeDestroyQuestionElement(root.value);
});
}
function noop() {}
export function useLocString(
getLocString: () => LocalizableString
): Ref<string> {
const renderedHtml = ref();
const onStringChangedCallbck = (locString: LocalizableString) => {
renderedHtml.value = locString.renderedHtml;
};
const setupOnChangedCallback = (locString: LocalizableString) => {
renderedHtml.value = locString.renderedHtml;
locString.onChanged = () => {
renderedHtml.value = locString.renderedHtml;
};
locString.onStringChanged.add(onStringChangedCallbck);
};
const stopWatch = watch(
getLocString,
(newValue, oldValue) => {
if (oldValue) oldValue.onChanged = noop;
if (oldValue) oldValue.onStringChanged.remove(onStringChangedCallbck);
setupOnChangedCallback(newValue);
},
{ immediate: true }
);
onBeforeUnmount(() => {
const locString = getLocString();
if (locString) {
locString.onChanged = noop;
locString.onStringChanged.remove(onStringChangedCallbck);
}
stopWatch();
});
Expand Down
51 changes: 51 additions & 0 deletions testCafe/questions/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -2267,4 +2267,55 @@ frameworks.forEach((framework) => {
let surveyResult = await getSurveyResult();
await t.expect(surveyResult).eql({ q1: { row1: { col1: "other", "col1-Comment": "ABC" } } });
});
});
frameworks.forEach((framework) => {
fixture`${framework} ${title}`.page`${url}${framework}`;
test("Check item title changes when locale is changed", async (t) => {
await initSurvey(framework, {
locale: "de",
elements: [
{
defaultValue: "one",
choices: [
{
text: {
default: "english",
de: "notenglish",
},
value: "one",
},
],
name: "q1",
title: {
default: "english",
de: "notenglish",
},
type: "dropdown",
},
],
});
const changeLocale = ClientFunction((locale) => {
window.survey.locale = locale;
});
await t
.expect(Selector(".sv_q_dropdown__value span").withExactText("notenglish").exists).ok()
.click("input")
.expect(Selector("li div").withAttribute("title", "notenglish").exists).ok()
.expect(Selector("li div span").withExactText("notenglish").exists).ok()
.click("body", { offsetX: 0 });
await changeLocale("en");
await t
.expect(Selector(".sv_q_dropdown__value span").withExactText("english").exists).ok()
.click("input")
.expect(Selector("li div").withAttribute("title", "english").exists).ok()
.expect(Selector("li div span").withExactText("english").exists).ok()
.click("body", { offsetX: 0 });
await changeLocale("de");
await t
.expect(Selector(".sv_q_dropdown__value span").withExactText("notenglish").exists).ok()
.click("input")
.expect(Selector("li div").withAttribute("title", "notenglish").exists).ok()
.expect(Selector("li div span").withExactText("notenglish").exists).ok()
.click("body", { offsetX: 0 });
});
});

0 comments on commit fbf8a87

Please sign in to comment.