-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Index Management] Index details page: loading index data #163955
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
65900a7
0a8e6cf
ba1b14a
597ad61
f1b6bfe
6afdf1b
ef75f51
18c620d
bf74fe8
5e89667
10ee5d9
0837329
41b0f66
d435d28
e5f683e
f82bc7d
fb0fa06
0d6f9eb
1c3e39d
616f729
8e30328
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,22 +8,57 @@ | |
| import { setupEnvironment } from '../helpers'; | ||
| import { IndexDetailsPageTestBed, setup } from './index_details_page.helpers'; | ||
| import { act } from 'react-dom/test-utils'; | ||
| import { httpServiceMock } from '@kbn/core/public/mocks'; | ||
| import { IndexDetailsSection } from '../../../public/application/sections/home/index_list/details_page'; | ||
| import { testIndexMock } from './mocks'; | ||
|
|
||
| describe('<IndexDetailsPage />', () => { | ||
| let testBed: IndexDetailsPageTestBed; | ||
| let httpSetup: ReturnType<typeof setupEnvironment>['httpSetup']; | ||
| let httpRequestsMockHelpers: ReturnType<typeof setupEnvironment>['httpRequestsMockHelpers']; | ||
|
|
||
| beforeEach(async () => { | ||
| httpSetup = httpServiceMock.createSetupContract(); | ||
| const mockEnvironment = setupEnvironment(); | ||
| ({ httpSetup, httpRequestsMockHelpers } = mockEnvironment); | ||
| // test_index is configured in initialEntries of the memory router | ||
| httpRequestsMockHelpers.setLoadIndexDetailsResponse('test_index', testIndexMock); | ||
|
|
||
| await act(async () => { | ||
| testBed = await setup(httpSetup); | ||
| testBed = await setup(httpSetup, { | ||
| url: { | ||
| locators: { | ||
| get: () => ({ navigate: jest.fn() }), | ||
| }, | ||
| }, | ||
| }); | ||
| }); | ||
| testBed.component.update(); | ||
| }); | ||
|
|
||
| describe('error section', () => { | ||
| beforeEach(async () => { | ||
| httpRequestsMockHelpers.setLoadIndexDetailsResponse('test_index', undefined, { | ||
| statusCode: 400, | ||
| message: 'Data for index .apm-agent-configuration was not found', | ||
| }); | ||
| await act(async () => { | ||
| testBed = await setup(httpSetup); | ||
| }); | ||
|
|
||
| testBed.component.update(); | ||
| }); | ||
| it('displays an error callout when failed to load index details', async () => { | ||
| expect(testBed.actions.errorSection.isDisplayed()).toBe(true); | ||
| }); | ||
|
|
||
| it('resends a request when reload button is clicked', async () => { | ||
| // already sent 2 requests while setting up the component | ||
| const numberOfRequests = 2; | ||
| expect(httpSetup.get).toHaveBeenCalledTimes(numberOfRequests); | ||
| await testBed.actions.errorSection.clickReloadButton(); | ||
| expect(httpSetup.get).toHaveBeenCalledTimes(numberOfRequests + 1); | ||
| }); | ||
| }); | ||
|
|
||
| it('displays index name in the header', () => { | ||
| const header = testBed.actions.getHeader(); | ||
| // test_index is configured in initialEntries of the memory router | ||
|
|
@@ -58,4 +93,25 @@ describe('<IndexDetailsPage />', () => { | |
| const tabContent = testBed.actions.getActiveTabContent(); | ||
| expect(tabContent).toEqual('Pipelines'); | ||
| }); | ||
|
|
||
| it('navigates back to indices', async () => { | ||
| jest.spyOn(testBed.routerMock.history, 'push'); | ||
| await testBed.actions.clickBackToIndicesButton(); | ||
| expect(testBed.routerMock.history.push).toHaveBeenCalledTimes(1); | ||
| expect(testBed.routerMock.history.push).toHaveBeenCalledWith('/indices'); | ||
| }); | ||
|
|
||
| it('renders a link to discover', () => { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. only testing that the button is displayed, since the discover link component has its own tests
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it make sense to add a comment to this effect in the code? |
||
| // we only need to test that the link is rendered since the link component has its own tests for navigation | ||
| expect(testBed.actions.discoverLinkExists()).toBe(true); | ||
| }); | ||
|
|
||
| it('opens an index context menu when "manage index" button is clicked', async () => { | ||
| const { | ||
| actions: { contextMenu }, | ||
| } = testBed; | ||
| expect(contextMenu.isOpened()).toBe(false); | ||
| await testBed.actions.contextMenu.clickManageIndexButton(); | ||
| expect(contextMenu.isOpened()).toBe(true); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| * 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; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| import { Index } from '../../../public'; | ||
|
|
||
| export const testIndexMock: Index = { | ||
| health: 'green', | ||
| status: 'open', | ||
| name: 'test_index', | ||
| uuid: 'test1234', | ||
| primary: '1', | ||
| replica: '1', | ||
| documents: 1, | ||
| documents_deleted: 0, | ||
| size: '10kb', | ||
| primary_size: '10kb', | ||
| isFrozen: false, | ||
| aliases: 'none', | ||
| hidden: false, | ||
| isRollupIndex: false, | ||
| ilm: { | ||
| index: 'test_index', | ||
| managed: false, | ||
| }, | ||
| isFollowerIndex: false, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| /* | ||
| * 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; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
| import React from 'react'; | ||
| import { mountWithIntl } from '@kbn/test-jest-helpers'; | ||
| import { EuiButtonIcon } from '@elastic/eui'; | ||
| import { DiscoverLink } from './discover_link'; | ||
| import { AppContextProvider, AppDependencies } from '../app_context'; | ||
|
|
||
| describe('DiscoverLink', () => { | ||
| const indexName = 'my-fancy-index'; | ||
|
|
||
| it('renders the link as an icon by default', async () => { | ||
| const navigateMock = jest.fn(); | ||
| const ctx = { | ||
| url: { | ||
| locators: { | ||
| get: () => ({ navigate: navigateMock }), | ||
| }, | ||
| }, | ||
| } as unknown as AppDependencies; | ||
|
|
||
| const component = mountWithIntl( | ||
| <AppContextProvider value={ctx}> | ||
| <DiscoverLink indexName={indexName} /> | ||
| </AppContextProvider> | ||
| ); | ||
|
|
||
| expect(component.exists('[data-test-subj="discoverIconLink"]')).toBe(true); | ||
| expect(component.exists('[data-test-subj="discoverButtonLink"]')).toBe(false); | ||
| }); | ||
|
|
||
| it('renders the link as a button if the prop is set', async () => { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These tests are mostly from the renamed file |
||
| const navigateMock = jest.fn(); | ||
| const ctx = { | ||
| url: { | ||
| locators: { | ||
| get: () => ({ navigate: navigateMock }), | ||
| }, | ||
| }, | ||
| } as unknown as AppDependencies; | ||
|
|
||
| const component = mountWithIntl( | ||
| <AppContextProvider value={ctx}> | ||
| <DiscoverLink indexName={indexName} asButton={true} /> | ||
| </AppContextProvider> | ||
| ); | ||
|
|
||
| expect(component.exists('[data-test-subj="discoverIconLink"]')).toBe(false); | ||
| expect(component.exists('[data-test-subj="discoverButtonLink"]')).toBe(true); | ||
| }); | ||
|
|
||
| it('calls navigate method when button is clicked', async () => { | ||
| const navigateMock = jest.fn(); | ||
| const ctx = { | ||
| url: { | ||
| locators: { | ||
| get: () => ({ navigate: navigateMock }), | ||
| }, | ||
| }, | ||
| } as unknown as AppDependencies; | ||
|
|
||
| const component = mountWithIntl( | ||
| <AppContextProvider value={ctx}> | ||
| <DiscoverLink indexName={indexName} /> | ||
| </AppContextProvider> | ||
| ); | ||
| const button = component.find(EuiButtonIcon); | ||
|
|
||
| await button.simulate('click'); | ||
| expect(navigateMock).toHaveBeenCalledWith({ dataViewSpec: { title: indexName } }); | ||
| }); | ||
|
|
||
| it('does not render a button if locators is not defined', () => { | ||
| const ctx = {} as unknown as AppDependencies; | ||
|
|
||
| const component = mountWithIntl( | ||
| <AppContextProvider value={ctx}> | ||
| <DiscoverLink indexName={indexName} /> | ||
| </AppContextProvider> | ||
| ); | ||
| const button = component.find(EuiButtonIcon); | ||
|
|
||
| expect(button).toHaveLength(0); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not testing the loading indicator here, because I think I could re-use what @sabarasaba implemented for enrich policies here. So I'm planning to add the test later when enrich policies are merged into main.