Skip to content

Commit

Permalink
Add test for new terser markup function
Browse files Browse the repository at this point in the history
* Add automated test for new terser markup function which brings the
  total test count to 197.
  • Loading branch information
puckowski committed Oct 28, 2023
1 parent 59103b5 commit aea0026
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 8 deletions.
1 change: 1 addition & 0 deletions dist/todo.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
<div id="divdetectthen1"></div>
<div id="divtestrefcomp1"></div>
<div id="divsvgtest1"></div>
<div id="divtersermarkup1"></div>
<div id="divhydrateslfor1" slssrclass="HydrateSlForComponent1"><div slfor="hydratefor:list:makeRow:updateRow"><p>a</p><p>b</p><p>c</p></div></div>
<div class="container" id="divrenderhydrate" slssrclass="TestRenderHydrate1"><table class="table table-hover table-striped test-data"><tbody slfor="myfor:data:makeRow:updateRow"><tr onclick="" onremove=""><td class="col-md-1">1</td><td class="col-md-4"><a href="#" onclick="">clean purple car</a></td><td class="col-md-1"><a href="#" onclick=""><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a></td><td class="col-md-6"></td></tr><tr onclick="" onremove=""><td class="col-md-1">2</td><td class="col-md-4"><a href="#" onclick="">easy brown pizza</a></td><td class="col-md-1"><a href="#" onclick=""><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a></td><td class="col-md-6"></td></tr><tr onclick="" onremove=""><td class="col-md-1">3</td><td class="col-md-4"><a href="#" onclick="">easy white house</a></td><td class="col-md-1"><a href="#" onclick=""><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a></td><td class="col-md-6"></td></tr><tr onclick="" onremove=""><td class="col-md-1">4</td><td class="col-md-4"><a href="#" onclick="">helpful white pizza</a></td><td class="col-md-1"><a href="#" onclick=""><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a></td><td class="col-md-6"></td></tr><tr onclick="" onremove=""><td class="col-md-1">5</td><td class="col-md-4"><a href="#" onclick="">helpful yellow cookie</a></td><td class="col-md-1"><a href="#" onclick=""><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a></td><td class="col-md-6"></td></tr><tr onclick="" onremove=""><td class="col-md-1">6</td><td class="col-md-4"><a href="#" onclick="">tall pink car</a></td><td class="col-md-1"><a href="#" onclick=""><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a></td><td class="col-md-6"></td></tr></tbody></table></div>
<div slssrclass="TestSsrHydrateComponent1" id="testssrhydrate"><button id="ssrTest2" onclick="someFunc()">Test Hydrate</button><div id="ssrTest1">SSR placeholder.</div></div>
Expand Down
4 changes: 2 additions & 2 deletions dist_sling/sling.es5.js
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ var l = function l(_ref3) {
}), t;
};
function version() {
return "20.2.0";
return "20.3.0";
}
var E = function E(t, e) {
return t.split(e).length - 1;
Expand Down Expand Up @@ -906,7 +906,7 @@ function markup(t) {
};
}
function m() {
return "string" == typeof arguments[0] && "object" == _typeof(arguments[1]) && Array.isArray(arguments[2]) ? markup(arguments[0], {
return 3 === arguments.length && "string" == typeof arguments[0] && "object" == _typeof(arguments[1]) && Array.isArray(arguments[2]) ? markup(arguments[0], {
attrs: arguments[1],
children: arguments[2]
}) : markup(arguments[0], arguments[1]);
Expand Down
2 changes: 1 addition & 1 deletion dist_sling/sling.min.es5.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist_sling/sling.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist_sling/sling.min.nomodule.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist_sling/sling.slim.min.js

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions src/globalTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,19 @@ class HelloWorldComponentAnimate {
}
}

class TestTerserMarkupOverloadComponent {
view() {
return m("div", {
id: "divtersermarkup1"
},
[
m("span", { style: 'color: blue;' }, [textNode('Blue text.')]),
textNode('Regular text.')
]
);
}
}

class TestAttributeUserProfileComponent {
constructor() {
this.id = "Unknown";
Expand Down Expand Up @@ -8568,6 +8581,29 @@ export class GlobalTestRunner {
}, 1000);
}

testFinalize300TerserMarkupFunctionOverload() {
const result = {
test: 'test terser markup function overload',
success: false,
message: ''
};

mount('divtersermarkup1', new TestTerserMarkupOverloadComponent());

const ele = document.getElementById('divtersermarkup1');

const cssObj = window.getComputedStyle(ele.childNodes[0], null);
const color = cssObj.getPropertyValue('color');

result.success = ele && ele.childNodes && ele.childNodes.length === 2 && ele.children[0] && ele.children[0].tagName === 'SPAN'
&& ele.children[0].childNodes[0].textContent === 'Blue text.'
&& ele.childNodes[1] && ele.childNodes[1].textContent === 'Regular text.'
&& color === 'rgb(0, 0, 255)';

window.globalTestResults.push(result);
window.globalTestCount++;
}

testRunLastDestroyMapNoDuplicates() {
const result = {
test: 'test destroy map contains no duplicate nodes',
Expand Down
2 changes: 1 addition & 1 deletion src/sling/core/sling.js
Original file line number Diff line number Diff line change
Expand Up @@ -1740,7 +1740,7 @@ export function markup(tagName, { attrs = {}, children = [] } = {}) {
}

export function m() {
if (typeof arguments[0] === 'string' && typeof arguments[1] === 'object' && Array.isArray(arguments[2])) {
if (arguments.length === 3 && typeof arguments[0] === 'string' && typeof arguments[1] === 'object' && Array.isArray(arguments[2])) {
return markup(arguments[0], { attrs: arguments[1], children: arguments[2] });
} else {
return markup(arguments[0], arguments[1]);
Expand Down
2 changes: 1 addition & 1 deletion src/sling/core/sling.slim.js
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ export function markup(tagName, { attrs = {}, children = [] } = {}) {
}

export function m() {
if (typeof arguments[0] === 'string' && typeof arguments[1] === 'object' && Array.isArray(arguments[2])) {
if (arguments.length === 3 && typeof arguments[0] === 'string' && typeof arguments[1] === 'object' && Array.isArray(arguments[2])) {
return markup(arguments[0], { attrs: arguments[1], children: arguments[2] });
} else {
return markup(arguments[0], arguments[1]);
Expand Down
1 change: 1 addition & 0 deletions src/todo.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
<div id="divdetectthen1"></div>
<div id="divtestrefcomp1"></div>
<div id="divsvgtest1"></div>
<div id="divtersermarkup1"></div>
<div id="divhydrateslfor1" slssrclass="HydrateSlForComponent1"><div slfor="hydratefor:list:makeRow:updateRow"><p>a</p><p>b</p><p>c</p></div></div>
<div class="container" id="divrenderhydrate" slssrclass="TestRenderHydrate1"><table class="table table-hover table-striped test-data"><tbody slfor="myfor:data:makeRow:updateRow"><tr onclick="" onremove=""><td class="col-md-1">1</td><td class="col-md-4"><a href="#" onclick="">clean purple car</a></td><td class="col-md-1"><a href="#" onclick=""><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a></td><td class="col-md-6"></td></tr><tr onclick="" onremove=""><td class="col-md-1">2</td><td class="col-md-4"><a href="#" onclick="">easy brown pizza</a></td><td class="col-md-1"><a href="#" onclick=""><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a></td><td class="col-md-6"></td></tr><tr onclick="" onremove=""><td class="col-md-1">3</td><td class="col-md-4"><a href="#" onclick="">easy white house</a></td><td class="col-md-1"><a href="#" onclick=""><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a></td><td class="col-md-6"></td></tr><tr onclick="" onremove=""><td class="col-md-1">4</td><td class="col-md-4"><a href="#" onclick="">helpful white pizza</a></td><td class="col-md-1"><a href="#" onclick=""><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a></td><td class="col-md-6"></td></tr><tr onclick="" onremove=""><td class="col-md-1">5</td><td class="col-md-4"><a href="#" onclick="">helpful yellow cookie</a></td><td class="col-md-1"><a href="#" onclick=""><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a></td><td class="col-md-6"></td></tr><tr onclick="" onremove=""><td class="col-md-1">6</td><td class="col-md-4"><a href="#" onclick="">tall pink car</a></td><td class="col-md-1"><a href="#" onclick=""><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a></td><td class="col-md-6"></td></tr></tbody></table></div>
<div slssrclass="TestSsrHydrateComponent1" id="testssrhydrate"><button id="ssrTest2" onclick="someFunc()">Test Hydrate</button><div id="ssrTest1">SSR placeholder.</div></div>
Expand Down

0 comments on commit aea0026

Please sign in to comment.