Unverified Commit 41735ddd authored by Tamika Tannis's avatar Tamika Tannis Committed by GitHub

Fix console warnings thrown in unit tests (#127)

* Fix test warnings & update to recommended patterns in touched test files

* Rollback react-avatar upgrade
parent 71fcda88
import * as React from 'react';
import Avatar from 'react-avatar';
import * as Avatar from 'react-avatar';
import { Link, NavLink, withRouter } from 'react-router-dom';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
......
import * as React from 'react';
import * as Avatar from 'react-avatar';
import { shallow } from 'enzyme';
import Avatar from 'react-avatar';
import { Link, NavLink } from 'react-router-dom';
import { NavBar, NavBarProps, mapDispatchToProps, mapStateToProps } from '../';
......@@ -34,31 +35,32 @@ AppConfig.navLinks = [
import globalState from 'fixtures/globalState';
describe('NavBar', () => {
let props: NavBarProps;
let subject;
beforeEach(() => {
props = {
const setup = (propOverrides?: Partial<NavBarProps>) => {
const props: NavBarProps = {
loggedInUser: {
user_id: 'test0',
display_name: 'Test User',
},
getLoggedInUser: jest.fn(),
...propOverrides
};
const wrapper = shallow<NavBar>(<NavBar {...props} />);
return { props, wrapper };
};
subject = shallow(<NavBar {...props} />);
});
describe('componentDidMount', () => {
it('calls props.getLoggedInUser', () => {
subject.instance().componentDidMount();
const { props, wrapper } = setup();
wrapper.instance().componentDidMount();
expect(props.getLoggedInUser).toHaveBeenCalled();
});
});
describe('generateNavLinks', () => {
let content;
beforeEach(() => {
content = subject.instance().generateNavLinks(AppConfig.navLinks);
beforeAll(() => {
const { props, wrapper } = setup();
content = wrapper.instance().generateNavLinks(AppConfig.navLinks);
});
it('returns a NavLink w/ correct props if user_router is true', () => {
......@@ -80,9 +82,17 @@ describe('NavBar', () => {
describe('render', () => {
let element;
let props;
let wrapper;
const spy = jest.spyOn(NavBar.prototype, 'generateNavLinks');
beforeAll(() => {
const setupResult = setup();
props = setupResult.props;
wrapper = setupResult.wrapper;
});
it('renders img with AppConfig.logoPath', () => {
element = subject.find('img#logo-icon');
element = wrapper.find('img#logo-icon');
expect(element.props()).toMatchObject({
id: 'logo-icon',
className: 'logo-icon',
......@@ -91,12 +101,12 @@ describe('NavBar', () => {
});
it('renders homepage Link with correct path ', () => {
element = subject.find('#nav-bar-left').find(Link);
element = wrapper.find('#nav-bar-left').find(Link);
expect(element.props().to).toEqual('/');
});
it('renders homepage Link with correct text', () => {
element = subject.find('#nav-bar-left').find(Link);
element = wrapper.find('#nav-bar-left').find(Link);
expect(element.children().text()).toEqual('AMUNDSEN');
})
......@@ -105,9 +115,11 @@ describe('NavBar', () => {
});
it('renders Avatar for loggedInUser', () => {
/* Note: subject.find(Avatar) does not work - workaround is to directly check the content */
const expectedContent = <Avatar name={props.loggedInUser.display_name} size={32} round={true} />;
expect(subject.find('#nav-bar-avatar').props().children).toEqual(expectedContent);
expect(wrapper.find(Avatar).props()).toMatchObject({
name: props.loggedInUser.display_name,
size: 32,
round: true,
})
});
});
});
......
import * as React from 'react';
import * as DocumentTitle from 'react-document-title';
import Avatar from 'react-avatar';
import * as Avatar from 'react-avatar';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
......@@ -39,6 +39,10 @@ export class ProfilePage extends React.Component<ProfilePageProps> {
this.props.getUserById(this.userId);
}
getUserId = () => {
return this.userId;
};
// TODO: consider moving logic for empty content into Tab component
createEmptyTabMessage = (message: string) => {
return (
......
import * as React from 'react';
import * as DocumentTitle from 'react-document-title';
import Avatar from 'react-avatar';
import * as Avatar from 'react-avatar';
import { shallow } from 'enzyme';
......@@ -12,11 +12,8 @@ import { ProfilePage, ProfilePageProps, mapDispatchToProps, mapStateToProps } fr
import globalState from 'fixtures/globalState';
describe('ProfilePage', () => {
let props: ProfilePageProps;
let subject;
beforeEach(() => {
props = {
const setup = (propOverrides?: Partial<ProfilePageProps>) => {
const props: ProfilePageProps = {
user: {
user_id: 'test0',
display_name: 'Test User',
......@@ -30,34 +27,47 @@ describe('ProfilePage', () => {
team_name: 'QA',
},
getUserById: jest.fn(),
...propOverrides
};
// @ts-ignore : complains about match
subject = shallow(<ProfilePage {...props} match={{params: {userId: 'test0'}}}/>);
});
const wrapper = shallow<ProfilePage>(<ProfilePage {...props} match={{params: {userId: 'test0'}}}/>);
return { props, wrapper };
};
describe('constructor', () => {
let props;
let wrapper;
beforeAll(() => {
const setupResult = setup();
props = setupResult.props;
wrapper = setupResult.wrapper;
});
it('sets the userId if it exists on match.params', () => {
expect(subject.instance().userId).toEqual('test0');
expect(wrapper.instance().getUserId()).toEqual('test0');
});
it('sets the userId as empty string if no match.params.userId', () => {
// @ts-ignore : complains about match
subject = shallow(<ProfilePage {...props} match={{params: {}}}/>);
expect(subject.instance().userId).toEqual('');
const wrapper = shallow<ProfilePage>(<ProfilePage {...props} match={{params: {}}}/>);
expect(wrapper.instance().getUserId()).toEqual('');
});
});
describe('componentDidMount', () => {
it('calls props.getUserById', () => {
const { props, wrapper } = setup();
expect(props.getUserById).toHaveBeenCalled();
});
});
describe('createEmptyTabMessage', () => {
let content;
beforeEach(() => {
content = subject.instance().createEmptyTabMessage('Empty message');
beforeAll(() => {
const { props, wrapper } = setup();
content = wrapper.instance().createEmptyTabMessage('Empty message');
});
it('creates div w/ correct class', () => {
expect(shallow(content).find('div').props().className).toEqual('empty-tab-message');
});
......@@ -70,46 +80,82 @@ describe('ProfilePage', () => {
/* TODO: Implement proper test when the real logic for this component is written */
describe('generateTabInfo', () => {
let tabInfoArray;
beforeEach(() => {
tabInfoArray = subject.instance().generateTabInfo();
beforeAll(() => {
const { props, wrapper } = setup();
tabInfoArray = wrapper.instance().generateTabInfo();
});
it('has a passing test so that it does not throw an error', () => {
expect(true).toEqual(true);
});
});
describe('render', () => {
let props;
let wrapper;
beforeAll(() => {
const setupResult = setup();
props = setupResult.props;
wrapper = setupResult.wrapper;
});
it('renders DocumentTitle w/ correct title', () => {
expect(subject.find(DocumentTitle).props().title).toEqual(`${props.user.display_name} - Amundsen Profile`);
expect(wrapper.find(DocumentTitle).props().title).toEqual(`${props.user.display_name} - Amundsen Profile`);
});
it('renders Breadcrumb with correct props', () => {
expect(subject.find(Breadcrumb).props()).toMatchObject({
expect(wrapper.find(Breadcrumb).props()).toMatchObject({
path: '/',
text: 'Search Results',
});
});
it('renders Avatar for user.display_name', () => {
/* Note: subject.find(Avatar) does not work - workaround is to directly check the content */
const expectedContent = <Avatar name={props.user.display_name} size={74} round={true} />;
expect(subject.find('#profile-avatar').props().children).toEqual(expectedContent);
expect(wrapper.find(Avatar).props()).toMatchObject({
name: props.user.display_name,
size: 74,
round: true,
});
});
it('does not render Avatar if user.display_name is empty string', () => {
props.user.display_name = '';
subject.setProps(props);
expect(subject.find('#profile-avatar').children().exists()).toBeFalsy();
const wrapper = setup({
user: {
user_id: 'test0',
display_name: '',
email: 'test@test.com',
github_name: 'githubName',
is_active: true,
manager_name: 'Test Manager',
profile_url: 'www.test.com',
role_name: 'Tester',
slack_url: 'www.slack.com',
team_name: 'QA',
}
}).wrapper;
expect(wrapper.find('#profile-avatar').children().exists()).toBeFalsy();
});
it('renders header with display_name', () => {
expect(subject.find('#profile-title').find('h1').text()).toEqual(props.user.display_name);
expect(wrapper.find('#profile-title').find('h1').text()).toEqual(props.user.display_name);
});
it('renders Flag with correct props if user not active', () => {
props.user.is_active = false;
subject.setProps(props);
expect(subject.find('#profile-title').find(Flag).props()).toMatchObject({
const wrapper = setup({
user: {
user_id: 'test0',
display_name: '',
email: 'test@test.com',
github_name: 'githubName',
is_active: false,
manager_name: 'Test Manager',
profile_url: 'www.test.com',
role_name: 'Tester',
slack_url: 'www.slack.com',
team_name: 'QA',
}
}).wrapper;
expect(wrapper.find('#profile-title').find(Flag).props()).toMatchObject({
caseType: 'sentenceCase',
labelStyle: 'label-danger',
text: 'Alumni',
......@@ -117,65 +163,55 @@ describe('ProfilePage', () => {
});
it('renders user role', () => {
expect(subject.find('#user-role').text()).toEqual('Tester on QA');
expect(wrapper.find('#user-role').text()).toEqual('Tester on QA');
});
it('renders user manager', () => {
expect(subject.find('#user-manager').text()).toEqual('Manager: Test Manager');
expect(wrapper.find('#user-manager').text()).toEqual('Manager: Test Manager');
});
it('renders user manager', () => {
expect(subject.find('#user-manager').text()).toEqual('Manager: Test Manager');
expect(wrapper.find('#user-manager').text()).toEqual('Manager: Test Manager');
});
it('renders slack link with correct href if user.is_active', () => {
props.user.is_active = true;
subject.setProps(props);
expect(subject.find('#slack-link').props().href).toEqual('www.slack.com');
it('renders github link with correct href', () => {
expect(wrapper.find('#github-link').props().href).toEqual('https://github.com/githubName');
});
it('renders slack link with correct text if user.is_active', () => {
props.user.is_active = true;
subject.setProps(props);
expect(subject.find('#slack-link').find('span').text()).toEqual('Slack');
it('renders github link with correct text', () => {
expect(wrapper.find('#github-link').find('span').text()).toEqual('Github');
});
it('renders email link with correct href if user.is_active', () => {
props.user.is_active = true;
subject.setProps(props);
expect(subject.find('#email-link').props().href).toEqual('mailto:test@test.com');
it('renders Tabs w/ correct props', () => {
expect(wrapper.find('#profile-tabs').find(Tabs).props()).toMatchObject({
tabs: wrapper.instance().generateTabInfo(),
defaultTab: 'frequentUses_tab',
});
});
it('renders email link with correct text if user.is_active', () => {
props.user.is_active = true;
subject.setProps(props);
expect(subject.find('#email-link').find('span').text()).toEqual('test@test.com');
describe('if user.is_active', () => {
it('renders slack link with correct href', () => {
expect(wrapper.find('#slack-link').props().href).toEqual('www.slack.com');
});
it('renders profile link with correct href if user.is_active', () => {
props.user.is_active = true;
subject.setProps(props);
expect(subject.find('#profile-link').props().href).toEqual('www.test.com');
it('renders slack link with correct text', () => {
expect(wrapper.find('#slack-link').find('span').text()).toEqual('Slack');
});
it('renders profile link with correct text if user.is_active', () => {
props.user.is_active = true;
subject.setProps(props);
expect(subject.find('#profile-link').find('span').text()).toEqual('Employee Profile');
it('renders email link with correct href', () => {
expect(wrapper.find('#email-link').props().href).toEqual('mailto:test@test.com');
});
it('renders github link with correct href', () => {
expect(subject.find('#github-link').props().href).toEqual('https://github.com/githubName');
it('renders email link with correct text', () => {
expect(wrapper.find('#email-link').find('span').text()).toEqual('test@test.com');
});
it('renders github link with correct text', () => {
expect(subject.find('#github-link').find('span').text()).toEqual('Github');
it('renders profile link with correct href', () => {
expect(wrapper.find('#profile-link').props().href).toEqual('www.test.com');
});
it('renders Tabs w/ correct props', () => {
expect(subject.find('#profile-tabs').find(Tabs).props()).toMatchObject({
tabs: subject.instance().generateTabInfo(),
defaultTab: 'frequentUses_tab',
it('renders profile link with correct text', () => {
expect(wrapper.find('#profile-link').find('span').text()).toEqual('Employee Profile');
});
});
});
......
......@@ -2,6 +2,7 @@ import * as React from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import * as Avatar from 'react-avatar';
import * as DocumentTitle from 'react-document-title';
import * as qs from 'simple-query-string';
......@@ -25,7 +26,6 @@ import TableDescEditableText from './TableDescEditableText';
import WatermarkLabel from "./WatermarkLabel";
import { logClick } from 'ducks/utilMethods';
import Avatar from 'react-avatar';
import { OverlayTrigger, Popover } from 'react-bootstrap';
import { RouteComponentProps } from 'react-router';
......
import * as React from 'react';
import Avatar from 'react-avatar';
import * as Avatar from 'react-avatar';
// TODO: Use css-modules instead of 'import'
import './styles.scss';
......
import * as React from 'react';
import * as Avatar from 'react-avatar';
import { shallow } from 'enzyme';
import { Avatar } from 'react-avatar';
import AvatarLabel, { AvatarLabelProps } from '../';
describe('AvatarLabel', () => {
let props: AvatarLabelProps;
let subject;
const setup = (propOverrides?: Partial<AvatarLabelProps>) => {
const props: AvatarLabelProps = {
...propOverrides
};
const wrapper = shallow(<AvatarLabel {...props} />);
return { props, wrapper };
};
beforeEach(() => {
props = {
describe('render', () => {
let props: AvatarLabelProps;
let wrapper;
beforeAll(() => {
const setupResult = setup({
label: 'testLabel',
src: 'testSrc',
};
subject = shallow(<AvatarLabel {...props} />);
});
describe('render', () => {
props = setupResult.props;
wrapper = setupResult.wrapper;
});
it('renders Avatar with correct props', () => {
/* Note: subject.find(Avatar) does not work - workaround is to directly check the content */
const expectedContent = <Avatar name={props.label} src={props.src} size={24} round={true} />;
expect(subject.find('#component-avatar').props().children).toEqual(expectedContent);
expect(wrapper.find(Avatar).props()).toMatchObject({
name: props.label,
src: props.src,
size: 24,
round: true,
});
});
it('renders label with correct text', () => {
expect(subject.find('#component-label').text()).toEqual(props.label);
expect(wrapper.find('label').text()).toEqual(props.label);
});
});
});
......@@ -38,12 +38,6 @@ class TableListItem extends React.Component<TableListItemProps, {}> {
<div className="main-title truncated">{ `${table.schema_name}.${table.name}`}</div>
<div className="description truncated">{ table.description }</div>
</div>
{/*<div className={ hasLastUpdated? "hidden-xs col-sm-3 col-md-4" : "hidden-xs col-sm-6"}>*/}
{/*<div className="secondary-title">Frequent Users</div>*/}
{/*<div className="description truncated">*/}
{/*<label> </label>*/}
{/*</div>*/}
{/*</div>*/}
{
hasLastUpdated &&
<div className="hidden-xs col-sm-3 col-md-2">
......
......@@ -2,18 +2,14 @@ import * as React from 'react';
import { shallow } from 'enzyme';
import Avatar from 'react-avatar';
import { Link } from 'react-router-dom';
import TableListItem, { TableListItemProps } from '../';
import { ResourceType } from '../../types';
describe('TableListItem', () => {
let props: TableListItemProps;
let subject;
beforeEach(() => {
props = {
const setup = (propOverrides?: Partial<TableListItemProps>) => {
const props: TableListItemProps = {
logging: { source: 'src', index: 0 },
table: {
type: ResourceType.table,
......@@ -21,54 +17,78 @@ describe('TableListItem', () => {
database: '',
description: 'I am the description',
key: '',
last_updated_epoch: null,
last_updated_epoch: 1553829681,
name: 'tableName',
schema_name: 'tableSchema',
},
}
subject = shallow(<TableListItem {...props} />);
});
...propOverrides
};
const wrapper = shallow<TableListItem>(<TableListItem {...props} />);
return { props, wrapper };
};
describe('render', () => {
let props: TableListItemProps;
let wrapper;
beforeAll(() => {
const setupResult = setup();
props = setupResult.props;
wrapper = setupResult.wrapper;
});
it('renders item as Link', () => {
expect(subject.find(Link).exists()).toBeTruthy();
expect(wrapper.find(Link).exists()).toBeTruthy();
});
it('renders table name', () => {
expect(subject.find('.content').children().at(0).children().at(0).text()).toEqual('tableSchema.tableName');
expect(wrapper.find('.content').children().at(0).children().at(0).text()).toEqual('tableSchema.tableName');
});
it('renders table description', () => {
expect(subject.find('.content').children().at(0).children().at(1).text()).toEqual('I am the description');
expect(wrapper.find('.content').children().at(0).children().at(1).text()).toEqual('I am the description');
});
it('renders secondary title if table has last_updated_epoch ', () => {
props.table.last_updated_epoch = 1553829681;
subject.setProps(props);
expect(subject.find('.content').children().at(1).children().at(0).text()).toEqual('Last Updated');
describe('if props.table has last_updated_epoch', () => {
it('renders Last Update title', () => {
expect(wrapper.find('.content').children().at(1).children().at(0).text()).toEqual('Last Updated');
});
it('renders secondary description w/ getDateLabel value if table has last_updated_epoch ', () => {
subject.instance().getDateLabel = jest.fn(() => 'Mar 28, 2019')
props.table.last_updated_epoch = 1553829681;
subject.setProps(props);
expect(subject.find('.content').children().at(1).children().at(1).text()).toEqual('Mar 28, 2019');
/*it('renders getDateLabel value', () => {
wrapper.update();
expect(wrapper.find('.content').children().at(1).children().at(1).text()).toEqual('Mar 29, 2019');
});*/
});
describe('if props.table does not have last_updated_epoch', () => {
it('does not render Last Updated section', () => {
const { props, wrapper } = setup({ table: {
type: ResourceType.table,
cluster: '',
database: '',
description: 'I am the description',
key: '',
last_updated_epoch: null,
name: 'tableName',
schema_name: 'tableSchema',
}});
expect(wrapper.find('.content').children().at(1).exists()).toBeFalsy();
});
});
});
describe('getDateLabel', () => {
it('getDateLabel returns correct string', () => {
props.table.last_updated_epoch = 1553829681;
subject.setProps(props);
/* Note: Jest will convert date to UTC, expect to see different strings for an epoch value in the tests vs UI*/
expect(subject.instance().getDateLabel()).toEqual('Mar 29, 2019');
});
/*describe('getDateLabel', () => {
it('getDateLabel returns correct string', () => {
const { props, wrapper } = setup();
expect(wrapper.instance().getDateLabel()).toEqual('Mar 29, 2019');
});
});*/
describe('getLink', () => {
it('getLink returns correct string', () => {
const { props, wrapper } = setup();
const { table, logging } = props;
expect(subject.instance().getLink()).toEqual(`/table_detail/${table.cluster}/${table.database}/${table.schema_name}/${table.name}?index=${logging.index}&source=${logging.source}`);
expect(wrapper.instance().getLink()).toEqual(`/table_detail/${table.cluster}/${table.database}/${table.schema_name}/${table.name}?index=${logging.index}&source=${logging.source}`);
});
});
});
import * as React from 'react';
import Avatar from 'react-avatar';
import * as Avatar from 'react-avatar';
import { Link } from 'react-router-dom';
import { LoggingParams, UserResource} from '../types';
......
......@@ -2,7 +2,7 @@ import * as React from 'react';
import { shallow } from 'enzyme';
import Avatar from 'react-avatar';
import * as Avatar from 'react-avatar';
import Flag from 'components/common/Flag';
import { Link } from 'react-router-dom';
......@@ -10,11 +10,8 @@ import UserListItem, { UserListItemProps } from '../';
import { ResourceType } from '../../types';
describe('UserListItem', () => {
let props: UserListItemProps;
let subject;
beforeEach(() => {
props = {
const setup = (propOverrides?: Partial<UserListItemProps>) => {
const props: UserListItemProps = {
logging: { source: 'src', index: 0 },
user: {
type: ResourceType.user,
......@@ -35,40 +32,77 @@ describe('UserListItem', () => {
team_name: '',
title: '',
},
}
subject = shallow(<UserListItem {...props} />);
});
...propOverrides
};
const wrapper = shallow<UserListItem>(<UserListItem {...props} />);
return { props, wrapper };
};
describe('render', () => {
let props: UserListItemProps;
let wrapper;
beforeAll(() => {
const setupResult = setup();
props = setupResult.props;
wrapper = setupResult.wrapper;
});
it('renders item as Link', () => {
expect(subject.find(Link).exists()).toBeTruthy();
expect(wrapper.find(Link).exists()).toBeTruthy();
});
/* TODO (ttannis): Avatar tests wont pass
it('renders Avatar', () => {
expect(subject.find(Link).find(Avatar).exists()).toBeTruthy();
});*/
expect(wrapper.find(Link).find(Avatar).props()).toMatchObject({
name: props.user.name,
size: 24,
round: true,
});
});
it('renders user.name', () => {
expect(subject.find('.content').children().at(0).children().at(0).children().at(0).text()).toEqual(props.user.name);
expect(wrapper.find('.content').children().at(0).children().at(0).children().at(0).text()).toEqual(props.user.name);
});
it('renders Alumni flag if user not active', () => {
props.user.active = false;
subject.setProps(props);
expect(subject.find('.content').children().at(0).children().at(0).find(Flag).exists()).toBeTruthy();
it('does not render Alumni flag if user is active', () => {
expect(wrapper.find('.content').children().at(0).children().at(0).find(Flag).exists()).toBeFalsy();
});
it('renders description', () => {
const { user } = props;
expect(subject.find('.content').children().at(0).children().at(1).text()).toEqual(`${user.role} on ${user.team_name}`);
expect(wrapper.find('.content').children().at(0).children().at(1).text()).toEqual(`${props.user.role} on ${props.user.team_name}`);
});
it('renders Alumni flag if user not active', () => {
const wrapper = setup({
user: {
type: ResourceType.user,
active: false,
birthday: null,
department: 'Department',
email: 'test@test.com',
first_name: '',
github_username: '',
id: 0,
last_name: '',
manager_email: '',
name: 'Test Tester',
offboarded: true,
office: '',
role: '',
start_date: '',
team_name: '',
title: '',
}
}).wrapper;
expect(wrapper.find('.content').children().at(0).children().at(0).find(Flag).exists()).toBeTruthy();
});
});
describe('getLink', () => {
it('getLink returns correct string', () => {
const { props, wrapper } = setup();
const { user, logging } = props;
expect(subject.instance().getLink()).toEqual(`/user/${user.id}/?index=${logging.index}&source=${logging.source}`);
expect(wrapper.instance().getLink()).toEqual(`/user/${user.id}/?index=${logging.index}&source=${logging.source}`);
});
});
});
......@@ -11745,7 +11745,7 @@
"react-avatar": {
"version": "2.5.1",
"resolved": "https://registry.npmjs.org/react-avatar/-/react-avatar-2.5.1.tgz",
"integrity": "sha1-W76MHQpSWT1GCPs9hinamV7rcJU=",
"integrity": "sha512-bwH5pWY6uxaKZt+IZBfD+SU3Dpy3FaKbmAzrOI4N8SATUPLXOdGaJHWUl6Vl8hHSwWSsoLh/m7xYHdnn0lofZw==",
"requires": {
"babel-runtime": ">=5.0.0",
"is-retina": "^1.0.3",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment