Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
Add component tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tkbky committed Nov 1, 2017
1 parent 398c4e8 commit 3758806
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
58 changes: 58 additions & 0 deletions tests/components/get_link_modal.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import React from 'react';

import {shallow} from 'enzyme';
import {Modal} from 'react-bootstrap';

import GetLinkModal from 'components/get_link_modal.jsx';

describe('components/GetLinkModal', () => {
test('should match snapshot when all props is set', () => {
function emptyFunction() {} //eslint-disable-line no-empty-function

const wrapper = shallow(
<GetLinkModal
show={true}
onHide={emptyFunction}
title={'title'}
helpText={'help text'}
link={'https://mattermost.com'}
/>
);

expect(wrapper).toMatchSnapshot();
});

test('should match snapshot when helpText is not set', () => {
function emptyFunction() {} //eslint-disable-line no-empty-function

const wrapper = shallow(
<GetLinkModal
show={true}
onHide={emptyFunction}
title={'title'}
link={'https://mattermost.com'}
/>
);

expect(wrapper).toMatchSnapshot();
});

test('should have called onHide', () => {
const onHide = jest.fn();

const wrapper = shallow(
<GetLinkModal
show={true}
onHide={onHide}
title={'title'}
link={'https://mattermost.com'}
/>
);

wrapper.find(Modal).first().props().onHide();
expect(onHide).toHaveBeenCalledTimes(1);
});
});
15 changes: 15 additions & 0 deletions tests/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,18 @@ import Adapter from 'enzyme-adapter-react-15';
import {configure} from 'enzyme';

configure({adapter: new Adapter()});

var documentMock = (function() {
const supportedCommands = ['copy'];

return {
queryCommandSupported(cmd) {
return supportedCommands.includes(cmd);
},
execCommand(cmd) {
return supportedCommands.includes(cmd);
}
};
}());

Object.defineProperty(window, 'document', {value: documentMock});

0 comments on commit 3758806

Please sign in to comment.