[Fleet] Fix tag creation (#138603) (#138620)

(cherry picked from commit cee2689116)

Co-authored-by: Nicolas Chaulet <nicolas.chaulet@elastic.co>
This commit is contained in:
Kibana Machine 2022-08-11 11:27:11 -04:00 committed by GitHub
parent 0acef82ef3
commit 93b1898599
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View file

@ -108,6 +108,27 @@ describe('TagsAddRemove', () => {
);
});
it('should show allow to add new tag when agent do not have any tags', () => {
allTags = [];
selectedTags = [];
const result = renderComponent('agent1');
const searchInput = result.getByTestId('addRemoveTags');
fireEvent.input(searchInput, {
target: { value: 'tag' },
});
fireEvent.click(result.getByTestId('createTagBtn'));
expect(mockUpdateTags).toHaveBeenCalledWith(
'agent1',
['tag'],
expect.anything(),
'Tag created',
'Tag creation failed'
);
});
it('should add new tag when not found in search and button clicked', () => {
const result = renderComponent('agent1');
const searchInput = result.getByRole('combobox');

View file

@ -212,7 +212,7 @@ export const TagsAddRemove: React.FC<Props> = ({
</Fragment>
)}
</EuiSelectable>
{!isExactMatch && labels.length && searchValue !== '' ? createTagButton : null}
{(!isExactMatch || labels.length === 0) && searchValue !== '' ? createTagButton : null}
</EuiWrappingPopover>
</>
);