Skip to content

Commit 93cfcd9

Browse files
add tests
1 parent 3de63d4 commit 93cfcd9

3 files changed

Lines changed: 49 additions & 2 deletions

File tree

x-pack/plugins/index_management/__jest__/client_integration/index_details_page/index_details_page.helpers.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ export interface IndexDetailsPageTestBed extends TestBed {
5151
isDisplayed: () => boolean;
5252
clickReloadButton: () => Promise<void>;
5353
};
54+
statsTab: {
55+
indexStatsContentExists: () => boolean;
56+
indexStatsTabExists: () => boolean;
57+
};
5458
};
5559
}
5660

@@ -135,6 +139,15 @@ export const setup = async (
135139
component.update();
136140
},
137141
};
142+
143+
const statsTab = {
144+
indexStatsContentExists: () => {
145+
return exists('statsTabContent');
146+
},
147+
indexStatsTabExists: () => {
148+
return exists('indexDetailsTab-stats');
149+
},
150+
};
138151
return {
139152
...testBed,
140153
routerMock,
@@ -146,6 +159,7 @@ export const setup = async (
146159
discoverLinkExists,
147160
contextMenu,
148161
errorSection,
162+
statsTab,
149163
},
150164
};
151165
};

x-pack/plugins/index_management/__jest__/client_integration/index_details_page/index_details_page.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,39 @@ describe('<IndexDetailsPage />', () => {
6060
});
6161
});
6262

63+
describe('Stats tab', () => {
64+
it('loads index stats from the API', async () => {
65+
const numberOfRequests = 1;
66+
// Expect initial request to fetch index details
67+
expect(httpSetup.get).toHaveBeenCalledTimes(numberOfRequests);
68+
69+
await testBed.actions.clickIndexDetailsTab(IndexDetailsSection.Stats);
70+
expect(httpSetup.get).toHaveBeenLastCalledWith(`${API_BASE_PATH}/stats/${testIndexName}`, {
71+
asSystemRequest: undefined,
72+
body: undefined,
73+
query: undefined,
74+
version: undefined,
75+
});
76+
expect(httpSetup.get).toHaveBeenCalledTimes(numberOfRequests + 1);
77+
});
78+
79+
it('renders index stats', async () => {
80+
await testBed.actions.clickIndexDetailsTab(IndexDetailsSection.Stats);
81+
expect(testBed.actions.statsTab.indexStatsContentExists()).toBe(true);
82+
});
83+
84+
it('hides index stats tab if enableIndexStats===false', async () => {
85+
await act(async () => {
86+
testBed = await setup(httpSetup, {
87+
config: { enableIndexStats: false },
88+
});
89+
});
90+
testBed.component.update();
91+
92+
expect(testBed.actions.statsTab.indexStatsTabExists()).toBe(false);
93+
});
94+
});
95+
6396
it('loads index details from the API', async () => {
6497
expect(httpSetup.get).toHaveBeenLastCalledWith(
6598
`${INTERNAL_API_BASE_PATH}/indices/${testIndexName}`,

x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/tabs/stats.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export const StatsTab: React.FunctionComponent<Props> = ({ indexName }) => {
8888

8989
if (indexStats) {
9090
return (
91-
<EuiFlexGroup alignItems="flexStart">
91+
<EuiFlexGroup alignItems="flexStart" data-test-subj="statsTabContent">
9292
<EuiFlexItem grow={7}>
9393
<EuiPanel>
9494
<EuiCodeBlock isCopyable language="json" fontSize="m" paddingSize="m">
@@ -120,7 +120,7 @@ export const StatsTab: React.FunctionComponent<Props> = ({ indexName }) => {
120120
<p>
121121
<FormattedMessage
122122
id="xpack.idxMgmt.indexDetails.indexStatsTab.indexStatsDescription"
123-
defaultMessage="Index stats contains high-level aggregation and statistics for an index. The {primariesField} field represents the values for only primary shards, while the {totalField} field contains the accumulated values for both primary and replica shards."
123+
defaultMessage="Index stats contain high-level aggregation and statistics for an index. The {primariesField} field represents the values for only primary shards, while the {totalField} field contains the accumulated values for both primary and replica shards."
124124
values={{
125125
primariesField: <EuiCode>primaries</EuiCode>,
126126
totalField: <EuiCode>total</EuiCode>,

0 commit comments

Comments
 (0)