Skip to content

Commit

Permalink
fix: #38 + additional selenium unmet issue
Browse files Browse the repository at this point in the history
  • Loading branch information
eavichay committed Mar 15, 2018
1 parent 1999c4a commit 86ba9d7
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Slim.es6.js

Large diffs are not rendered by default.

25 changes: 16 additions & 9 deletions Slim.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
isWCSupported: 'customElements' in window && 'import' in document.createElement('link') && 'content' in document.createElement('template'),
isIE11: !!window['MSInputMethodContext'] && !!document['documentMode'],
isChrome: undefined,
isEdge: undefined
isEdge: undefined,
isSafari: undefined
};

try {
__flags.isChrome = /Chrome/.test(navigator.userAgent);
__flags.isEdge = /Edge/.test(navigator.userAgent);
__flags.isSafari = /Safari/.test(navigator.userAgent);

if (__flags.isIE11 || __flags.isEdge) {
__flags.isChrome = false;
Expand Down Expand Up @@ -403,12 +405,17 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons

var _this = _possibleConstructorReturn(this, (Slim.__proto__ || Object.getPrototypeOf(Slim)).call(this));

_this.__isSlim = true;
Slim.debug('ctor', _this.localName);
if (Slim.checkCreationBlocking(_this)) {
return _possibleConstructorReturn(_this);
}
_this.createdCallback();
var init = function init() {
_this.__isSlim = true;
Slim.debug('ctor', _this.localName);
if (Slim.checkCreationBlocking(_this)) {
return;
}
_this.createdCallback();
};
if (__flags.isSafari) {
Slim.asap(init);
} else init();
return _this;
}

Expand Down Expand Up @@ -936,7 +943,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
}
});

