Skip to content

Commit 639ced0

Browse files
- restored the original disabled button behavior
1 parent 34bcb42 commit 639ced0

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

x-pack/plugins/security_solution/public/timelines/components/timeline/pin/index.test.tsx

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,16 @@
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

918
describe('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
});

x-pack/plugins/security_solution/public/timelines/components/timeline/pin/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const Pin = React.memo<Props>(
3434
iconSize={iconSize}
3535
iconType={getPinIcon(pinned)}
3636
onClick={onClick}
37-
isDisabled={isTemplate}
37+
isDisabled={isTemplate || !allowUnpinning}
3838
/>
3939
);
4040
}

0 commit comments

Comments
 (0)