Skip to content

Commit

Permalink
Work for #6966 - fixed u-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tsv2013 committed Sep 18, 2023
1 parent 61fb232 commit 60246c0
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 27 deletions.
3 changes: 0 additions & 3 deletions src/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2282,9 +2282,6 @@ export class Question extends SurveyElement<Question>
};
this.resizeObserver = new ResizeObserver((entries: ResizeObserverEntry[]) => {
window.requestAnimationFrame((): void | undefined => {
if (!Array.isArray(entries) || !entries.length) {
return;
}
this.triggerResponsiveness(false);
});
});
Expand Down
3 changes: 0 additions & 3 deletions src/survey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4532,9 +4532,6 @@ export class SurveyModel extends SurveyElementCore
let isProcessed = false;
this.resizeObserver = new ResizeObserver((entries: ResizeObserverEntry[]) => {
window.requestAnimationFrame((): void | undefined => {
if (!Array.isArray(entries) || !entries.length) {
return;
}
if (isProcessed || !isContainerVisible(observedElement)) {
isProcessed = false;
} else {
Expand Down
3 changes: 0 additions & 3 deletions src/utils/responsivity-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ export class ResponsivityManager {
if (typeof ResizeObserver !== "undefined") {
this.resizeObserver = new ResizeObserver((entries: ResizeObserverEntry[]) => {
window.requestAnimationFrame((): void | undefined => {
if (!Array.isArray(entries) || !entries.length) {
return;
}
this.process();
});
});
Expand Down
30 changes: 16 additions & 14 deletions tests/questionImagepicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { defaultV2Css } from "../src/defaultCss/defaultV2Css";

export default QUnit.module("imagepicker");

QUnit.test("Add choices in runtime", function(assert) {
QUnit.test("Add choices in runtime", function (assert) {
let survey = new SurveyModel({});
let page = survey.addNewPage();
let question = <QuestionImagePickerModel>page.addNewQuestion("imagepicker");
Expand Down Expand Up @@ -34,7 +34,7 @@ QUnit.test("Add choices in runtime", function(assert) {
);
});

QUnit.test("Localized imageLink", function(assert) {
QUnit.test("Localized imageLink", function (assert) {
let survey = new SurveyModel({});
let page = survey.addNewPage();
let question = <QuestionImagePickerModel>page.addNewQuestion("imagepicker");
Expand Down Expand Up @@ -73,7 +73,7 @@ QUnit.test("Localized imageLink", function(assert) {
survey.locale = "";
});

QUnit.test("check dependency getItemClass method on colCount", function(
QUnit.test("check dependency getItemClass method on colCount", function (
assert
) {
let survey = new SurveyModel({});
Expand All @@ -86,7 +86,7 @@ QUnit.test("check dependency getItemClass method on colCount", function(
"sv_q_imgsel sv_q_imagepicker_inline"
);
});
QUnit.test("check process responsiveness for imagepicker, colCount == 0", function(assert) {
QUnit.test("check process responsiveness for imagepicker, colCount == 0", function (assert) {
let survey = new SurveyModel({});
survey.css = defaultV2Css;
let page = survey.addNewPage();
Expand All @@ -113,7 +113,7 @@ QUnit.test("check process responsiveness for imagepicker, colCount == 0", functi
assert.equal(question.renderedImageHeight, 100);
});

QUnit.test("check process responsiveness for imagepicker, colCount !== 0", function(assert) {
QUnit.test("check process responsiveness for imagepicker, colCount !== 0", function (assert) {
let survey = new SurveyModel({});
survey.css = defaultV2Css;
let page = survey.addNewPage();
Expand Down Expand Up @@ -148,7 +148,7 @@ QUnit.test("check process responsiveness for imagepicker, colCount !== 0", funct
assert.equal(question.renderedImageHeight, "50");
});

QUnit.test("check isResponsive getter", function(assert) {
QUnit.test("check isResponsive getter", function (assert) {
let survey = new SurveyModel({});
survey.css = defaultV2Css;
let page = survey.addNewPage();
Expand All @@ -161,7 +161,7 @@ QUnit.test("check isResponsive getter", function(assert) {
assert.notOk(question["isResponsive"]);
});

QUnit.test("check isResponsive getter after end of loading json", function(assert) {
QUnit.test("check isResponsive getter after end of loading json", function (assert) {
let survey = new SurveyModel(
{
"elements": [
Expand Down Expand Up @@ -205,17 +205,18 @@ QUnit.test("check isResponsive getter after end of loading json", function(asser
});

export class CustomResizeObserver {
constructor(private callback: () => void) {}
constructor(private callback: () => void) { }
observe() {
this.call();
}
call() {
this.callback();
}
disconnect() {}
disconnect() { }
}

QUnit.test("check resizeObserver behavior", function(assert) {
QUnit.test("check resizeObserver behavior", function (assert) {
window.requestAnimationFrame = (func: any) => !!func && func();
const ResizeObserver = window.ResizeObserver;
const setTimeout = window.setTimeout;
window.ResizeObserver = <any>CustomResizeObserver;
Expand Down Expand Up @@ -265,7 +266,8 @@ QUnit.test("check resizeObserver behavior", function(assert) {
rootEl.remove();
});

QUnit.test("check resizeObserver not process if container is not visible", function(assert) {
QUnit.test("check resizeObserver not process if container is not visible", function (assert) {
window.requestAnimationFrame = (func: any) => !!func && func();
const ResizeObserver = window.ResizeObserver;
window.ResizeObserver = <any>CustomResizeObserver;
const rootEl = document.createElement("div");
Expand Down Expand Up @@ -310,7 +312,7 @@ QUnit.test("check resizeObserver not process if container is not visible", funct
rootEl.remove();
});

QUnit.test("check contentNotLoaded and contentMode flags behavior", function(assert) {
QUnit.test("check contentNotLoaded and contentMode flags behavior", function (assert) {
const survey = new SurveyModel(
{
"elements": [
Expand All @@ -328,7 +330,7 @@ QUnit.test("check contentNotLoaded and contentMode flags behavior", function(ass
}
);
const question = <QuestionImagePickerModel>survey.getAllQuestions()[0];
const choice = <ImageItemValue> question.visibleChoices[0];
const choice = <ImageItemValue>question.visibleChoices[0];
assert.notOk(choice.contentNotLoaded);
question.onContentLoaded(choice, { target: {} });
assert.notOk(choice.contentNotLoaded);
Expand All @@ -341,7 +343,7 @@ QUnit.test("check contentNotLoaded and contentMode flags behavior", function(ass
assert.ok(choice.contentNotLoaded);
});

QUnit.test("check reCalcGap", function(assert) {
QUnit.test("check reCalcGap", function (assert) {
const survey = new SurveyModel(
{
"elements": [
Expand Down
1 change: 1 addition & 0 deletions tests/question_ratingtests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ QUnit.test("check rating initResponsiveness", (assert) => {
});

QUnit.test("check rating resize observer behavior", (assert) => {
window.requestAnimationFrame = (func: any) => !!func && func();
const ResizeObserver = window.ResizeObserver;
const getComputedStyle = window.getComputedStyle;
window.ResizeObserver = <any>CustomResizeObserver;
Expand Down
12 changes: 8 additions & 4 deletions tests/surveytests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7661,7 +7661,7 @@ QUnit.test(
assert.equal(survey.getCorrectAnswerCount(), 1, "The answer is correct now, #2");
let counter = 0;
survey.onIsAnswerCorrect.add(function (survey, options) {
counter ++;
counter++;
const q = options.question;
options.result = Helpers.isTwoValueEquals(q.value, q.correctAnswer, false);
});
Expand Down Expand Up @@ -15608,6 +15608,7 @@ class CustomResizeObserver {
}

QUnit.test("Check survey resize observer double process", function (assert) {
window.requestAnimationFrame = (func: any) => !!func && func();
const getComputedStyle = window.getComputedStyle;
window.getComputedStyle = <any>((el: HTMLElement) => {
return el.style;
Expand Down Expand Up @@ -17717,7 +17718,8 @@ QUnit.test("Copy panel with invisible questions at design-time", (assert): any =
survey.setDesignMode(true);
survey.fromJSON({
elements: [
{ type: "panel", name: "panel1",
{
type: "panel", name: "panel1",
elements: [
{ type: "text", name: "q1", visible: false },
{ type: "text", name: "q2" }
Expand Down Expand Up @@ -17819,7 +17821,8 @@ QUnit.test("Test getDisplayValue() function", function (assert) {
assert.deepEqual(survey.data, {
q1: [1, 2], q1_exp: "Item 1, Item 2",
q2: [{ q2_q1: [2, 3], q2_q1_exp: "Item 2, Item 3" }],
q3: [{ col1: [1, 3], col1_exp: "Item 1, Item 3", q3_q1: [1, 2, 3], q3_q1_exp: "Item 1, Item 2, Item 3" }] }, "displayValue works correctly");
q3: [{ col1: [1, 3], col1_exp: "Item 1, Item 3", q3_q1: [1, 2, 3], q3_q1_exp: "Item 1, Item 2, Item 3" }]
}, "displayValue works correctly");
});
QUnit.test("Test propertyValue() function", function (assert) {
const survey = new SurveyModel({
Expand Down Expand Up @@ -17870,7 +17873,8 @@ QUnit.test("Test propertyValue() function", function (assert) {
assert.deepEqual(survey.data, {
q1_exp: "Q1",
q2: [{ q2_q1_exp: "Q2_Q1" }],
q3: [{ col1_exp: "Column 1" }] }, "propertyValue works correctly");
q3: [{ col1_exp: "Column 1" }]
}, "propertyValue works correctly");
});
QUnit.test("Error on pre-processing localizable string Bug#6967", function (assert) {
const prevVal = surveyLocalization.locales.en.completeText;
Expand Down

0 comments on commit 60246c0

Please sign in to comment.