Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ssibility test commands and extracted tests
  • Loading branch information
tsv2013 committed Oct 20, 2023
1 parent 2e1aab5 commit 5c9c54d
Show file tree
Hide file tree
Showing 4 changed files with 308 additions and 3 deletions.
299 changes: 299 additions & 0 deletions accessibilityTests/helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,299 @@
import { ClientFunction, Selector } from "testcafe";
// eslint-disable-next-line no-undef
const minimist = require("minimist");

// eslint-disable-next-line no-undef
const args = minimist(process.argv.slice(2));
const environment = args.env;

export const frameworks = environment
? [environment]
: ["knockout", "react", "vue"];
// eslint-disable-next-line no-console
console.log("Frameworks: " + frameworks.join(", "));
export const url = "http://127.0.0.1:8080/examples_test/default/";
export const urlV2 = "http://127.0.0.1:8080/examples_test/defaultV2/";
export const url_test = "http://127.0.0.1:8080/examples_test/";
export const FLOAT_PRECISION = 0.01;

export const applyTheme = ClientFunction((theme) => {
window["Survey"].StylesManager.applyTheme(theme);
});

export const initSurvey = ClientFunction(
(framework, json, events, isDesignMode, props) => {
// eslint-disable-next-line no-console
console.error = (msg) => {
throw new Error(msg);
};
// eslint-disable-next-line no-console
console.warn = (msg) => {
throw new Error(msg);
};
// eslint-disable-next-line no-console
console.log("surveyjs console.error and console.warn override");

const model = new window["Survey"].Model(json);
model.setDesignMode(isDesignMode);
const surveyComplete = function (model) {
window["SurveyResult"] = model.data;
document.getElementById("surveyResultElement").innerHTML = JSON.stringify(
model.data
);
};
if (!!events) {
for (var str in events) {
model[str].add(events[str]);
}
}
if (!!props) {
for (var key in props) {
model[key] = props[key];
}
}
model.onComplete.add(surveyComplete);

if (framework === "knockout") {
document.getElementById("surveyElement").innerHTML = "";
model.render("surveyElement");
} else if (framework === "react") {
document.getElementById("surveyElement").innerHTML = "";
window["ReactDOM"].render(
window["React"].createElement(window["Survey"].Survey, {
model: model,
onComplete: surveyComplete,
}),
document.getElementById("surveyElement")
);
} else if (framework === "vue") {
document.getElementById("surveyElement").innerHTML =
"<survey :survey='survey'/>";
!!window["vueApp"] && window["vueApp"].$destroy();
window["vueApp"] = new window["Vue"]({
el: "#surveyElement",
data: { survey: model },
});
} else if (framework === "angular" || framework == "vue3") {
window.setSurvey(model);
}
window["survey"] = model;
}
);

export const registerCustomToolboxComponent = ClientFunction(
(framework, json, events, isDesignMode, props) => {
if (framework === "knockout") {
window["ko"].components.register("svc-custom-action", {
viewModel: {
createViewModel: (params) => {
return params.item;
},
},
template:
'<span class="my-custom-action-class" data-bind="click: function() { $data.action() }, text: $data.title"></span>',
});
} else if (framework === "react") {
class CustomActionButton extends window["React"].Component {
click = () => {
this.props.item.action();
};
render() {
return (
// eslint-disable-next-line react/react-in-jsx-scope
<span className="my-custom-action-class" onClick={this.click}>
{" "}
{this.props.item.title}
</span>
);
}
}

window["Survey"].ReactElementFactory.Instance.registerElement(
"svc-custom-action",
(props) => {
return window["React"].createElement(CustomActionButton, props);
}
);
} else if (framework === "vue") {
window["Vue"].component("svc-custom-action", {
props: {
item: {},
},
template:
'<span class="my-custom-action-class" data-bind="click: function() { $data.action() }">{{ item.title }}</span>',
});
}
}
);

