Skip to content

Commit e680364

Browse files
committed
Advanced tests
1 parent f650d40 commit e680364

File tree

5 files changed

+91
-229
lines changed

5 files changed

+91
-229
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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, test} from '@playwright/test';
19+
import {getProp} from "./util";
20+
21+
test.beforeEach(async ({page}) => {
22+
await page.goto('/react');
23+
})
24+
25+
test.describe('advanced support', () => {
26+
test.describe('attributes and properties', () => {
27+
test('will pass array data as a property', async ({page}) => {
28+
const ce = page.locator('#ce-with-properties');
29+
expect(await getProp(ce, 'arr')).toEqual(['R', 'e', 'a', 'c', 't'])
30+
})
31+
32+
test('will pass object data as a property', async ({page}) => {
33+
const ce = page.locator('#ce-with-properties');
34+
expect(await getProp(ce, 'obj')).toEqual({org: "facebook", repo: "react"})
35+
})
36+
37+
test("will pass object data to a camelCase-named property", async ({page}) => {
38+
const ce = page.locator('#ce-with-properties');
39+
expect(await getProp(ce, 'camelCaseObj')).toEqual({label: "passed"})
40+
})
41+
});
42+
43+
test.describe('events', () => {
44+
45+
test("can declaratively listen to a lowercase DOM event dispatched by a Custom Element", async ({page}) => {
46+
const ce = page.locator('#ce-with-declarative-event');
47+
await expect(page.getByText(/lowercase:/)).toHaveText(/false/);
48+
await ce.click();
49+
await expect(page.getByText(/lowercase:/)).toHaveText(/true/);
50+
})
51+
52+
test("can declaratively listen to a camelCase DOM event dispatched by a Custom Element", async ({page}) => {
53+
const ce = page.locator('#ce-with-declarative-event');
54+
await expect(page.getByText(/camelCase:/)).toHaveText(/false/);
55+
await ce.click();
56+
await expect(page.getByText(/camelCase:/)).toHaveText(/true/);
57+
})
58+
test("can declaratively listen to a kebab-case DOM event dispatched by a Custom Element", async ({page}) => {
59+
const ce = page.locator('#ce-with-declarative-event');
60+
await expect(page.getByText(/kebab-case:/)).toHaveText(/false/);
61+
await ce.click();
62+
await expect(page.getByText(/kebab-case:/)).toHaveText(/true/);
63+
})
64+
test("can declaratively listen to a CAPScase DOM event dispatched by a Custom Element", async ({page}) => {
65+
const ce = page.locator('#ce-with-declarative-event');
66+
await expect(page.getByText(/CAPScase:/)).toHaveText(/false/);
67+
await ce.click();
68+
await expect(page.getByText(/CAPScase:/)).toHaveText(/true/);
69+
})
70+
test("can declaratively listen to a PascalCase DOM event dispatched by a Custom Element", async ({page}) => {
71+
const ce = page.locator('#ce-with-declarative-event');
72+
await expect(page.getByText(/PascalCase:/)).toHaveText(/false/);
73+
await ce.click();
74+
await expect(page.getByText(/PascalCase:/)).toHaveText(/true/);
75+
})
76+
});
77+
})

libraries/__shared__/tests/basic-tests.test.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
import {expect, test} from '@playwright/test';
19+
import {getPropOrAttr} from './util';
1920

2021
test.beforeEach(async ({page}) => {
2122
await page.goto('/react');
@@ -60,12 +61,6 @@ test.describe("basic support", () => {
6061
});
6162

6263
test.describe('attributes and properties', () => {
63-
const getPropOrAttr = async (ce, name) => {
64-
const prop = await (await (await ce.elementHandle()).getProperty(name)).jsonValue()
65-
const attr = ce.getAttribute(name);
66-
return prop ?? attr;
67-
}
68-
6964
test("will pass boolean data as either an attribute or a property", async ({page}) => {
7065
const ce = page.locator('#ce-with-properties');
7166
expect(await getPropOrAttr(ce, 'bool')).toEqual(true)

libraries/__shared__/tests/util.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const getProp = async (ce, name) => {
2+
return await (await (await ce.elementHandle()).getProperty(name)).jsonValue()
3+
}
4+
5+
export const getPropOrAttr = async (ce, name) => {
6+
return await getProp(ce, name) ?? ce.getAttribute(name);
7+
}

libraries/react/src/advanced-tests.js

Lines changed: 0 additions & 217 deletions
This file was deleted.

libraries/react/src/components.jsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,18 +197,18 @@ export class ComponentWithDeclarativeEvent extends Component {
197197
let state = this.state;
198198
return (
199199
<div>
200-
<div ref={(el) => this.lowercase = el}>{state.lowercaseHandled.toString()}</div>
201-
<div ref={(el) => this.kebab = el}>{state.kebabHandled.toString()}</div>
202-
<div ref={(el) => this.camel = el}>{state.camelHandled.toString()}</div>
203-
<div ref={(el) => this.caps = el}>{state.capsHandled.toString()}</div>
204-
<div ref={(el) => this.pascal = el}>{state.pascalHandled.toString()}</div>
200+
<div ref={(el) => this.lowercase = el}>lowercase: {state.lowercaseHandled.toString()}</div>
201+
<div ref={(el) => this.kebab = el}>kebab-case: {state.kebabHandled.toString()}</div>
202+
<div ref={(el) => this.camel = el}>camelCase: {state.camelHandled.toString()}</div>
203+
<div ref={(el) => this.caps = el}>CAPScase: {state.capsHandled.toString()}</div>
204+
<div ref={(el) => this.pascal = el}>PascalCase: {state.pascalHandled.toString()}</div>
205205
<ce-with-event id="ce-with-declarative-event"
206206
onlowercaseevent={this.handleLowercaseEvent}
207207
onkebab-event={this.handleKebabEvent}
208208
oncamelEvent={this.handleCamelEvent}
209209
onCAPSevent={this.handleCapsEvent}
210210
onPascalEvent={this.handlePascalEvent}
211-
></ce-with-event>
211+
>Declarative</ce-with-event>
212212
</div>
213213
);
214214
}

0 commit comments

Comments
 (0)