Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth committed Aug 28, 2023
1 parent 3de63d4 commit 93cfcd9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export interface IndexDetailsPageTestBed extends TestBed {
isDisplayed: () => boolean;
clickReloadButton: () => Promise<void>;
};
statsTab: {
indexStatsContentExists: () => boolean;
indexStatsTabExists: () => boolean;
};
};
}

Expand Down Expand Up @@ -135,6 +139,15 @@ export const setup = async (
component.update();
},
};

const statsTab = {
indexStatsContentExists: () => {
return exists('statsTabContent');
},
indexStatsTabExists: () => {
return exists('indexDetailsTab-stats');
},
};
return {
...testBed,
routerMock,
Expand All @@ -146,6 +159,7 @@ export const setup = async (
discoverLinkExists,
contextMenu,
errorSection,
statsTab,
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,39 @@ describe('<IndexDetailsPage />', () => {
});
});

describe('Stats tab', () => {
it('loads index stats from the API', async () => {
const numberOfRequests = 1;
// Expect initial request to fetch index details
expect(httpSetup.get).toHaveBeenCalledTimes(numberOfRequests);

await testBed.actions.clickIndexDetailsTab(IndexDetailsSection.Stats);
expect(httpSetup.get).toHaveBeenLastCalledWith(`${API_BASE_PATH}/stats/${testIndexName}`, {
asSystemRequest: undefined,
body: undefined,
query: undefined,
version: undefined,
});
expect(httpSetup.get).toHaveBeenCalledTimes(numberOfRequests + 1);
});

it('renders index stats', async () => {
await testBed.actions.clickIndexDetailsTab(IndexDetailsSection.Stats);
expect(testBed.actions.statsTab.indexStatsContentExists()).toBe(true);
});

it('hides index stats tab if enableIndexStats===false', async () => {
await act(async () => {
testBed = await setup(httpSetup, {
config: { enableIndexStats: false },
});
});
testBed.component.update();

expect(testBed.actions.statsTab.indexStatsTabExists()).toBe(false);
});
});

it('loads index details from the API', async () => {
expect(httpSetup.get).toHaveBeenLastCalledWith(
`${INTERNAL_API_BASE_PATH}/indices/${testIndexName}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const StatsTab: React.FunctionComponent<Props> = ({ indexName }) => {

if (indexStats) {
return (
<EuiFlexGroup alignItems="flexStart">
<EuiFlexGroup alignItems="flexStart" data-test-subj="statsTabContent">
<EuiFlexItem grow={7}>
<EuiPanel>
<EuiCodeBlock isCopyable language="json" fontSize="m" paddingSize="m">
Expand Down Expand Up @@ -120,7 +120,7 @@ export const StatsTab: React.FunctionComponent<Props> = ({ indexName }) => {
<p>
<FormattedMessage
id="xpack.idxMgmt.indexDetails.indexStatsTab.indexStatsDescription"
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."
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."
values={{
primariesField: <EuiCode>primaries</EuiCode>,
totalField: <EuiCode>total</EuiCode>,
Expand Down

0 comments on commit 93cfcd9

Please sign in to comment.