Skip to content

Commit ad0290c

Browse files
author
Mykhailo Miroshnikov
committed
Merge branch 'MAGETWO-33502' of github.corp.ebay.com:magento-vanilla/magento2ce into MAGETWO-33502
2 parents 79c8459 + 85691be commit ad0290c

File tree

17 files changed

+412
-75
lines changed

17 files changed

+412
-75
lines changed

app/code/Magento/Ui/view/base/templates/form/default.phtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
/**
77
* @var \Magento\Ui\Component\Form $block
88
*/
9+
$formConfig = $block->getRenderContext()->getConfigBuilder()->toJsonNew($block->getRenderContext()->getStorage());
910
?>
1011
<script type="text/x-magento-init">
1112
{
1213
"*": {
13-
"Magento_Ui/js/core/app": <?php echo $block->getRenderContext()->getConfigBuilder()->toJsonNew($block->getRenderContext()->getStorage()); ?>
14+
"Magento_Ui/js/core/app": <?php echo $formConfig; ?>
1415
}
1516
}
1617
</script>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Copyright © 2015 Magento. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
define([], function () {
6+
'use strict';
7+
8+
/**
9+
* Function used to be a placeholder for mage-init directive.
10+
*/
11+
function fn() {
12+
fn.testCallback.apply(fn, arguments);
13+
}
14+
15+
/**
16+
* Function whose call wll be tested.
17+
*/
18+
fn.testCallback = function () {};
19+
20+
return fn;
21+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"base": {
3+
"nodeId": "mage-init-node",
4+
"dataAttr": "data-mage-init",
5+
"containerId": "test-suite-container"
6+
},
7+
"fn": {
8+
"nodeData": {
9+
"tests/assets/apply/components/fn": {
10+
"baz": "foo"
11+
}
12+
},
13+
"timeout": 20
14+
}
15+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Copyright © 2015 Magento. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
define([
6+
'tests/tools',
7+
'tests/assets/apply/components/fn',
8+
'text!./config.json',
9+
'text!./templates/node.html'
10+
], function (tools, fnComponent, config, nodeTmpl) {
11+
'use strict';
12+
13+
var preset;
14+
15+
preset = tools.init(config, {
16+
'fn': nodeTmpl
17+
});
18+
19+
preset.fn.component = fnComponent;
20+
21+
return preset;
22+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!--
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
<div id="<%= containerId %>">
8+
<div id="<%= nodeId %>"
9+
<%= dataAttr %>='<%= JSON.stringify(nodeData) %>'></div>
10+
</div>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"base": {
3+
"containerId": "test-suite-container",
4+
"dataAttr": "data-mage-init"
5+
},
6+
"virtual": {
7+
"scriptData": {
8+
"*": {
9+
"tests/assets/script/component": {
10+
"config": {
11+
"foo": "bar"
12+
}
13+
}
14+
}
15+
},
16+
"scriptId": "virtual-selector"
17+
},
18+
"bySelector": {
19+
"nodeData": {
20+
"tests/assets/script/component": {
21+
"data": {
22+
"foo": {
23+
"baz": "foo"
24+
}
25+
}
26+
}
27+
},
28+
"scriptData": {
29+
"#node-by-selector": {
30+
"tests/assets/script/component": {
31+
"data": {
32+
"foo": {
33+
"bar": "baz"
34+
}
35+
}
36+
}
37+
}
38+
},
39+
"merged": {
40+
"tests/assets/script/component": {
41+
"data": {
42+
"foo": {
43+
"baz": "foo",
44+
"bar": "baz"
45+
}
46+
}
47+
}
48+
},
49+
"nodeId": "node-by-selector"
50+
}
51+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Copyright © 2015 Magento. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
define([
6+
'tests/tools',
7+
'text!./config.json',
8+
'text!./templates/selector.html',
9+
'text!./templates/virtual.html'
10+
], function (tools, config, selectorTmpl, virtualTmpl) {
11+
'use strict';
12+
13+
return tools.init(config, {
14+
bySelector: selectorTmpl,
15+
virtual: virtualTmpl
16+
});
17+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!--
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
<div id="<%= containerId %>">
8+
<div
9+
id="<%= nodeId %>"
10+
<%= dataAttr %>='<%= JSON.stringify(nodeData) %>'></div>
11+
12+
<script type="text/x-magento-init">
13+
<%= JSON.stringify(scriptData) %>
14+
</script>
15+
</div>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!--
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
<div id="<%= containerId %>">
8+
<script id="<%= scriptId %>" type="text/x-magento-init">
9+
<%= JSON.stringify(scriptData) %>
10+
</script>
11+
</div>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* Copyright © 2015 Magento. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
define([
6+
'underscore',
7+
'tests/tools',
8+
'tests/assets/apply/index',
9+
'mage/apply/main'
10+
], function (_, tools, config, mage) {
11+
'use strict';
12+
13+
describe('mage/apply/main', function () {
14+
var body = document.body;
15+
16+
afterEach(function () {
17+
tools.removeContainer(config.base.containerId);
18+
});
19+
20+
it('exports object', function () {
21+
expect(_.isFunction(mage) || _.isObject(mage)).toBe(true);
22+
});
23+
24+
it('removes data-mage-init attribute affter processing', function () {
25+
var preset = config.fn,
26+
elem;
27+
28+
/**
29+
* Checks if element has data attribute.
30+
*
31+
* @returns {Boolean}
32+
*/
33+
function hasAttr() {
34+
return elem.hasAttribute(preset.dataAttr);
35+
}
36+
37+
body.insertAdjacentHTML('beforeend', preset.tmpl);
38+
39+
elem = document.getElementById(preset.nodeId);
40+
41+
expect(hasAttr()).toBe(true);
42+
43+
mage.apply();
44+
45+
expect(hasAttr()).toBe(false);
46+
});
47+
48+
it('calls function returned from module', function (done) {
49+
var preset = config.fn,
50+
node;
51+
52+
spyOn(preset.component, 'testCallback').and.callThrough();
53+
54+
body.insertAdjacentHTML('beforeend', preset.tmpl);
55+
56+
node = document.getElementById(preset.nodeId);
57+
58+
mage.apply();
59+
60+
setTimeout(function () {
61+
expect(preset.component.testCallback)
62+
.toHaveBeenCalledWith(jasmine.any(Object), node);
63+
64+
done();
65+
}, preset.timeout);
66+
});
67+
});
68+
});

0 commit comments

Comments
 (0)