__flags.isChrome && Slim.customDirective(function (attr) {
!__flags.isIE11 && Slim.customDirective(function (attr) {
return attr.nodeName === 's:repeat';
}, function (source, templateNode, attribute) {
var path = attribute.value;
Expand Down Expand Up @@ -1041,7 +1048,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
source[_$2].reversed[tProp] = true;
}, true);

!__flags.isChrome && Slim.customDirective(function (attr) {
__flags.isIE11 && Slim.customDirective(function (attr) {
return (/^s:repeat$/.test(attr.nodeName)
);
}, function (source, templateNode, attribute) {
Expand Down
2 changes: 1 addition & 1 deletion Slim.min.js

Large diffs are not rendered by default.

23 changes: 15 additions & 8 deletions src/Slim.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
'content' in document.createElement('template'),
isIE11: !!window['MSInputMethodContext'] && !!document['documentMode'],
isChrome: undefined,
isEdge: undefined
isEdge: undefined,
isSafari: undefined
}

try {
__flags.isChrome = /Chrome/.test(navigator.userAgent)
__flags.isEdge = /Edge/.test(navigator.userAgent)
__flags.isSafari = /Safari/.test(navigator.userAgent)

if (__flags.isIE11 || __flags.isEdge) {
__flags.isChrome = false
Expand Down Expand Up @@ -290,12 +292,17 @@

constructor () {
super()
this.__isSlim = true
Slim.debug('ctor', this.localName)
if (Slim.checkCreationBlocking(this)) {
return
const init = () => {
this.__isSlim = true
Slim.debug('ctor', this.localName)
if (Slim.checkCreationBlocking(this)) {
return
}
this.createdCallback()
}
this.createdCallback()
if (__flags.isSafari) {
Slim.asap(init);
} else init();
}

// Native DOM Api V1
Expand Down Expand Up @@ -702,7 +709,7 @@
}
})

__flags.isChrome && Slim.customDirective(attr => attr.nodeName === 's:repeat', (source, templateNode, attribute) => {
!__flags.isIE11 && Slim.customDirective(attr => attr.nodeName === 's:repeat', (source, templateNode, attribute) => {
let path = attribute.value
let tProp = 'data'
if (path.indexOf(' as' )) {
Expand Down Expand Up @@ -802,7 +809,7 @@
source[_$].reversed[tProp] = true
}, true)

!__flags.isChrome && Slim.customDirective(attr => /^s:repeat$/.test(attr.nodeName), (source, templateNode, attribute) => {
__flags.isIE11 && Slim.customDirective(attr => /^s:repeat$/.test(attr.nodeName), (source, templateNode, attribute) => {
let path = attribute.nodeValue
let tProp = 'data'
if (path.indexOf(' as' )) {
Expand Down
8 changes: 6 additions & 2 deletions tests/find.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ module.exports = {
},

find: function(browser) {
// this workaround is needed since chrome driver for chrome 65+ has selenium issue
const setValueWorkaround = function(selector, value) {
document.querySelector(selector).value = value;
};
browser.waitForElementPresent('body');
browser.waitForElementPresent('test-find');
browser.useCss().waitForElementPresent('test-find::shadow #output');
browser.setValue('test-find::shadow #inp', 'after');
browser.execute(setValueWorkaround, ['test-find::shadow #inp', 'after']);
browser.click('test-find::shadow #btn');
browser.waitForElementPresent('test-find::shadow #output');
browser.assert.containsText('test-find::shadow #output', 'after');

}
};
17 changes: 13 additions & 4 deletions tests/repeater.test.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="../src/Slim.js"></script>
<script src="../Slim.js"></script>
</head>
<body>
<repeater-test>
</repeater-test>

<script>
Slim.debug = console.log;
Slim.tag('repeater-child', '<span bind:prop="item.label" bind>{{item.text}}</span>', class extends Slim {});
Slim.tag('repeater-child', '<span bind:prop="item.label" bind>{{item.text}}</span>', Slim);
Slim.tag('n-r', `
<div bind:title="item.title" bind>{{item.title}}</div>
<ul>
Expand All @@ -23,10 +23,14 @@
})
Slim.tag(`repeater-test`,
`
<select change="handleChange">
<option s:repeat="items as item" bind bind:value="item.text">{{title}} > {{item.label}}</option>
</select>
<h2 bind>{{dataValue}}</h2>
<ul>
<li s:repeat="items" bind:iteration="getIndex(data)" bind>{{title}} > {{data.label}} >> {{reverse(data.label)}}</li>
</ul>
<repeater-child s:repeat="items as item"></repeater-child>
<repeater-child s:repeat="items as item" bind:item-id="data-index"></repeater-child>
<n-r s:repeat="nested as item"></n-r>
`,

Expand All @@ -36,13 +40,18 @@
window.unit = this;
}

handleChange (e) {
this.dataValue = e.target.value;
}

onBeforeCreated() {
this.title = 'Hello'
this.items = [
{ label: "item 0", text: "text 0" },
{ label: "item 1", text: "text 1" },
{ label: "item 2", text: "text 2" }
];
this.dataValue = this.items[0].text;
this.nested = [
{ title: '1', children: [
{ title: '1.1', children: [] },
Expand All @@ -63,7 +72,7 @@
}

reverse(value) {
return value.split('').reverse().join('')
return value ? value.split('').reverse().join('') : '';
}

addOne() {
Expand Down
10 changes: 10 additions & 0 deletions tests/repeater.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ module.exports = {
repeater: function(browser) {
browser.waitForElementPresent('body');
browser.waitForElementPresent('repeater-test');

browser.waitForElementPresent('select');
browser.waitForElementPresent('option[value="text 0"]');
browser.waitForElementPresent('option[value="text 1"]');
browser.waitForElementPresent('option[value="text 2"]');

browser.assert.containsText('h2', 'text 0');
browser.click('select');
browser.click('option[value="text 2"]');
browser.assert.containsText('h2', 'text 2');
browser.waitForElementPresent('ul');
browser.assert.containsText('li[iteration="0"]', "item 0");
browser.assert.containsText('li[iteration="1"]', "item 1");
Expand Down

0 comments on commit 86ba9d7

Please sign in to comment.