1+ import { fixture , expect } from '@open-wc/testing' ;
2+
3+ /**
4+ * <hx-div> component tests
5+ *
6+ * @type HXDivElement
7+ *
8+ */
9+ describe ( '<hx-div> component tests' , ( ) => {
10+ const template = '<hx-div>' ;
11+
12+ describe ( 'test instantiate element' , ( ) => {
13+ it ( 'should be instantiated with hx-defined attribute' , async ( ) => {
14+ const component = /** @type {HXDivElement } */ await fixture ( template ) ;
15+ const attr = component . hasAttribute ( 'hx-defined' ) ;
16+
17+ expect ( attr ) . to . be . true ;
18+ } ) ;
19+
20+ it ( 'should not be hidden' , async ( ) => {
21+ const component = /** @type {HXDivElement } */ await fixture ( template ) ;
22+ const prop = component . hidden ;
23+
24+ expect ( prop ) . to . be . false ;
25+ } ) ;
26+
27+ it ( `the rendered Light DOM should NOT equal simple template ${ template } ` , async ( ) => {
28+ const component = /** @type {HXDivElement } */ await fixture ( template ) ;
29+
30+ expect ( component ) . lightDom . to . not . equal ( template ) ;
31+ } ) ;
32+ } ) ;
33+
34+ describe ( 'test Shadow DOM' , ( ) => {
35+ describe ( 'verify render' , ( ) => {
36+ it ( 'should have a static Shadow DOM' , async function ( ) {
37+ const component = /** @type { HXDivElement } */ await fixture ( template ) ;
38+ const shadow = component . shadowRoot . innerHTML ;
39+
40+ expect ( component ) . shadowDom . to . equal ( shadow ) ;
41+ } ) ;
42+
43+ it ( 'should render the Shadow Root mode open' , async ( ) => {
44+ const component = /** @type { HXDivElement } */ await fixture ( template ) ;
45+ const mode = component . shadowRoot . mode ;
46+
47+ expect ( mode ) . to . equal ( "open" ) ;
48+ } ) ;
49+
50+ it ( 'should have a single <slot>' , async ( ) => {
51+ const component = /** @type { HXDivElement } */ await fixture ( template ) ;
52+ const shadow = component . shadowRoot ;
53+ const query = shadow . querySelectorAll ( 'slot' ) ;
54+ const len = query . length ;
55+
56+ expect ( len ) . to . be . equal ( 1 ) ;
57+ } ) ;
58+
59+ it ( 'should have an unnamed <slot>' , async ( ) => {
60+ const component = /** @type { HXDivElement } */ await fixture ( template ) ;
61+ const name = component . slot ;
62+
63+ if ( name !== null ) {
64+ expect ( name ) . to . be . equal ( '' ) ;
65+ } else {
66+ expect ( name ) . to . be . null ; // IE11, Legacy Edge, and older browsers
67+ }
68+ } ) ;
69+ } ) ;
70+ } ) ;
71+
72+ describe ( 'test <hx-div> getter and setter methods' , ( ) => {
73+ it ( 'should be able to scroll in the vertical direction' , async ( ) => {
74+ const component = /** @type {HXDivElement } */ await fixture ( template ) ;
75+ component . scroll = 'vertical' ;
76+ const attr = component . hasAttribute ( 'scroll' ) ;
77+ const scrollDirection = component . getAttribute ( 'scroll' ) ;
78+
79+ expect ( attr ) . to . be . true ;
80+ expect ( scrollDirection ) . to . be . equal ( component . scroll ) ;
81+ } ) ;
82+ } ) ;
83+ } ) ;
0 commit comments