44 * you may not use this file except in compliance with the Elastic License.
55 */
66
7- import { getPinIcon } from './' ;
7+ import { mount } from 'enzyme' ;
8+ import React from 'react' ;
9+
10+ import { TimelineType } from '../../../../../common/types/timeline' ;
11+
12+ import { getPinIcon , Pin } from './' ;
13+
14+ interface ButtonIcon {
15+ isDisabled : boolean ;
16+ }
817
918describe ( 'pin' , ( ) => {
1019 describe ( 'getPinRotation' , ( ) => {
@@ -16,4 +25,62 @@ describe('pin', () => {
1625 expect ( getPinIcon ( false ) ) . toEqual ( 'pin' ) ;
1726 } ) ;
1827 } ) ;
28+
29+ describe ( 'disabled button behavior' , ( ) => {
30+ test ( 'the button is enabled when allowUnpinning is true, and timelineType is NOT `template` (the default)' , ( ) => {
31+ const allowUnpinning = true ;
32+ const wrapper = mount (
33+ < Pin allowUnpinning = { allowUnpinning } onClick = { jest . fn ( ) } pinned = { false } />
34+ ) ;
35+
36+ expect (
37+ ( wrapper . find ( '[data-test-subj="pin"]' ) . first ( ) . props ( ) as ButtonIcon ) . isDisabled
38+ ) . toBe ( false ) ;
39+ } ) ;
40+
41+ test ( 'the button is disabled when allowUnpinning is false, and timelineType is NOT `template` (the default)' , ( ) => {
42+ const allowUnpinning = false ;
43+ const wrapper = mount (
44+ < Pin allowUnpinning = { allowUnpinning } onClick = { jest . fn ( ) } pinned = { false } />
45+ ) ;
46+
47+ expect (
48+ ( wrapper . find ( '[data-test-subj="pin"]' ) . first ( ) . props ( ) as ButtonIcon ) . isDisabled
49+ ) . toBe ( true ) ;
50+ } ) ;
51+
52+ test ( 'the button is disabled when allowUnpinning is true, and timelineType is `template`' , ( ) => {
53+ const allowUnpinning = true ;
54+ const timelineType = TimelineType . template ;
55+ const wrapper = mount (
56+ < Pin
57+ allowUnpinning = { allowUnpinning }
58+ onClick = { jest . fn ( ) }
59+ pinned = { false }
60+ timelineType = { timelineType }
61+ />
62+ ) ;
63+
64+ expect (
65+ ( wrapper . find ( '[data-test-subj="pin"]' ) . first ( ) . props ( ) as ButtonIcon ) . isDisabled
66+ ) . toBe ( true ) ;
67+ } ) ;
68+
69+ test ( 'the button is disabled when allowUnpinning is false, and timelineType is `template`' , ( ) => {
70+ const allowUnpinning = false ;
71+ const timelineType = TimelineType . template ;
72+ const wrapper = mount (
73+ < Pin
74+ allowUnpinning = { allowUnpinning }
75+ onClick = { jest . fn ( ) }
76+ pinned = { false }
77+ timelineType = { timelineType }
78+ />
79+ ) ;
80+
81+ expect (
82+ ( wrapper . find ( '[data-test-subj="pin"]' ) . first ( ) . props ( ) as ButtonIcon ) . isDisabled
83+ ) . toBe ( true ) ;
84+ } ) ;
85+ } ) ;
1986} ) ;
0 commit comments