Skip to content

Commit 2f5c6be

Browse files
committed
Move riot tests to use common tests
1 parent 93718b7 commit 2f5c6be

File tree

9 files changed

+393
-208
lines changed

9 files changed

+393
-208
lines changed

libraries/__shared__/tests/package-lock.json

Lines changed: 111 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "tests",
3+
"version": "1.0.0",
4+
"description": "",
5+
"author": "",
6+
"license": "ISC",
7+
"devDependencies": {
8+
"chai": "4.3.10"
9+
}
10+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/**
2+
* @license
3+
* Copyright 2017 Google Inc. All rights reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import { expect } from 'chai'
19+
20+
21+
function skip() {
22+
this.skip();
23+
return {};
24+
}
25+
export default function (
26+
{
27+
renderComponentWithProperties = skip,
28+
renderComponentWithDeclarativeEvent = skip
29+
}
30+
) {
31+
32+
33+
describe('advanced support', function () {
34+
35+
describe('attributes and properties', function () {
36+
it('will pass array data as a property', async function () {
37+
this.weight = 2
38+
const { wc } = await renderComponentWithProperties.call(this)
39+
let data = wc.arr
40+
expect(data).to.eql(['r', 'i', 'o', 't'])
41+
})
42+
43+
it('will pass object data as a property', async function () {
44+
this.weight = 2
45+
const { wc } = await renderComponentWithProperties.call(this)
46+
let data = wc.obj
47+
expect(data).to.eql({org: 'riotjs', repo: 'riot'})
48+
})
49+
50+
it('will pass object data to a camelCase-named property', async function () {
51+
this.weight = 2
52+
const { wc } = await renderComponentWithProperties.call(this)
53+
let data = wc.camelCaseObj;
54+
expect(data).to.eql({label: "passed"});
55+
})
56+
57+
})
58+
59+
describe('events', function () {
60+
it('can declaratively listen to a lowercase DOM event dispatched by a Custom Element', async function () {
61+
this.weight = 2
62+
const { wc } = await renderComponentWithDeclarativeEvent.call(this)
63+
expect(wc).to.exist
64+
let handled = document.querySelector('#lowercase')
65+
expect(handled.textContent).to.eql('false')
66+
wc.click()
67+
expect(handled.textContent).to.eql('true')
68+
})
69+
70+
it('can declaratively listen to a kebab-case DOM event dispatched by a Custom Element', async function () {
71+
this.weight = 1
72+
const { wc } = await renderComponentWithDeclarativeEvent.call(this)
73+
let handled = document.querySelector('#kebab')
74+
expect(handled.textContent).to.eql('false')
75+
wc.click()
76+
expect(handled.textContent).to.eql('true')
77+
})
78+
79+
it('can declaratively listen to a camelCase DOM event dispatched by a Custom Element', async function () {
80+
this.weight = 1
81+
const { wc } = await renderComponentWithDeclarativeEvent.call(this)
82+
let handled = document.querySelector('#camel')
83+
expect(handled.textContent).to.eql('false')
84+
wc.click()
85+
expect(handled.textContent).to.eql('true')
86+
})
87+
88+
it('can declaratively listen to a CAPScase DOM event dispatched by a Custom Element', async function () {
89+
this.weight = 1
90+
const { wc } = await renderComponentWithDeclarativeEvent.call(this)
91+
let handled = document.querySelector('#caps')
92+
expect(handled.textContent).to.eql('false')
93+
wc.click()
94+
expect(handled.textContent).to.eql('true')
95+
})
96+
97+
it('can declaratively listen to a PascalCase DOM event dispatched by a Custom Element', async function () {
98+
this.weight = 1
99+
const { wc } = await renderComponentWithDeclarativeEvent.call(this)
100+
let handled = document.querySelector('#pascal')
101+
expect(handled.textContent).to.eql('false')
102+
wc.click()
103+
expect(handled.textContent).to.eql('true')
104+
})
105+
})
106+
})
107+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/**
2+
* @license
3+
* Copyright 2017 Google Inc. All rights reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import {expect} from 'chai'
19+
20+
function skip() {
21+
this.skip();
22+
return {};
23+
}
24+
25+
export default function (
26+
{
27+
renderComponentWithoutChildren = skip,
28+
renderComponentWithChildren = skip,
29+
renderComponentWithChildrenRerender = skip,
30+
renderComponentWithDifferentViews = skip,
31+
renderComponentWithProperties = skip,
32+
renderComponentWithImperativeEvent = skip,
33+
}) {
34+
35+
describe('basic support', function () {
36+
37+
describe('no children', function () {
38+
it('can display a Custom Element with no children', async function () {
39+
this.weight = 3
40+
const { wc } = await renderComponentWithoutChildren.call(this);
41+
expect(wc).to.exist
42+
})
43+
})
44+
45+
describe('with children', function () {
46+
function expectHasChildren(wc) {
47+
expect(wc).to.exist
48+
let shadowRoot = wc.shadowRoot
49+
let heading = shadowRoot.querySelector('h1')
50+
expect(heading).to.exist
51+
expect(heading.textContent).to.eql('Test h1')
52+
let paragraph = shadowRoot.querySelector('p')
53+
expect(paragraph).to.exist
54+
expect(paragraph.textContent).to.eql('Test p')
55+
}
56+
57+
it('can display a Custom Element with children in a Shadow Root', async function () {
58+
this.weight = 3
59+
const { wc } = await renderComponentWithChildren.call(this);
60+
expectHasChildren(wc)
61+
})
62+
63+
it('can display a Custom Element with children in a Shadow Root and pass in Light DOM children', async function () {
64+
this.weight = 3
65+
const { wc } = await renderComponentWithChildrenRerender.call(this);
66+
expectHasChildren(wc)
67+
expect(wc.textContent.includes('2')).to.be.true
68+
})
69+
70+
it('can display a Custom Element with children in the Shadow DOM and handle hiding and showing the element', async function () {
71+
this.weight = 3
72+
const { wc, toggle } = await renderComponentWithDifferentViews.call(this);
73+
expectHasChildren(wc)
74+
toggle()
75+
let dummy = document.querySelector('#dummy')
76+
expect(dummy).to.exist
77+
expect(dummy.textContent).to.eql('Dummy view')
78+
toggle()
79+
expectHasChildren(wc)
80+
})
81+
})
82+
83+
describe('attributes and properties', function () {
84+
it('will pass boolean data as either an attribute or a property', async function () {
85+
this.weight = 3
86+
const { wc } = await renderComponentWithProperties.call(this);
87+
let data = wc.bool || wc.hasAttribute('bool')
88+
expect(data).to.be.true
89+
})
90+
91+
it('will pass numeric data as either an attribute or a property', async function () {
92+
this.weight = 3
93+
const { wc } = await renderComponentWithProperties.call(this);
94+
let data = wc.num || wc.getAttribute('num')
95+
expect(parseInt(data, 10)).to.eql(42)
96+
})
97+
98+
it('will pass string data as either an attribute or a property', async function () {
99+
this.weight = 3
100+
const { wc } = await renderComponentWithProperties.call(this);
101+
let data = wc.str || wc.getAttribute('str')
102+
expect(data).to.eql('riot')
103+
})
104+
})
105+
106+
describe('events', async function () {
107+
it('can imperatively listen to a DOM event dispatched by a Custom Element', async function () {
108+
this.weight = 3
109+
const { wc } = await renderComponentWithImperativeEvent.call(this)
110+
expect(wc).to.exist
111+
let handled = document.querySelector('#handled')
112+
expect(handled.textContent).to.eql('false')
113+
wc.click()
114+
expect(handled.textContent).to.eql('true')
115+
})
116+
})
117+
})
118+
}

libraries/riot/karma.conf.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ module.exports = function(config) {
6161
resolve: {
6262
modules: [
6363
path.resolve(__dirname, '../__shared__/webcomponents/src'),
64+
path.resolve(__dirname, '../__shared__/tests/src'),
6465
path.resolve(__dirname, './node_modules')
6566
]
6667
},

0 commit comments

Comments
 (0)