@@ -38,33 +38,70 @@ describe('vaadin-button', () => {
3838 } ) ;
3939 } ) ;
4040
41- describe ( 'default' , ( ) => {
42- let button , label ;
41+ describe ( 'role' , ( ) => {
42+ describe ( 'default' , ( ) => {
43+ beforeEach ( ( ) => {
44+ element = fixtureSync ( '<vaadin-button>Press me</vaadin-button>' ) ;
45+ } ) ;
4346
44- beforeEach ( ( ) => {
45- element = fixtureSync ( '<vaadin-button>Vaadin <i>Button</i></vaadin-button>' ) ;
46- button = element . $ . button ;
47- label = element . shadowRoot . querySelector ( '[part=label]' ) ;
47+ it ( 'should set role attribute to button by default' , ( ) => {
48+ expect ( element . getAttribute ( 'role' ) ) . to . equal ( 'button' ) ;
49+ } ) ;
4850 } ) ;
4951
50- it ( 'should have [type=button] on the native button' , ( ) => {
51- expect ( button . getAttribute ( 'type' ) ) . to . be . eql ( 'button' ) ;
52+ describe ( 'custom' , ( ) => {
53+ beforeEach ( ( ) => {
54+ element = fixtureSync ( '<vaadin-button role="menuitem">Press me</vaadin-button>' ) ;
55+ } ) ;
56+
57+ it ( 'should not override custom role attribute' , ( ) => {
58+ expect ( element . getAttribute ( 'role' ) ) . to . equal ( 'menuitem' ) ;
59+ } ) ;
60+ } ) ;
61+ } ) ;
62+
63+ describe ( 'label' , ( ) => {
64+ let label ;
65+
66+ beforeEach ( ( ) => {
67+ element = fixtureSync ( '<vaadin-button>Press me</vaadin-button>' ) ;
68+ label = element . shadowRoot . querySelector ( '[part=label]' ) ;
5269 } ) ;
5370
5471 it ( 'should define the button label using light DOM' , ( ) => {
5572 const children = FlattenedNodesObserver . getFlattenedNodes ( label ) ;
56- expect ( children [ 1 ] . textContent ) . to . be . equal ( 'Vaadin ' ) ;
57- expect ( children [ 2 ] . outerHTML ) . to . be . equal ( '<i>Button</i>' ) ;
73+ expect ( children [ 1 ] . textContent ) . to . be . equal ( 'Press me' ) ;
5874 } ) ;
75+ } ) ;
5976
60- it ( 'should disable the native button ', ( ) => {
61- element . disabled = true ;
62- expect ( button . hasAttribute ( 'disabled' ) ) . to . be . true ;
77+ describe ( 'mixins ', ( ) => {
78+ beforeEach ( ( ) => {
79+ element = fixtureSync ( '<vaadin- button>Press me</vaadin-button>' ) ;
6380 } ) ;
6481
65- // TODO: Remove when it will be possible to detect whether the button element inherits ActiveMixin.
66- // A related issue: https://github.com/vaadin/web-components/issues/2357
67- describe ( 'active' , ( ) => {
82+ // TODO: Remove when it would be possible for an element:
83+ // – to detect if it inherits DisabledMixin.
84+ // – or to run a suit of the tests defined in DisabledMixin.
85+ describe ( 'DisabledMixin' , ( ) => {
86+ it ( 'should set disabled property to false by default' , ( ) => {
87+ expect ( element . disabled ) . to . be . false ;
88+ } ) ;
89+
90+ it ( 'should reflect disabled property to attribute' , ( ) => {
91+ element . disabled = true ;
92+ expect ( element . hasAttribute ( 'disabled' ) ) . to . be . true ;
93+ } ) ;
94+
95+ it ( 'should set the aria-disabled attribute when disabled' , ( ) => {
96+ element . disabled = true ;
97+ expect ( element . getAttribute ( 'aria-disabled' ) ) . to . equal ( 'true' ) ;
98+ } ) ;
99+ } ) ;
100+
101+ // TODO: Remove when it would be possible for an element:
102+ // – to detect if it inherits ActiveMixin.
103+ // – or to run a suit of the tests defined in ActiveMixin.
104+ describe ( 'ActiveMixin' , ( ) => {
68105 ( isIOS ? it . skip : it ) ( 'should have active attribute on mousedown' , ( ) => {
69106 mousedown ( element ) ;
70107 expect ( element . hasAttribute ( 'active' ) ) . to . be . true ;
@@ -135,23 +172,85 @@ describe('vaadin-button', () => {
135172 } ) ;
136173 } ) ;
137174
138- describe ( 'focus-ring' , ( ) => {
139- beforeEach ( async ( ) => {
140- // Focus on the button
141- await sendKeys ( { press : 'Tab' } ) ;
175+ // TODO: Remove when it would be possible for an element:
176+ // – to detect if it inherits TabindexMixin.
177+ // – or to run a suit of the tests defined in TabindexMixin.
178+ describe ( 'TabindexMixin' , ( ) => {
179+ it ( 'should set tabindex attribute to 0 by default' , ( ) => {
180+ expect ( element . getAttribute ( 'tabindex' ) ) . to . be . equal ( '0' ) ;
181+ } ) ;
182+
183+ it ( 'should reflect tabindex property to the attribute' , ( ) => {
184+ element . tabindex = 1 ;
185+ expect ( element . getAttribute ( 'tabindex' ) ) . to . be . equal ( '1' ) ;
142186 } ) ;
143187
144- it ( 'should set focus-ring attribute when focusing with Tab' , ( ) => {
145- expect ( element . hasAttribute ( 'focus-ring' ) ) . to . be . true ;
188+ it ( 'should reflect native tabIndex property to the attribute' , ( ) => {
189+ element . tabIndex = 1 ;
190+ expect ( element . getAttribute ( 'tabindex' ) ) . to . be . equal ( '1' ) ;
146191 } ) ;
147192
148- it ( 'should remove focus-ring attribute when loosing focus with Shift+Tab' , async ( ) => {
149- // Focus out of the button
150- await sendKeys ( { down : 'Shift' } ) ;
151- await sendKeys ( { press : 'Tab' } ) ;
152- await sendKeys ( { up : 'Shift' } ) ;
193+ it ( 'should set tabindex attribute to -1 when disabled' , ( ) => {
194+ element . tabIndex = 1 ;
195+ element . disabled = true ;
196+ expect ( element . getAttribute ( 'tabindex' ) ) . to . be . equal ( '-1' ) ;
197+ } ) ;
198+
199+ it ( 'should restore tabindex attribute when enabled' , ( ) => {
200+ element . tabIndex = 1 ;
201+ element . disabled = true ;
202+ element . disabled = false ;
203+ expect ( element . getAttribute ( 'tabindex' ) ) . to . be . equal ( '1' ) ;
204+ } ) ;
205+
206+ it ( 'should restore tabindex attribute with the last known value when enabled' , ( ) => {
207+ element . tabIndex = 1 ;
208+ element . disabled = true ;
209+ element . tabIndex = 2 ;
210+ expect ( element . getAttribute ( 'tabindex' ) ) . to . be . equal ( '-1' ) ;
211+
212+ element . disabled = false ;
213+ expect ( element . getAttribute ( 'tabindex' ) ) . to . be . equal ( '2' ) ;
214+ } ) ;
215+ } ) ;
216+
217+ // TODO: Remove when it would be possible for an element:
218+ // – to detect if it inherits FocusMixin.
219+ // – or to run a suit of the tests defined in FocusMixin.
220+ describe ( 'FocusMixin' , ( ) => {
221+ describe ( 'focusing with Tab' , ( ) => {
222+ beforeEach ( async ( ) => {
223+ // Focus on the button
224+ await sendKeys ( { press : 'Tab' } ) ;
225+ } ) ;
226+
227+ it ( 'should set focused attribute' , ( ) => {
228+ expect ( element . hasAttribute ( 'focused' ) ) . to . be . true ;
229+ } ) ;
230+
231+ it ( 'should set focus-ring attribute' , ( ) => {
232+ expect ( element . hasAttribute ( 'focus-ring' ) ) . to . be . true ;
233+ } ) ;
234+ } ) ;
235+
236+ describe ( 'loosing focus with Shift+Tab' , ( ) => {
237+ beforeEach ( async ( ) => {
238+ // Focus on the button
239+ await sendKeys ( { press : 'Tab' } ) ;
240+
241+ // Focus out of the button
242+ await sendKeys ( { down : 'Shift' } ) ;
243+ await sendKeys ( { press : 'Tab' } ) ;
244+ await sendKeys ( { up : 'Shift' } ) ;
245+ } ) ;
246+
247+ it ( 'should remove focused attribute' , ( ) => {
248+ expect ( element . hasAttribute ( 'focused' ) ) . to . be . false ;
249+ } ) ;
153250
154- expect ( element . hasAttribute ( 'focus-ring' ) ) . to . be . false ;
251+ it ( 'should remove focus-ring attribute' , ( ) => {
252+ expect ( element . hasAttribute ( 'focus-ring' ) ) . to . be . false ;
253+ } ) ;
155254 } ) ;
156255 } ) ;
157256 } ) ;
0 commit comments