integration.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. window.__karma__.loaded = function () { };
  2. window.validation = true;
  3. window.onload = function () {
  4. // Loading tests
  5. var xhr = new XMLHttpRequest();
  6. xhr.open("GET", "/tests/validation/config.json", true);
  7. xhr.addEventListener("load", function () {
  8. if (xhr.status === 200) {
  9. config = JSON.parse(xhr.responseText);
  10. config.tests.forEach(function (test, index) {
  11. if (test.repeatVariables) {
  12. let paramsArray = [];
  13. var variables = test.repeatVariables.split(",");
  14. var repeatTimes = test.repeatTimes.split(",").map(s => +s);
  15. for (var i = 0; i < repeatTimes[0]; ++i) {
  16. if (repeatTimes[1]) {
  17. for (var j = 0; j < repeatTimes[1]; ++j) {
  18. var obj = {};
  19. obj[variables[0]] = i;
  20. obj[variables[1]] = j;
  21. paramsArray.push(obj);
  22. }
  23. } else {
  24. var obj = {};
  25. obj[variables[0]] = i;
  26. paramsArray.push(obj);
  27. }
  28. }
  29. paramsArray.forEach(function (params) {
  30. let newTest = processTest(test, "", params);
  31. delete newTest.repeatVariables;
  32. config.tests.push(newTest);
  33. });
  34. }
  35. });
  36. describe("Validation Tests", function () {
  37. // Run tests
  38. config.tests.forEach(function (test, index) {
  39. if (test.repeatVariables || test.onlyVisual || test.excludeFromAutomaticTesting) {
  40. return;
  41. }
  42. it(test.title, function (done) {
  43. this.timeout(60000);
  44. var self = this;
  45. var deferredDone = function (err) {
  46. setTimeout(function () {
  47. done(err);
  48. }, 1000);
  49. }
  50. try {
  51. runTest(index, function (result, screenshot) {
  52. try {
  53. expect(result).to.be.true;
  54. deferredDone();
  55. }
  56. catch (e) {
  57. if (screenshot) {
  58. //console.error(screenshot);
  59. }
  60. deferredDone(e);
  61. }
  62. });
  63. }
  64. catch (e) {
  65. deferredDone(e);
  66. }
  67. });
  68. });
  69. });
  70. window.__karma__.start();
  71. }
  72. }, false);
  73. xhr.send();
  74. }
  75. function processTest(test, key, params) {
  76. if (!key) {
  77. let testCopy = Object.assign({}, test);
  78. Object.keys(testCopy).forEach(testKey => {
  79. testCopy[testKey] = processTest(testCopy, testKey, params);
  80. });
  81. return testCopy;
  82. } else {
  83. if (typeof test[key] === "object") {
  84. let testCopy = Object.assign({}, test[key]);
  85. Object.keys(testCopy).forEach(testKey => {
  86. testCopy[testKey] = processTest(testCopy, testKey, params);
  87. });
  88. return testCopy;
  89. } else if (typeof test[key] === "string") {
  90. let evals = test[key].match(/{{\s*([^{}]+)\s*}}/g);
  91. if (evals) {
  92. let clean = evals.map(function (x) { var s = x.replace(/}/g, "").replace(/{/g, ""); return s; });
  93. evals.forEach((ev, idx) => {
  94. var valuated = clean[idx];
  95. Object.keys(params).forEach(p => {
  96. valuated = valuated.replace(p, "" + params[p]);
  97. });
  98. valuated = eval(valuated);
  99. test[key] = test[key].replace(ev, valuated);
  100. });
  101. test[key] = parseFloat(test[key]) || test[key];
  102. }
  103. return test[key];
  104. }
  105. else return test[key];
  106. }
  107. }