export const registerCustomItemComponent = ClientFunction(
(framework, json, events, isDesignMode, props) => {
if (framework === "knockout") {
window["ko"].components.register("new-item", {
viewModel: {
createViewModel: function (params, componentInfo) {
const item = params.item;
item.iconName = "icon-defaultfile";
item.hint = item.title + " - Description";
return item;
},
},
template:
'<div class="my-list-item" style="display:flex;" data-bind="attr: { title: hint } "><span><sv-svg-icon params=\'iconName: iconName, size: iconSize\'></sv-svg-icon></span><span data-bind="text: title, css: getActionBarItemTitleCss()"></span></div>',
});
} else if (framework === "react") {
class ItemTemplateComponent extends window["React"].Component {
render() {
const item = this.props.item;
var Survey = window["Survey"];
item.iconName = "icon-defaultfile";
item.hint = item.title + " - Description";

/* eslint-disable */
return (
<div
className="my-list-item"
style={{ display: "flex" }}
title={item.hint}
>
{" "}
<span>
{" "}
<Survey.SvgIcon
iconName={item.iconName}
size={item.iconSize}
></Survey.SvgIcon>{" "}
</span>{" "}
<span>{item.title}</span>{" "}
</div>
);
/* eslint-enable */
}
}
window["Survey"].ReactElementFactory.Instance.registerElement(
"new-item",
(props) => {
return window["React"].createElement(ItemTemplateComponent, props);
}
);
} else if (framework === "vue") {
window["Vue"].component("new-item", {
props: {
item: {},
},
created: function () {
const item = this.item;
item.iconName = "icon-defaultfile";
item.hint = item.title + " - Description";
},
template:
'<div class="my-list-item" style="display:flex;" v-bind:title="item.hint" ><span><sv-svg-icon :iconName="item.iconName" :size = "item.iconSize"></sv-svg-icon></span><span v-bind:class="item.getActionBarItemTitleCss()">{{ item.title }}</span></div>',
});
}
}
);

export const getSurveyResult = ClientFunction(() => {
var result = window["SurveyResult"];
if (typeof result === "undefined") {
return result;
}
//clean result object from the vuejs stuff
return JSON.parse(JSON.stringify(result));
});

export const getData = ClientFunction(() => {
return window["survey"].data;
});

export const setData = ClientFunction((newData) => {
window["survey"].data = newData;
window["survey"].render();
});

export const setOptions = ClientFunction((questionName, modValue) => {
const mergeOptions = function (obj1, obj2) {
for (const attrname in obj2) {
obj1[attrname] = obj2[attrname];
}
};
const q = window["survey"].getQuestionByName(questionName || "car");
mergeOptions(q, modValue);
// window["survey"].render();
});

export const joinElementInnerText = ClientFunction((tagName, index) => {
const el = document.getElementsByTagName(tagName)[index];
const spans = el.querySelectorAll("span");
let res = "";
for (let i = 0; i < spans.length; i++) {
const sp = spans[i];
if (!sp.innerHTML || sp.innerHTML == "&nbsp;") continue;
const childs = sp.getElementsByTagName("span");
if (childs.length > 0) continue;
if (!!res) res += " ";
res += sp.innerHTML;
}
return res;
});

export const getQuestionValue = ClientFunction(() => {
return window["survey"].getAllQuestions()[0].value;
});

export const getQuestionJson = ClientFunction(() => {
return JSON.stringify(window["survey"].getAllQuestions()[0].toJSON());
});

export const getPanelJson = ClientFunction(() => {
return JSON.stringify(window["survey"].getAllPanels()[0].toJSON());
});

export function getDynamicPanelRemoveButton(questionTitle, buttonText) {
return Selector("span")
.withText(`${questionTitle}`)
.parent("[aria-labelledby]")
.find("span")
.withText(buttonText);
}

export async function checkSurveyWithEmptyQuestion(t) {
const requiredMessage =
Selector(".sv-string-viewer").withText("Response required.");

await t
.expect(requiredMessage.exists)
.notOk()
.click(completeButton)
.expect(requiredMessage.visible)
.ok();

let surveyResult = await getSurveyResult();
await t.expect(typeof surveyResult).eql("undefined");
}

export function getListItemByText(text) {
return Selector(".sv-popup__content .sv-list .sv-list__item")
.withText(text)
.filterVisible();
}
export var completeButton = Selector(".sv_complete_btn");

