Skip to content

Commit

Permalink
updated and added more tests, cleaned up linter issues and per page s…
Browse files Browse the repository at this point in the history
…election bug
  • Loading branch information
yctercero committed Jun 9, 2020
1 parent 5303cc9 commit 6027cbb
Show file tree
Hide file tree
Showing 10 changed files with 343 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ storiesOf('ExceptionItem', module)
.add('with os', () => {
const payload = getExceptionItemMock();
payload.description = '';
payload.comments = [];
payload.comment = [];
payload.entries = [
{
field: 'actingProcess.file.signer',
Expand All @@ -29,6 +29,7 @@ storiesOf('ExceptionItem', module)
return (
<ThemeProvider theme={() => ({ eui: euiLightVars, darkMode: false })}>
<ExceptionItem
loadingItemIds={[]}
commentsAccordionId={'accordion--comments'}
exceptionItem={payload}
handleDelete={() => {}}
Expand All @@ -40,7 +41,7 @@ storiesOf('ExceptionItem', module)
.add('with description', () => {
const payload = getExceptionItemMock();
payload._tags = [];
payload.comments = [];
payload.comment = [];
payload.entries = [
{
field: 'actingProcess.file.signer',
Expand All @@ -53,6 +54,7 @@ storiesOf('ExceptionItem', module)
return (
<ThemeProvider theme={() => ({ eui: euiLightVars, darkMode: false })}>
<ExceptionItem
loadingItemIds={[]}
commentsAccordionId={'accordion--comments'}
exceptionItem={payload}
handleDelete={() => {}}
Expand All @@ -77,6 +79,7 @@ storiesOf('ExceptionItem', module)
return (
<ThemeProvider theme={() => ({ eui: euiLightVars, darkMode: false })}>
<ExceptionItem
loadingItemIds={[]}
commentsAccordionId={'accordion--comments'}
exceptionItem={payload}
handleDelete={() => {}}
Expand All @@ -89,11 +92,12 @@ storiesOf('ExceptionItem', module)
const payload = getExceptionItemMock();
payload._tags = [];
payload.description = '';
payload.comments = [];
payload.comment = [];

return (
<ThemeProvider theme={() => ({ eui: euiLightVars, darkMode: false })}>
<ExceptionItem
loadingItemIds={[]}
commentsAccordionId={'accordion--comments'}
exceptionItem={payload}
handleDelete={() => {}}
Expand All @@ -108,6 +112,7 @@ storiesOf('ExceptionItem', module)
return (
<ThemeProvider theme={() => ({ eui: euiLightVars, darkMode: false })}>
<ExceptionItem
loadingItemIds={[]}
commentsAccordionId={'accordion--comments'}
exceptionItem={payload}
handleDelete={() => {}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ThemeProvider } from 'styled-components';
import euiLightVars from '@elastic/eui/dist/eui_theme_light.json';

import { ExceptionsViewerHeader } from '../viewer/exceptions_viewer_header';
import { ExceptionListType } from '../types';

storiesOf('ExceptionsViewerHeader', module)
.add('loading', () => {
Expand All @@ -18,10 +19,9 @@ storiesOf('ExceptionsViewerHeader', module)
isInitLoading={true}
detectionsListItems={5}
endpointListItems={2000}
supportedListTypes={['a', 'b']}
supportedListTypes={[ExceptionListType.DETECTION_ENGINE, ExceptionListType.ENDPOINT]}
onFilterChange={() => {}}
onAddEndpointExceptionClick={() => {}}
onAddDetectionsExceptionClick={() => {}}
onAddExceptionClick={() => {}}
/>
</ThemeProvider>
);
Expand All @@ -33,10 +33,9 @@ storiesOf('ExceptionsViewerHeader', module)
isInitLoading={false}
detectionsListItems={5}
endpointListItems={2000}
supportedListTypes={['a', 'b']}
supportedListTypes={[ExceptionListType.DETECTION_ENGINE, ExceptionListType.ENDPOINT]}
onFilterChange={() => {}}
onAddEndpointExceptionClick={() => {}}
onAddDetectionsExceptionClick={() => {}}
onAddExceptionClick={() => {}}
/>
</ThemeProvider>
);
Expand All @@ -48,10 +47,9 @@ storiesOf('ExceptionsViewerHeader', module)
isInitLoading={false}
detectionsListItems={0}
endpointListItems={2000}
supportedListTypes={['a']}
supportedListTypes={[ExceptionListType.DETECTION_ENGINE]}
onFilterChange={() => {}}
onAddEndpointExceptionClick={() => {}}
onAddDetectionsExceptionClick={() => {}}
onAddExceptionClick={() => {}}
/>
</ThemeProvider>
);
Expand All @@ -63,10 +61,9 @@ storiesOf('ExceptionsViewerHeader', module)
isInitLoading={false}
detectionsListItems={5}
endpointListItems={0}
supportedListTypes={['a']}
supportedListTypes={[ExceptionListType.DETECTION_ENGINE]}
onFilterChange={() => {}}
onAddEndpointExceptionClick={() => {}}
onAddDetectionsExceptionClick={() => {}}
onAddExceptionClick={() => {}}
/>
</ThemeProvider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,25 @@ import {
NestedExceptionEntry,
FormattedEntry,
} from './types';
import { ExceptionList } from '../../../lists_plugin_deps';

export const getExceptionListMock = (): ExceptionList => ({
id: '5b543420',
created_at: '2020-04-23T00:19:13.289Z',
created_by: 'user_name',
list_id: 'test-exception',
tie_breaker_id: '77fd1909-6786-428a-a671-30229a719c1f',
updated_at: '2020-04-23T00:19:13.289Z',
updated_by: 'user_name',
namespace_type: 'single',
name: '',
description: 'This is a description',
_tags: ['os:windows'],
tags: [],
type: 'endpoint',
meta: {},
totalItems: 0,
});

export const getExceptionItemEntryMock = (): ExceptionEntry => ({
field: 'actingProcess.file.signer',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export interface FilterOptions {

export interface Filter {
filter: Partial<FilterOptions>;
pagination: Partial<Pagination>;
pagination: Partial<ExceptionsPagination>;
}

export interface SetExceptionsProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('ExceptionEntries', () => {
const wrapper = mount(
<ThemeProvider theme={() => ({ eui: euiLightVars, darkMode: false })}>
<ExceptionEntries
disableDelete={false}
entries={[getFormattedEntryMock()]}
handleDelete={jest.fn()}
handleEdit={jest.fn()}
Expand All @@ -32,6 +33,7 @@ describe('ExceptionEntries', () => {
const wrapper = mount(
<ThemeProvider theme={() => ({ eui: euiLightVars, darkMode: false })}>
<ExceptionEntries
disableDelete={false}
entries={[getFormattedEntryMock(), getFormattedEntryMock()]}
handleDelete={jest.fn()}
handleEdit={jest.fn()}
Expand All @@ -47,6 +49,7 @@ describe('ExceptionEntries', () => {
const wrapper = mount(
<ThemeProvider theme={() => ({ eui: euiLightVars, darkMode: false })}>
<ExceptionEntries
disableDelete={false}
entries={[getFormattedEntryMock()]}
handleDelete={jest.fn()}
handleEdit={mockHandleEdit}
Expand All @@ -64,6 +67,7 @@ describe('ExceptionEntries', () => {
const wrapper = mount(
<ThemeProvider theme={() => ({ eui: euiLightVars, darkMode: false })}>
<ExceptionEntries
disableDelete={false}
entries={[getFormattedEntryMock()]}
handleDelete={mockHandleDelete}
handleEdit={jest.fn()}
Expand All @@ -84,6 +88,7 @@ describe('ExceptionEntries', () => {
const wrapper = mount(
<ThemeProvider theme={() => ({ eui: euiLightVars, darkMode: false })}>
<ExceptionEntries
disableDelete={false}
entries={[parentEntry, getFormattedEntryMock(true)]}
handleDelete={jest.fn()}
handleEdit={jest.fn()}
Expand Down Expand Up @@ -125,6 +130,7 @@ describe('ExceptionEntries', () => {
const wrapper = mount(
<ThemeProvider theme={() => ({ eui: euiLightVars, darkMode: false })}>
<ExceptionEntries
disableDelete={false}
entries={[getFormattedEntryMock()]}
handleDelete={jest.fn()}
handleEdit={jest.fn()}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React from 'react';
import { ThemeProvider } from 'styled-components';
import { mount } from 'enzyme';
import euiLightVars from '@elastic/eui/dist/eui_theme_light.json';

import { ExceptionsViewerPagination } from './exceptions_pagination';

describe('ExceptionsViewerPagination', () => {
it('it renders passed in "pageSize" as selected option', () => {
const wrapper = mount(
<ThemeProvider theme={() => ({ eui: euiLightVars, darkMode: false })}>
<ExceptionsViewerPagination
pagination={{
pageIndex: 0,
pageSize: 50,
totalItemCount: 1,
pageSizeOptions: [5, 10, 20, 50, 100],
}}
onPaginationChange={jest.fn()}
/>
</ThemeProvider>
);

expect(wrapper.find('[data-test-subj="exceptionsPerPageBtn"]').at(0).text()).toEqual(
'Items per page: 50'
);
});

it('it renders all passed in page size options when per page button clicked', () => {
const wrapper = mount(
<ThemeProvider theme={() => ({ eui: euiLightVars, darkMode: false })}>
<ExceptionsViewerPagination
pagination={{
pageIndex: 0,
pageSize: 50,
totalItemCount: 1,
pageSizeOptions: [20, 50, 100],
}}
onPaginationChange={jest.fn()}
/>
</ThemeProvider>
);

wrapper.find('[data-test-subj="exceptionsPerPageBtn"] button').simulate('click');

expect(wrapper.find('button[data-test-subj="exceptionsPerPageItem"]').at(0).text()).toEqual(
'20 items'
);
expect(wrapper.find('button[data-test-subj="exceptionsPerPageItem"]').at(1).text()).toEqual(
'50 items'
);
expect(wrapper.find('button[data-test-subj="exceptionsPerPageItem"]').at(2).text()).toEqual(
'100 items'
);
});

it('it invokes "onPaginationChange" when per page item is clicked', () => {
const mockOnPaginationChange = jest.fn();
const wrapper = mount(
<ThemeProvider theme={() => ({ eui: euiLightVars, darkMode: false })}>
<ExceptionsViewerPagination
pagination={{
pageIndex: 0,
pageSize: 50,
totalItemCount: 1,
pageSizeOptions: [20, 50, 100],
}}
onPaginationChange={mockOnPaginationChange}
/>
</ThemeProvider>
);

wrapper.find('[data-test-subj="exceptionsPerPageBtn"] button').simulate('click');
wrapper.find('button[data-test-subj="exceptionsPerPageItem"]').at(0).simulate('click');

expect(mockOnPaginationChange).toHaveBeenCalledWith({
filter: {},
pagination: { pageIndex: 0, pageSize: 20, totalItemCount: 1 },
});
});

it('it renders correct total page count', () => {
const wrapper = mount(
<ThemeProvider theme={() => ({ eui: euiLightVars, darkMode: false })}>
<ExceptionsViewerPagination
pagination={{
pageIndex: 0,
pageSize: 50,
totalItemCount: 160,
pageSizeOptions: [20, 50, 100],
}}
onPaginationChange={jest.fn()}
/>
</ThemeProvider>
);

expect(wrapper.find('[data-test-subj="exceptionsPagination"]').at(0).prop('pageCount')).toEqual(
4
);
expect(
wrapper.find('[data-test-subj="exceptionsPagination"]').at(0).prop('activePage')
).toEqual(0);
});

it('it invokes "onPaginationChange" when next clicked', () => {
const mockOnPaginationChange = jest.fn();
const wrapper = mount(
<ThemeProvider theme={() => ({ eui: euiLightVars, darkMode: false })}>
<ExceptionsViewerPagination
pagination={{
pageIndex: 0,
pageSize: 50,
totalItemCount: 160,
pageSizeOptions: [20, 50, 100],
}}
onPaginationChange={mockOnPaginationChange}
/>
</ThemeProvider>
);

wrapper.find('[data-test-subj="pagination-button-next"]').at(1).simulate('click');

expect(mockOnPaginationChange).toHaveBeenCalledWith({
filter: {},
pagination: { pageIndex: 2, pageSize: 50, totalItemCount: 160 },
});
});

it('it invokes "onPaginationChange" when page clicked', () => {
const mockOnPaginationChange = jest.fn();
const wrapper = mount(
<ThemeProvider theme={() => ({ eui: euiLightVars, darkMode: false })}>
<ExceptionsViewerPagination
pagination={{
pageIndex: 0,
pageSize: 50,
totalItemCount: 160,
pageSizeOptions: [20, 50, 100],
}}
onPaginationChange={mockOnPaginationChange}
/>
</ThemeProvider>
);

wrapper.find('button[data-test-subj="pagination-button-3"]').simulate('click');

expect(mockOnPaginationChange).toHaveBeenCalledWith({
filter: {},
pagination: { pageIndex: 4, pageSize: 50, totalItemCount: 160 },
});
});
});
Loading

0 comments on commit 6027cbb

Please sign in to comment.