Skip to content

Commit

Permalink
adds tests and addresses comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dplumlee committed Oct 1, 2020
1 parent 6feb5d6 commit bb163a9
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export const getColumns = ({
field: 'tags',
name: i18n.COLUMN_TAGS,
render: (value: Rule['tags']) => {
if (value != null && value.length > 0) {
if (value.length > 0) {
return <TagsDisplay tags={value} />;
}
return getEmptyTagValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import { TestProviders } from '../../../../../common/mock';
import { waitFor } from '@testing-library/react';
import { AllRules } from './index';

const mockTags = ['Elastic', 'Endpoint', 'Data Protection', 'ML', 'Continuous Monitoring'];

jest.mock('react-router-dom', () => {
const original = jest.requireActual('react-router-dom');

Expand Down Expand Up @@ -68,7 +66,7 @@ jest.mock('./reducer', () => {
risk_score: 73,
rule_id: '571afc56-5ed9-465d-a2a9-045f099f6e7e',
severity: 'high',
tags: mockTags,
tags: ['Elastic', 'Endpoint'],
threat: [],
throttle: null,
to: 'now',
Expand Down Expand Up @@ -114,7 +112,7 @@ jest.mock('../../../../containers/detection_engine/rules', () => {
risk_score: 73,
rule_id: '571afc56-5ed9-465d-a2a9-045f099f6e7e',
severity: 'high',
tags: mockTags,
tags: ['Elastic', 'Endpoint'],
threat: [],
throttle: null,
to: 'now',
Expand Down Expand Up @@ -211,12 +209,6 @@ describe('AllRules', () => {
});
});
});

it('visibly renders all tags', () => {
for (let i = 0; i < mockTags.length; i++) {
expect(wrapper.exists(`[data-test-subj="rules-table-column-tags-${i}"]`)).toBeTruthy();
}
});
});

it('renders monitoring tab when monitoring tab clicked', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,19 @@ interface TagsFilterPopoverProps {
isLoading: boolean; // TO DO reimplement?
}

const PopoverContentWrapper = styled.div`
width: 275px;
`;

const ScrollableDiv = styled.div`
max-height: 250px;
overflow: auto;
overflow-y: auto;
`;

const TagOverflowContainer = styled.span`
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
`;

/**
Expand All @@ -65,8 +75,9 @@ const TagsFilterPopoverComponent = ({
checked={selectedTags.includes(tag) ? 'on' : undefined}
key={`${index}-${tag}`}
onClick={() => toggleSelectedGroup(tag, selectedTags, onSelectedTagsChanged)}
title={tag}
>
{`${tag}`}
<TagOverflowContainer>{tag}</TagOverflowContainer>
</EuiFilterSelectItem>
));
}, [onSelectedTagsChanged, selectedTags, filterTags]);
Expand Down Expand Up @@ -101,25 +112,27 @@ const TagsFilterPopoverComponent = ({
panelPaddingSize="none"
repositionOnScroll
>
<EuiPopoverTitle>
<EuiFieldSearch
placeholder="Search tags"
value={searchInput}
onChange={onSearchInputChange}
isClearable
aria-label="Rules tag search"
/>
</EuiPopoverTitle>
<ScrollableDiv>{tagsComponent}</ScrollableDiv>
{filterTags.length === 0 && (
<EuiFlexGroup gutterSize="m" justifyContent="spaceAround">
<EuiFlexItem grow={true}>
<EuiPanel>
<EuiText>{i18n.NO_TAGS_AVAILABLE}</EuiText>
</EuiPanel>
</EuiFlexItem>
</EuiFlexGroup>
)}
<PopoverContentWrapper>
<EuiPopoverTitle>
<EuiFieldSearch
placeholder="Search tags"
value={searchInput}
onChange={onSearchInputChange}
isClearable
aria-label="Rules tag search"
/>
</EuiPopoverTitle>
<ScrollableDiv>{tagsComponent}</ScrollableDiv>
{filterTags.length === 0 && (
<EuiFlexGroup gutterSize="m" justifyContent="spaceAround">
<EuiFlexItem grow={true}>
<EuiPanel>
<EuiText>{i18n.NO_TAGS_AVAILABLE}</EuiText>
</EuiPanel>
</EuiFlexItem>
</EuiFlexGroup>
)}
</PopoverContentWrapper>
</EuiPopover>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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 { mount, ReactWrapper } from 'enzyme';

import { TagsDisplay } from './tag_display';
import { TestProviders } from '../../../../../common/mock';
import { waitFor } from '@testing-library/react';

const mockTags = ['Elastic', 'Endpoint', 'Data Protection', 'ML', 'Continuous Monitoring'];

describe('When tag display loads', () => {
let wrapper: ReactWrapper;
beforeEach(() => {
wrapper = mount(
<TestProviders>
<TagsDisplay tags={mockTags} />
</TestProviders>
);
});
it('visibly renders 3 initial tags', () => {
for (let i = 0; i < 3; i++) {
expect(wrapper.exists(`[data-test-subj="rules-table-column-tags-${i}"]`)).toBeTruthy();
}
});
describe("when the 'see all' button is clicked", () => {
beforeEach(() => {
const seeAllButton = wrapper.find('[data-test-subj="tags-display-popover-button"] button');
seeAllButton.simulate('click');
});
it('renders all the tags in the popover', async () => {
await waitFor(() => {
wrapper.update();
expect(wrapper.exists('[data-test-subj="tags-display-popover"]')).toBeTruthy();
for (let i = 0; i < mockTags.length; i++) {
expect(
wrapper.exists(`[data-test-subj="rules-table-column-popover-tags-${i}"]`)
).toBeTruthy();
}
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,7 @@
*/

import React, { useState } from 'react';
import {
EuiFlexGroup,
EuiFlexItem,
EuiPanel,
EuiPopover,
EuiText,
EuiFieldSearch,
EuiPopoverTitle,
EuiBadgeGroup,
EuiBadge,
EuiButtonEmpty,
} from '@elastic/eui';
import { EuiPopover, EuiBadgeGroup, EuiBadge, EuiButtonEmpty } from '@elastic/eui';
import styled from 'styled-components';
import * as i18n from '../translations';

Expand All @@ -29,7 +18,9 @@ const TagWrapper = styled(EuiBadgeGroup)`
`;

const TagPopoverWrapper = styled(EuiBadgeGroup)`
width: min-content;
max-height: 200px;
max-width: 600px;
overflow: auto;
`;

const TagPopoverButton = styled(EuiButtonEmpty)`
Expand Down Expand Up @@ -73,6 +64,7 @@ const TagsDisplayComponent = ({ tags }: TagsDisplayProps) => {
<EuiPopover
ownFocus
display="block"
data-test-subj="tags-display-popover"
button={
<TagPopoverButton
size="xs"
Expand Down

0 comments on commit bb163a9

Please sign in to comment.