export const explicitErrorHandler = ClientFunction(() => {
window.addEventListener("error", e => {
if (e.message === "ResizeObserver loop completed with undelivered notifications." ||
e.message === "ResizeObserver loop limit exceeded") {
e.stopImmediatePropagation();
}
});
});
export function filterIsInViewport(node) {
const rect = node.getBoundingClientRect();

return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { frameworks, urlV2, initSurvey } from "../helper";
import { frameworks, urlV2, initSurvey } from "./helper";
import { fixture, Selector, test } from "testcafe";
import { axeCheck, createReport } from "axe-testcafe";
const title = "navigation";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { frameworks, url, initSurvey } from "../helper";
import { frameworks, url, initSurvey } from "./helper";
import { fixture, test } from "testcafe";
import { axeCheck, createReport } from "axe-testcafe";
const title = "textbase";
Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@
"visual-regression-tests:file": "testcafe chrome:headless --app \"http-server\" ./visualRegressionTests/tests/defaultV2/paneldynamic.ts --screenshots ./ --reporter minimal --selector-timeout 1500",
"visual-regression-tests:ci:vue3": "testcafe -c 4 -q attemptLimit=5,successThreshold=1 chrome:headless ./visualRegressionTests/ --app \"npm run preview --prefix ./packages/survey-vue3-ui/example\" --screenshots ./ --selector-timeout 1500 --reporter minimal --env=vue3",
"visual-regression-tests:vue3": "testcafe -c 4 -q chrome ./visualRegressionTests/ --app \"npm run preview --prefix ./packages/survey-vue3-ui/example\" --screenshots ./ --selector-timeout 1500 --reporter minimal --env=vue3",
"accessibility-tests": "testcafe chrome ./accessibilityTests/ --app \"http-server\" --screenshots ./ --reporter minimal --selector-timeout 1500",
"accessibility-tests:ci:knockout": "testcafe -c 4 -q attemptLimit=5,successThreshold=1 chrome:headless ./accessibilityTests/ --app \"http-server\" --screenshots ./ --selector-timeout 1500 --reporter minimal --env=knockout",
"accessibility-tests:ci:angular": "testcafe -c 4 -q attemptLimit=5,successThreshold=1 chrome:headless ./accessibilityTests/ --app \"http-server ./packages/survey-angular-ui/example/dist --proxy http://localhost:8080? -p 8080\" --screenshots ./ --selector-timeout 1500 --reporter minimal --env=angular",
"accessibility-tests:ci:react": "testcafe -c 4 -q attemptLimit=5,successThreshold=1 chrome:headless ./accessibilityTests/ --app \"http-server\" --screenshots ./ --selector-timeout 1500 --reporter minimal --env=react",
"accessibility-tests:ci:vue": "testcafe -c 4 -q attemptLimit=5,successThreshold=1 chrome:headless ./accessibilityTests/ --app \"http-server\" --screenshots ./ --selector-timeout 1500 --reporter minimal --env=vue",
"accessibility-tests:ci:vue3": "testcafe -c 4 -q attemptLimit=5,successThreshold=1 chrome:headless ./accessibilityTests/ --app \"npm run preview --prefix ./packages/survey-vue3-ui/example\" --screenshots ./ --selector-timeout 1500 --reporter minimal --env=vue3",
"testcafe:ci:vue3": "testcafe -c 4 -q attemptLimit=5,successThreshold=1 chrome:headless testCafe/ --app \"npm run preview --prefix ./packages/survey-vue3-ui/example\" --selector-timeout 1500 --reporter minimal --env=vue3",
"testcafe:vue3": "testcafe chrome testCafe/ --app \"npm run preview --prefix ./packages/survey-vue3-ui/example \" --selector-timeout 1500 --reporter minimal --env=vue3",
"testcafe:angular": "testcafe chrome testCafe/ --app \"http-server ./packages/survey-angular-ui/example/dist --proxy http://localhost:8080? -p 8080\" --selector-timeout 1500 --reporter minimal --env=angular",
Expand Down Expand Up @@ -196,4 +202,4 @@
"signature_pad": "^4.1.5",
"vite": "^3.1.8"
}
}
}

0 comments on commit 5c9c54d

Please sign in to comment.