Skip to content

Commit

Permalink
- restored the original disabled button behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-goldstein committed Jul 31, 2020
1 parent 34bcb42 commit 639ced0
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { getPinIcon } from './';
import { mount } from 'enzyme';
import React from 'react';

import { TimelineType } from '../../../../../common/types/timeline';

import { getPinIcon, Pin } from './';

interface ButtonIcon {
isDisabled: boolean;
}

describe('pin', () => {
describe('getPinRotation', () => {
Expand All @@ -16,4 +25,62 @@ describe('pin', () => {
expect(getPinIcon(false)).toEqual('pin');
});
});

describe('disabled button behavior', () => {
test('the button is enabled when allowUnpinning is true, and timelineType is NOT `template` (the default)', () => {
const allowUnpinning = true;
const wrapper = mount(
<Pin allowUnpinning={allowUnpinning} onClick={jest.fn()} pinned={false} />
);

expect(
(wrapper.find('[data-test-subj="pin"]').first().props() as ButtonIcon).isDisabled
).toBe(false);
});

test('the button is disabled when allowUnpinning is false, and timelineType is NOT `template` (the default)', () => {
const allowUnpinning = false;
const wrapper = mount(
<Pin allowUnpinning={allowUnpinning} onClick={jest.fn()} pinned={false} />
);

expect(
(wrapper.find('[data-test-subj="pin"]').first().props() as ButtonIcon).isDisabled
).toBe(true);
});

test('the button is disabled when allowUnpinning is true, and timelineType is `template`', () => {
const allowUnpinning = true;
const timelineType = TimelineType.template;
const wrapper = mount(
<Pin
allowUnpinning={allowUnpinning}
onClick={jest.fn()}
pinned={false}
timelineType={timelineType}
/>
);

expect(
(wrapper.find('[data-test-subj="pin"]').first().props() as ButtonIcon).isDisabled
).toBe(true);
});

test('the button is disabled when allowUnpinning is false, and timelineType is `template`', () => {
const allowUnpinning = false;
const timelineType = TimelineType.template;
const wrapper = mount(
<Pin
allowUnpinning={allowUnpinning}
onClick={jest.fn()}
pinned={false}
timelineType={timelineType}
/>
);

expect(
(wrapper.find('[data-test-subj="pin"]').first().props() as ButtonIcon).isDisabled
).toBe(true);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const Pin = React.memo<Props>(
iconSize={iconSize}
iconType={getPinIcon(pinned)}
onClick={onClick}
isDisabled={isTemplate}
isDisabled={isTemplate || !allowUnpinning}
/>
);
}
Expand Down

0 comments on commit 639ced0

Please sign in to comment.