Skip to content

Commit 25e1430

Browse files
committed
add test
1 parent 5780082 commit 25e1430

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

x-pack/plugins/security_solution/public/management/pages/endpoint_hosts/store/mock_endpoint_result_list.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ export const mockEndpointResultList: (options?: {
3232
total?: number;
3333
request_page_size?: number;
3434
request_page_index?: number;
35+
query_strategy_version?: MetadataQueryStrategyVersions;
3536
}) => HostResultList = (options = {}) => {
3637
const {
3738
total = 1,
3839
request_page_size: requestPageSize = 10,
3940
request_page_index: requestPageIndex = 0,
41+
query_strategy_version: queryStrategyVersion = MetadataQueryStrategyVersions.VERSION_2,
4042
} = options;
4143

4244
// Skip any that are before the page we're on
@@ -50,15 +52,15 @@ export const mockEndpointResultList: (options?: {
5052
hosts.push({
5153
metadata: generator.generateHostMetadata(),
5254
host_status: HostStatus.ERROR,
53-
query_strategy_version: MetadataQueryStrategyVersions.VERSION_2,
55+
query_strategy_version: queryStrategyVersion,
5456
});
5557
}
5658
const mock: HostResultList = {
5759
hosts,
5860
total,
5961
request_page_size: requestPageSize,
6062
request_page_index: requestPageIndex,
61-
query_strategy_version: MetadataQueryStrategyVersions.VERSION_2,
63+
query_strategy_version: queryStrategyVersion,
6264
};
6365
return mock;
6466
};
@@ -84,13 +86,15 @@ const endpointListApiPathHandlerMocks = ({
8486
endpointPackagePolicies = [],
8587
policyResponse = generator.generatePolicyResponse(),
8688
agentPolicy = generator.generateAgentPolicy(),
89+
queryStrategyVersion = MetadataQueryStrategyVersions.VERSION_2,
8790
}: {
8891
/** route handlers will be setup for each individual host in this array */
8992
endpointsResults?: HostResultList['hosts'];
9093
epmPackages?: GetPackagesResponse['response'];
9194
endpointPackagePolicies?: GetPolicyListResponse['items'];
9295
policyResponse?: HostPolicyResponse;
9396
agentPolicy?: GetAgentPoliciesResponseItem;
97+
queryStrategyVersion?: MetadataQueryStrategyVersions;
9498
} = {}) => {
9599
const apiHandlers = {
96100
// endpoint package info
@@ -107,7 +111,7 @@ const endpointListApiPathHandlerMocks = ({
107111
request_page_size: 10,
108112
request_page_index: 0,
109113
total: endpointsResults?.length || 0,
110-
query_strategy_version: MetadataQueryStrategyVersions.VERSION_2,
114+
query_strategy_version: queryStrategyVersion,
111115
};
112116
},
113117

@@ -164,11 +168,16 @@ export const setEndpointListApiMockImplementation: (
164168
apiResponses?: Parameters<typeof endpointListApiPathHandlerMocks>[0]
165169
) => void = (
166170
mockedHttpService,
167-
{ endpointsResults = mockEndpointResultList({ total: 3 }).hosts, ...pathHandlersOptions } = {}
171+
{
172+
endpointsResults = mockEndpointResultList({ total: 3 }).hosts,
173+
queryStrategyVersion = MetadataQueryStrategyVersions.VERSION_2,
174+
...pathHandlersOptions
175+
} = {}
168176
) => {
169177
const apiHandlers = endpointListApiPathHandlerMocks({
170178
...pathHandlersOptions,
171179
endpointsResults,
180+
queryStrategyVersion,
172181
});
173182

174183
mockedHttpService.post

x-pack/plugins/security_solution/public/management/pages/endpoint_hosts/view/index.test.tsx

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,34 @@ describe('when on the list page', () => {
108108
});
109109
});
110110

111+
describe('when loading data with the query_strategy_version is `v1`', () => {
112+
beforeEach(() => {
113+
reactTestingLibrary.act(() => {
114+
const mockedEndpointListData = mockEndpointResultList({
115+
total: 4,
116+
query_strategy_version: MetadataQueryStrategyVersions.VERSION_1,
117+
});
118+
setEndpointListApiMockImplementation(coreStart.http, {
119+
endpointsResults: mockedEndpointListData.hosts,
120+
queryStrategyVersion: mockedEndpointListData.query_strategy_version,
121+
});
122+
});
123+
});
124+
afterEach(() => {
125+
jest.clearAllMocks();
126+
});
127+
it('should not display the KQL bar', async () => {
128+
const renderResult = render();
129+
await reactTestingLibrary.act(async () => {
130+
await middlewareSpy.waitForAction('serverReturnedEndpointList');
131+
});
132+
// const adminSearchBar = await renderResult.findByTestId('adminSearchBar');
133+
return renderResult.findByTestId('adminSearchBar').catch((e) => {
134+
expect(e).not.toBeNull();
135+
});
136+
});
137+
});
138+
111139
describe('when there is no selected host in the url', () => {
112140
it('should not show the flyout', () => {
113141
const renderResult = render();
@@ -132,7 +160,6 @@ describe('when on the list page', () => {
132160
hostListData[index] = {
133161
metadata: hostListData[index].metadata,
134162
host_status: status,
135-
query_strategy_version: MetadataQueryStrategyVersions.VERSION_2,
136163
};
137164
}
138165
);
@@ -686,7 +713,6 @@ describe('when on the list page', () => {
686713
hostInfo = {
687714
host_status: hosts[0].host_status,
688715
metadata: hosts[0].metadata,
689-
query_strategy_version: MetadataQueryStrategyVersions.VERSION_2,
690716
};
691717
const packagePolicy = docGenerator.generatePolicyPackagePolicy();
692718
packagePolicy.id = hosts[0].metadata.Endpoint.policy.applied.id;

0 commit comments

Comments
 (0)