1- import { expect } from "chai" ;
1+ import { expect } from "chai" ;
22import prodApp from "./app.module" ;
33
4- describe ( "basic support" , ( ) => {
4+ import tests from 'basic-tests' ;
55
6+ describe ( '' , function ( ) {
67 beforeEach ( angular . mock . module ( prodApp ) ) ;
78
89 let compile ;
910 let scope ;
1011 let interval ;
12+
1113 beforeEach (
1214 inject ( ( $compile , $rootScope , $interval ) => {
1315 compile = $compile ;
@@ -16,115 +18,46 @@ describe("basic support", () => {
1618 } )
1719 ) ;
1820
19- describe ( "no children" , ( ) => {
20- it ( "can display a CE with no children" , function ( ) {
21- this . weight = 3 ;
22- const comp = compile ( "<comp-no-children>" ) ( scope ) ;
23- const wc = comp [ 0 ] . querySelector ( "ce-without-children" ) ;
24- expect ( wc ) . to . exist ;
25- } ) ;
26- } ) ;
27-
28- describe ( "with children" , ( ) => {
29- const prep = el => {
30- return compile ( el ) ( scope ) [ 0 ] ;
31- } ;
32- function expectHasChildren ( wc ) {
33- expect ( wc ) . to . exist ;
34- let shadowRoot = wc . shadowRoot ;
35- let heading = shadowRoot . querySelector ( "h1" ) ;
36- expect ( heading ) . to . exist ;
37- expect ( heading . textContent ) . to . eql ( "Test h1" ) ;
38- let paragraph = shadowRoot . querySelector ( "p" ) ;
39- expect ( paragraph ) . to . exist ;
40- expect ( paragraph . textContent ) . to . eql ( "Test p" ) ;
41- }
42-
43- it ( "can display a Custom Element with children in a Shadow Root" , function ( ) {
44- this . weight = 3 ;
45- const root = prep ( "<comp-with-children>" ) ;
46- let wc = root . querySelector ( "#wc" ) ;
47- expectHasChildren ( wc ) ;
48- } ) ;
49-
50- it ( "can display a Custom Element with children in a Shadow Root and pass in Light DOM children" , function ( ) {
51- this . weight = 3 ;
52- const root = prep ( "<comp-with-children-rerender>" ) ;
21+ function render ( component ) {
22+ const root = compile ( component ) ( scope ) [ 0 ] ;
23+ scope . $apply ( ) ;
24+ const wc = root . querySelector ( '#wc' ) ;
25+ return { wc, root }
26+ }
27+
28+ tests ( {
29+ renderComponentWithoutChildren ( ) {
30+ return render ( '<comp-no-children>' )
31+ } ,
32+ renderComponentWithChildren ( ) {
33+ return render ( '<comp-with-children>' )
34+ } ,
35+ renderComponentWithChildrenRerender ( ) {
36+ const result = render ( '<comp-with-children-rerender>' ) ;
5337 interval . flush ( 1000 ) ;
54- let wc = root . querySelector ( "#wc" ) ;
55- expectHasChildren ( wc ) ;
56- expect ( wc . textContent . includes ( "2" ) ) . to . be . true ;
57- } ) ;
58-
59- it ( "can display a Custom Element with children in a Shadow Root and handle hiding and showing the element" , function ( ) {
60- this . weight = 3 ;
61- scope . showWc = true ;
62- const root = prep ( `<comp-with-different-views show-wc="showWc">` ) ;
63- scope . $apply ( ) ;
64- let wc = root . querySelector ( "#wc" ) ;
65- expectHasChildren ( wc ) ;
66-
67- scope . showWc = false ;
68- scope . $apply ( ) ;
69-
70- let dummy = root . querySelector ( "#dummy" ) ;
71- expect ( dummy ) . to . exist ;
72- expect ( dummy . textContent ) . to . eql ( "Dummy view" ) ;
73-
38+ return result ;
39+ } ,
40+ renderComponentWithDifferentViews ( ) {
7441 scope . showWc = true ;
75- scope . $apply ( ) ;
42+ const { wc , root } = render ( '<comp-with-different-views show-wc="showWc">' ) ;
7643
77- wc = root . querySelector ( "#wc" ) ;
78- expectHasChildren ( wc ) ;
79- } ) ;
80- } ) ;
81-
82- describe ( "attributes and properties" , function ( ) {
83- let wc ;
84- beforeEach ( ( ) => {
85- const comp = compile ( "<comp-with-props>" ) ( scope ) ;
86- scope . $digest ( ) ;
87-
88- wc = comp [ 0 ] . querySelector ( "#wc" ) ;
89- } ) ;
90-
91- it ( "will pass boolean data as either an attribute or a property" , function ( ) {
92- this . weight = 3 ;
93- let data = wc . bool || wc . hasAttribute ( "bool" ) ;
94- expect ( data ) . to . be . true ;
95- // Extra test to see if AngularJS just left its binding syntax on
96- // the attribute and didn't actually set anything :P
97- if ( ! wc . bool ) {
98- data = wc . getAttribute ( "bool" ) ;
99- expect ( data . includes ( "{{" ) ) . to . be . false ;
44+ function toggle ( ) {
45+ scope . showWc = ! scope . showWc ;
46+ scope . $apply ( ) ;
10047 }
101- } ) ;
102-
103- it ( "will pass numeric data as either an attribute or a property" , function ( ) {
104- this . weight = 3 ;
105- let data = wc . num || wc . getAttribute ( "num" ) ;
106- expect ( parseInt ( data , 10 ) ) . to . eql ( 42 ) ;
107- } ) ;
10848
109- it ( "will pass string data as either an attribute or a property" , function ( ) {
110- this . weight = 3 ;
111- let data = wc . str || wc . getAttribute ( "str" ) ;
112- expect ( data ) . to . eql ( "Angular" ) ;
113- } ) ;
114- } ) ;
115-
116- describe ( "events" , ( ) => {
117- it ( "can imperatively listen to a DOM event dispatched by a Custom Element" , function ( ) {
118- this . weight = 3 ;
119- const root = compile ( "<comp-with-imperative-event>" ) ( scope ) [ 0 ] ;
120- scope . $digest ( ) ;
121- let wc = root . querySelector ( "#wc" ) ;
122- let handled = root . querySelector ( "#handled" ) ;
123- expect ( handled . textContent ) . to . eql ( "false" ) ;
124- wc . click ( ) ;
125- scope . $digest ( ) ;
126- expect ( handled . textContent ) . to . eql ( "true" ) ;
127- } ) ;
49+ return { wc, toggle, root }
50+ } ,
51+ renderComponentWithProperties ( ) {
52+ return render ( '<comp-with-props>' )
53+ } ,
54+ renderComponentWithImperativeEvent ( ) {
55+ const { wc, root } = render ( '<comp-with-imperative-event>' ) ;
56+ function click ( ) {
57+ wc . click ( ) ;
58+ scope . $digest ( ) ;
59+ }
60+ return { wc, click, root } ;
61+ }
12862 } ) ;
129-
13063} ) ;
0 commit comments