Unverified Commit 5b32e160 authored by Tamika Tannis's avatar Tamika Tannis Committed by GitHub

Create TableHeaderBullets component (#397)

* Create TableHeaderBullets component

* Fix mocks
parent f9bf500c
import * as React from 'react';
import { getDisplayNameByResource, getDatabaseDisplayName } from 'config/config-utils';
import { ResourceType } from 'interfaces/Resources';
export interface TableHeaderBulletsProps {
cluster: string;
database: string;
}
const TableHeaderBullets: React.SFC<TableHeaderBulletsProps> = ({ cluster, database }) => {
return (
<ul className="header-bullets">
<li>{ getDisplayNameByResource(ResourceType.table)}</li>
<li>{ getDatabaseDisplayName(database) }</li>
<li>{ cluster }</li>
</ul>
);
};
TableHeaderBullets.defaultProps = {
cluster: '',
database: '',
};
export default TableHeaderBullets;
import * as React from 'react';
import { mocked } from 'ts-jest/utils';
import { shallow } from 'enzyme';
import TableHeaderBullets, { TableHeaderBulletsProps } from '../';
import { ResourceType } from 'interfaces/Resources';
const MOCK_RESOURCE_DISPLAY_NAME = 'Test';
const MOCK_DB_DISPLAY_NAME = 'AlsoTest';
jest.mock('config/config-utils', () => ({
getDisplayNameByResource: jest.fn(),
getDatabaseDisplayName: jest.fn()
}));
import { getDatabaseDisplayName, getDisplayNameByResource } from 'config/config-utils';
describe('TableHeaderBullets', () => {
const setup = (propOverrides?: Partial<TableHeaderBulletsProps>) => {
const props: TableHeaderBulletsProps = {
database: 'hive',
cluster: 'main',
...propOverrides
};
const wrapper = shallow(<TableHeaderBullets {...props} />);
return { props, wrapper };
};
describe('render', () => {
let props: TableHeaderBulletsProps;
let wrapper;
let listElement;
beforeAll(() => {
mocked(getDatabaseDisplayName).mockImplementation(() => MOCK_DB_DISPLAY_NAME);
mocked(getDisplayNameByResource).mockImplementation(() => MOCK_RESOURCE_DISPLAY_NAME);
const setupResult = setup();
props = setupResult.props;
wrapper = setupResult.wrapper;
listElement = wrapper.find('ul');
});
it('renders a list with correct class', () => {
expect(listElement.props().className).toEqual('header-bullets');
});
it('renders a list with resource display name', () => {
expect(getDisplayNameByResource).toHaveBeenCalledWith(ResourceType.table);
expect(listElement.find('li').at(0).text()).toEqual(MOCK_RESOURCE_DISPLAY_NAME);
});
it('renders a list with database display name', () => {
expect(getDatabaseDisplayName).toHaveBeenCalledWith(props.database);
expect(listElement.find('li').at(1).text()).toEqual(MOCK_DB_DISPLAY_NAME);
});
it('renders a list with cluster', () => {
expect(listElement.find('li').at(2).text()).toEqual(props.cluster);
});
});
});
...@@ -24,6 +24,7 @@ import OwnerEditor from 'components/TableDetail/OwnerEditor'; ...@@ -24,6 +24,7 @@ import OwnerEditor from 'components/TableDetail/OwnerEditor';
import ReportTableIssue from 'components/TableDetail/ReportTableIssue'; import ReportTableIssue from 'components/TableDetail/ReportTableIssue';
import SourceLink from 'components/TableDetail/SourceLink'; import SourceLink from 'components/TableDetail/SourceLink';
import TableDescEditableText from 'components/TableDetail/TableDescEditableText'; import TableDescEditableText from 'components/TableDetail/TableDescEditableText';
import TableHeaderBullets from 'components/TableDetail/TableHeaderBullets';
import TableIssues from 'components/TableDetail/TableIssues'; import TableIssues from 'components/TableDetail/TableIssues';
import WatermarkLabel from 'components/TableDetail/WatermarkLabel'; import WatermarkLabel from 'components/TableDetail/WatermarkLabel';
import WriterLink from 'components/TableDetail/WriterLink'; import WriterLink from 'components/TableDetail/WriterLink';
...@@ -32,7 +33,7 @@ import { TableMetadata } from 'interfaces/TableMetadata'; ...@@ -32,7 +33,7 @@ import { TableMetadata } from 'interfaces/TableMetadata';
import { EditableSection } from 'components/TableDetail/EditableSection'; import { EditableSection } from 'components/TableDetail/EditableSection';
import { getDisplayNameByResource, getDatabaseDisplayName, getDatabaseIconClass, issueTrackingEnabled, notificationsEnabled } from 'config/config-utils'; import { getDatabaseIconClass, issueTrackingEnabled, notificationsEnabled } from 'config/config-utils';
import { ResourceType } from 'interfaces/Resources'; import { ResourceType } from 'interfaces/Resources';
import { formatDateTimeShort } from 'utils/dateUtils'; import { formatDateTimeShort } from 'utils/dateUtils';
...@@ -142,11 +143,10 @@ class TableDetail extends React.Component<TableDetailProps & RouteComponentProps ...@@ -142,11 +143,10 @@ class TableDetail extends React.Component<TableDetailProps & RouteComponentProps
</h3> </h3>
<BookmarkIcon bookmarkKey={ this.props.tableData.key }/> <BookmarkIcon bookmarkKey={ this.props.tableData.key }/>
<div className="body-2"> <div className="body-2">
<ul className="header-bullets"> <TableHeaderBullets
<li>{ getDisplayNameByResource(ResourceType.table) }</li> database={ data.database }
<li>{ getDatabaseDisplayName(data.database) }</li> cluster={ data.cluster }
<li>{ data.cluster }</li> />
</ul>
{ {
data.badges.length > 0 && data.badges.length > 0 &&
<BadgeList badges={ data.badges } /> <BadgeList badges={ data.badges } />
......
import * as React from 'react'; import * as React from 'react';
import { mocked } from 'ts-jest/utils';
import { shallow } from 'enzyme'; import { shallow } from 'enzyme';
import SearchItemList, { SearchItemListProps } from '../'; import SearchItemList, { SearchItemListProps } from '../';
...@@ -82,8 +83,7 @@ describe('SearchItemList', () => { ...@@ -82,8 +83,7 @@ describe('SearchItemList', () => {
describe('renders ResourceType.user SearchItem based on config', () =>{ describe('renders ResourceType.user SearchItem based on config', () =>{
it('when indexUsersEnabled = true, renders SearchItem', () => { it('when indexUsersEnabled = true, renders SearchItem', () => {
// @ts-ignore: Known issue but can't find solution: https://github.com/kulshekhar/ts-jest/issues/661 mocked(indexUsersEnabled).mockImplementation(() => true);
indexUsersEnabled.mockImplementation(() => true);
setUpResult = setup(); setUpResult = setup();
props = setUpResult.props; props = setUpResult.props;
wrapper = setUpResult.wrapper; wrapper = setUpResult.wrapper;
...@@ -101,8 +101,7 @@ describe('SearchItemList', () => { ...@@ -101,8 +101,7 @@ describe('SearchItemList', () => {
}); });
it('when indexUsersEnabled = false, does not render SearchItem', () => { it('when indexUsersEnabled = false, does not render SearchItem', () => {
// @ts-ignore: Known issue but can't find solution: https://github.com/kulshekhar/ts-jest/issues/661 mocked(indexUsersEnabled).mockImplementation(() => false);
indexUsersEnabled.mockImplementation(() => false);
wrapper = setup().wrapper; wrapper = setup().wrapper;
const item = wrapper.find('SearchItem').findWhere(item => item.prop('resourceType') === ResourceType.user); const item = wrapper.find('SearchItem').findWhere(item => item.prop('resourceType') === ResourceType.user);
expect(item.exists()).toBe(false) expect(item.exists()).toBe(false)
......
import * as React from 'react'; import * as React from 'react';
import { mocked } from 'ts-jest/utils';
import { shallow } from 'enzyme'; import { shallow } from 'enzyme';
import { InlineSearchResults, InlineSearchResultsProps, mapStateToProps } from '../'; import { InlineSearchResults, InlineSearchResultsProps, mapStateToProps } from '../';
...@@ -210,8 +211,7 @@ describe('InlineSearchResults', () => { ...@@ -210,8 +211,7 @@ describe('InlineSearchResults', () => {
}); });
it('returns the results of getDatabaseIconClass for ResourceType.table', () => { it('returns the results of getDatabaseIconClass for ResourceType.table', () => {
const mockClass = 'test-class'; const mockClass = 'test-class';
// @ts-ignore: Known issue but can't find solution: https://github.com/kulshekhar/ts-jest/issues/661 mocked(getDatabaseIconClass).mockImplementation(() => mockClass);
getDatabaseIconClass.mockImplementation(() => mockClass);
const givenTable = props.tables.results[0]; const givenTable = props.tables.results[0];
const output = wrapper.instance().getSuggestedResultIconClass(ResourceType.table, givenTable); const output = wrapper.instance().getSuggestedResultIconClass(ResourceType.table, givenTable);
expect(output).toEqual(mockClass); expect(output).toEqual(mockClass);
...@@ -285,8 +285,7 @@ describe('InlineSearchResults', () => { ...@@ -285,8 +285,7 @@ describe('InlineSearchResults', () => {
}); });
it('returns the results of getDatabaseDisplayName for ResourceType.table', () => { it('returns the results of getDatabaseDisplayName for ResourceType.table', () => {
const mockName = 'Hive'; const mockName = 'Hive';
// @ts-ignore: Known issue but can't find solution: https://github.com/kulshekhar/ts-jest/issues/661 mocked(getDatabaseDisplayName).mockImplementation(() => mockName);
getDatabaseDisplayName.mockImplementation(() => mockName);
const givenTable = props.tables.results[0]; const givenTable = props.tables.results[0];
const output = wrapper.instance().getSuggestedResultType(ResourceType.table, givenTable); const output = wrapper.instance().getSuggestedResultType(ResourceType.table, givenTable);
expect(output).toEqual(mockName); expect(output).toEqual(mockName);
...@@ -401,16 +400,14 @@ describe('InlineSearchResults', () => { ...@@ -401,16 +400,14 @@ describe('InlineSearchResults', () => {
describe('calls renderResultsByResource for ResourceType.user based on config', () => { describe('calls renderResultsByResource for ResourceType.user based on config', () => {
it('does not call if indexUsersEnabled() = false', () => { it('does not call if indexUsersEnabled() = false', () => {
// @ts-ignore: Known issue but can't find solution: https://github.com/kulshekhar/ts-jest/issues/661 mocked(indexUsersEnabled).mockImplementation(() => false);
indexUsersEnabled.mockImplementation(() => false);
renderResultsByResourceSpy.mockClear(); renderResultsByResourceSpy.mockClear();
wrapper.instance().renderResults(); wrapper.instance().renderResults();
expect(renderResultsByResourceSpy).not.toHaveBeenCalledWith(ResourceType.user); expect(renderResultsByResourceSpy).not.toHaveBeenCalledWith(ResourceType.user);
}); });
it('calls if indexUsersEnabled() = true', () => { it('calls if indexUsersEnabled() = true', () => {
// @ts-ignore: Known issue but can't find solution: https://github.com/kulshekhar/ts-jest/issues/661 mocked(indexUsersEnabled).mockImplementation(() => true);
indexUsersEnabled.mockImplementation(() => true);
renderResultsByResourceSpy.mockClear(); renderResultsByResourceSpy.mockClear();
wrapper.instance().renderResults(); wrapper.instance().renderResults();
expect(renderResultsByResourceSpy).toHaveBeenCalledWith(ResourceType.user); expect(renderResultsByResourceSpy).toHaveBeenCalledWith(ResourceType.user);
......
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