-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'lens/migrate_show_values_stage_2' of github.com:mbondyr…
…a/kibana into lens/migrate_show_values_stage_2 # Conflicts: # x-pack/plugins/lens/public/visualizations/partition/visualization.test.ts # x-pack/plugins/lens/public/visualizations/xy/visualization.test.tsx # x-pack/plugins/security_solution/server/lib/dashboards/__mocks__/index.ts # x-pack/plugins/security_solution/server/lib/detection_engine/rule_monitoring/logic/detection_engine_health/assets/dashboard_rule_monitoring.json
- Loading branch information
Showing
696 changed files
with
6,124 additions
and
2,297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
202 changes: 202 additions & 0 deletions
202
packages/content-management/table_list_view_table/src/__jest__/created_by.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,202 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import { render, screen, within, waitForElementToBeRemoved } from '@testing-library/react'; | ||
import { I18nProvider } from '@kbn/i18n-react'; | ||
import { WithServices } from './tests.helpers'; | ||
import { TableListViewTable, type TableListViewTableProps } from '../table_list_view_table'; | ||
import type { UserContentCommonSchema } from '@kbn/content-management-table-list-view-common'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
const hits: UserContentCommonSchema[] = [ | ||
{ | ||
id: 'item-1', | ||
type: 'dashboard', | ||
updatedAt: '2020-01-01T00:00:00Z', | ||
attributes: { | ||
title: 'Item 1', | ||
}, | ||
references: [], | ||
}, | ||
{ | ||
id: 'item-2', | ||
type: 'dashboard', | ||
updatedAt: '2020-01-01T00:00:00Z', | ||
attributes: { | ||
title: 'Item 2', | ||
}, | ||
createdBy: 'u_1', | ||
references: [], | ||
}, | ||
{ | ||
id: 'item-3', | ||
type: 'dashboard', | ||
updatedAt: '2020-01-01T00:00:00Z', | ||
attributes: { | ||
title: 'Item 3', | ||
}, | ||
createdBy: 'u_2', | ||
references: [], | ||
}, | ||
]; | ||
|
||
describe('created_by', () => { | ||
const requiredProps: TableListViewTableProps = { | ||
entityName: 'test', | ||
entityNamePlural: 'tests', | ||
listingLimit: 500, | ||
initialFilter: '', | ||
initialPageSize: 20, | ||
findItems: jest.fn().mockResolvedValue({ total: 0, hits }), | ||
getDetailViewLink: () => 'http://elastic.co', | ||
urlStateEnabled: false, | ||
onFetchSuccess: () => {}, | ||
tableCaption: 'my caption', | ||
setPageDataTestSubject: () => {}, | ||
}; | ||
|
||
const mockBulkGetUserProfiles = jest.fn((uids) => | ||
Promise.resolve( | ||
[ | ||
{ | ||
uid: 'u_1', | ||
enabled: true, | ||
user: { | ||
username: 'user1', | ||
}, | ||
data: {}, | ||
}, | ||
{ | ||
uid: 'u_2', | ||
enabled: true, | ||
user: { | ||
username: 'user2', | ||
}, | ||
data: {}, | ||
}, | ||
].filter((user) => uids.includes(user.uid)) | ||
) | ||
); | ||
|
||
const TableListViewWithServices = WithServices<TableListViewTableProps>(TableListViewTable, { | ||
bulkGetUserProfiles: mockBulkGetUserProfiles, | ||
}); | ||
const TableListView = (overrides: Partial<TableListViewTableProps>) => ( | ||
<I18nProvider> | ||
<MemoryRouter> | ||
<TableListViewWithServices {...requiredProps} {...overrides} /> | ||
</MemoryRouter> | ||
</I18nProvider> | ||
); | ||
|
||
test("shouldn't render created by filter when createdBy is disabled", async () => { | ||
render(<TableListView {...requiredProps} />); | ||
|
||
// wait until first render | ||
expect(await screen.findByTestId('itemsInMemTable')).toBeVisible(); | ||
|
||
expect(() => screen.getByTestId('userFilterPopoverButton')).toThrow(); | ||
}); | ||
|
||
test('should be able to filter by creators', async () => { | ||
render(<TableListView {...requiredProps} createdByEnabled={true} />); | ||
|
||
// wait until first render | ||
expect(await screen.findByTestId('itemsInMemTable')).toBeVisible(); | ||
|
||
// 3 items in the list | ||
expect(screen.getAllByTestId(/userContentListingTitleLink/)).toHaveLength(3); | ||
|
||
userEvent.click(screen.getByTestId('userFilterPopoverButton')); | ||
|
||
const userSelectablePopover = screen.getByTestId('userSelectableList'); | ||
const popover = within(userSelectablePopover); | ||
expect(await popover.findAllByTestId(/userProfileSelectableOption/)).toHaveLength(3); | ||
|
||
userEvent.click(popover.getByTestId('userProfileSelectableOption-user1')); | ||
|
||
// 2 item in the list | ||
expect(screen.getAllByTestId(/userContentListingTitleLink/)).toHaveLength(1); | ||
|
||
userEvent.click(popover.getByTestId('userProfileSelectableOption-user2')); | ||
|
||
// 2 item in the list | ||
expect(screen.getAllByTestId(/userContentListingTitleLink/)).toHaveLength(2); | ||
}); | ||
|
||
test('should be able to filter by "no creators"', async () => { | ||
render(<TableListView {...requiredProps} createdByEnabled={true} />); | ||
|
||
// wait until first render | ||
expect(await screen.findByTestId('itemsInMemTable')).toBeVisible(); | ||
|
||
// 3 items in the list | ||
expect(screen.getAllByTestId(/userContentListingTitleLink/)).toHaveLength(3); | ||
|
||
userEvent.click(screen.getByTestId('userFilterPopoverButton')); | ||
|
||
const userSelectablePopover = screen.getByTestId('userSelectableList'); | ||
const popover = within(userSelectablePopover); | ||
userEvent.click(await popover.findByTestId('userProfileSelectableOption-null')); | ||
|
||
// just 1 item in the list | ||
expect(screen.getAllByTestId(/userContentListingTitleLink/)).toHaveLength(1); | ||
}); | ||
|
||
test('"no creators" options shouldn\'t appear if all objects have creators', async () => { | ||
render( | ||
<TableListView | ||
{...requiredProps} | ||
createdByEnabled={true} | ||
findItems={async () => ({ | ||
hits: [hits[1], hits[2]], | ||
total: 2, | ||
})} | ||
/> | ||
); | ||
|
||
// wait until first render | ||
expect(await screen.findByTestId('itemsInMemTable')).toBeVisible(); | ||
// 2 items in the list | ||
expect(screen.getAllByTestId(/userContentListingTitleLink/)).toHaveLength(2); | ||
|
||
userEvent.click(screen.getByTestId('userFilterPopoverButton')); | ||
|
||
const userSelectablePopover = screen.getByTestId('userSelectableList'); | ||
const popover = within(userSelectablePopover); | ||
expect(await popover.findAllByTestId(/userProfileSelectableOption/)).toHaveLength(2); | ||
expect(() => popover.getByTestId('userProfileSelectableOption-null')).toThrow(); | ||
}); | ||
|
||
test('empty message in case no objects have creators', async () => { | ||
render( | ||
<TableListView | ||
{...requiredProps} | ||
createdByEnabled={true} | ||
findItems={async () => ({ | ||
hits: [hits[0]], | ||
total: 1, | ||
})} | ||
/> | ||
); | ||
|
||
// wait until first render | ||
expect(await screen.findByTestId('itemsInMemTable')).toBeVisible(); | ||
// 1 item in the list | ||
expect(screen.getAllByTestId(/userContentListingTitleLink/)).toHaveLength(1); | ||
|
||
userEvent.click(screen.getByTestId('userFilterPopoverButton')); | ||
|
||
const userSelectablePopover = screen.getByTestId('userSelectableList'); | ||
const popover = within(userSelectablePopover); | ||
await waitForElementToBeRemoved(() => popover.getByRole('progressbar')); | ||
expect(popover.getAllByTestId('userFilterEmptyMessage')[1]).toBeVisible(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.