Skip to content
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

[Security Solution][Endpoint] Tests and additional functionality for the Generic Artifact List page component #126400

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
68f4bf3
basic structure for test file
paul-tavares Feb 22, 2022
e9ba3ad
First test to validate loader is shown
paul-tavares Feb 22, 2022
3f52c80
Tests outline for artifact list page
paul-tavares Feb 22, 2022
4ef0c60
additional test placeholder
paul-tavares Feb 23, 2022
6b2e295
add additional test placdholder
paul-tavares Feb 24, 2022
f410f1e
Fix bug: ensure flyout calls `onSuccess()` when update is done
paul-tavares Feb 24, 2022
9eb0ac5
Support for proving a form submit handler
paul-tavares Feb 24, 2022
2670aff
Fix `useIsMounted()` hook and add its usage to the flyout
paul-tavares Feb 24, 2022
5a44e26
Several tests done
paul-tavares Feb 24, 2022
4150d7f
Fix some types in the tests
paul-tavares Feb 25, 2022
e34f543
tests for successful create
paul-tavares Feb 28, 2022
01f7f19
Merge remote-tracking branch 'upstream/main' into task/olm-2931-compl…
paul-tavares Mar 2, 2022
c6a0da3
Track isSubmitting depending on external or internal submit function
paul-tavares Mar 2, 2022
f5ce3c0
tests for external submit handler
paul-tavares Mar 3, 2022
578fe47
Some tests for edit mode
paul-tavares Mar 3, 2022
816cfa4
add return types to some translations properties
paul-tavares Mar 4, 2022
6cda1e2
Tests for flyout edit flow
paul-tavares Mar 4, 2022
0d91678
tests for sumit errors
paul-tavares Mar 4, 2022
c1b3879
fix export type
paul-tavares Mar 4, 2022
af10772
Merge remote-tracking branch 'upstream/main' into task/olm-2931-compl…
paul-tavares Mar 4, 2022
996387a
bug fix in TA http mocks
paul-tavares Mar 4, 2022
18c2fc4
Enhance http handler mock factory to provide the API options to the d…
paul-tavares Mar 4, 2022
6bb29f0
Initial set of UT for the card list
paul-tavares Mar 4, 2022
aa800f3
Change order of delay execution in http handler mock factory
paul-tavares Mar 7, 2022
fe2681e
fix Trusted Apps tests
paul-tavares Mar 7, 2022
0ea8772
Fix bug: add dataTestSubj to delete modal
paul-tavares Mar 7, 2022
39bafd8
tests for delete dialog
paul-tavares Mar 7, 2022
cbda992
Merge remote-tracking branch 'upstream/main' into task/olm-2931-compl…
paul-tavares Mar 7, 2022
2db0411
tests for interacting with the search bar
paul-tavares Mar 7, 2022
1c8769d
adjust changes made to http handler mock factoruy
paul-tavares Mar 7, 2022
aee99e5
Fix test failures due to shared state in user privileges
paul-tavares Mar 7, 2022
568670e
Merge remote-tracking branch 'upstream/main' into task/olm-2931-compl…
paul-tavares Mar 7, 2022
771d002
move onClick + test id to Button on search exceptions component
paul-tavares Mar 8, 2022
f9a84ee
some ore improvements to the http handler mock factory (?)
paul-tavares Mar 8, 2022
e733467
Merge remote-tracking branch 'upstream/main' into task/olm-2931-compl…
paul-tavares Mar 8, 2022
5801ef3
use generic Delete, create and update hooks for artifacts
paul-tavares Mar 8, 2022
8f46dc9
Use generic get hook for one artifct
paul-tavares Mar 8, 2022
77b204b
rename delete hook for distinction
paul-tavares Mar 8, 2022
5f651f2
use generic `useListArtifact()` hook + improvements to list hook code
paul-tavares Mar 8, 2022
567512e
add types to `useUrlParams` and delete custom `useUrlParams` from `Ar…
paul-tavares Mar 8, 2022
1cfbc8a
adjust comment
paul-tavares Mar 8, 2022
8500307
Fix flyout call to check if data exists
paul-tavares Mar 8, 2022
45f5f8f
Merge remote-tracking branch 'upstream/main' into task/olm-2931-compl…
paul-tavares Mar 8, 2022
96f15f2
skipping the test failures - white flag waiving :-(
paul-tavares Mar 9, 2022
d03392f
Merge remote-tracking branch 'upstream/main' into task/olm-2931-compl…
paul-tavares Mar 9, 2022
f55fe75
Merge remote-tracking branch 'upstream/main' into task/olm-2931-compl…
paul-tavares Mar 9, 2022
9d1f230
Merge branch 'main' into task/olm-2931-complete-generic-artifact-list…
kibanamachine Mar 9, 2022
cd3c5c8
Fix bug: drop `itemId` from url when edit item is not found.
paul-tavares Mar 9, 2022
73eb36f
Merge remote-tracking branch 'origin/task/olm-2931-complete-generic-a…
paul-tavares Mar 9, 2022
834dfcf
fix a few more instance of not clearing the correct url param
paul-tavares Mar 9, 2022
d895c30
Fix `doesDataExists` not updating when going from No data -to- user c…
paul-tavares Mar 9, 2022
628be5a
fix types
paul-tavares Mar 10, 2022
59c6cb3
Merge remote-tracking branch 'upstream/main' into task/olm-2931-compl…
paul-tavares Mar 10, 2022
8c7b72e
Fix rendering of the flyout
paul-tavares Mar 10, 2022
c02d07c
Rename artifact flyout component
paul-tavares Mar 10, 2022
918031d
Merge branch 'main' into task/olm-2931-complete-generic-artifact-list…
kibanamachine Mar 10, 2022
c56beb4
use `.toBeEnabled()` assertion
paul-tavares Mar 10, 2022
0c8c16b
Fix closing of flyout after an edit not clearing the item from state
paul-tavares Mar 10, 2022
0a5bcea
Fix bug in search handler that was causing 2 api requests
paul-tavares Mar 10, 2022
55a3d90
Merge remote-tracking branch 'origin/task/olm-2931-complete-generic-a…
paul-tavares Mar 10, 2022
316e69a
Merge remote-tracking branch 'upstream/main' into task/olm-2931-compl…
paul-tavares Mar 10, 2022
c6c9270
Merge branch 'main' into task/olm-2931-complete-generic-artifact-list…
paul-tavares Mar 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ type SingleResponseProvider<F extends ResponseProviderCallback = ResponseProvide
* Delay responding to the HTTP call until this promise is resolved. Use it to introduce
* elongated delays in order to test intermediate UI states.
*
* @param options
*
* @example
* apiMocks.responseProvider.someProvider.mockDelay
* // Delay this response by 1/2 second
* .mockImplementation(
* () => new Promise(r => setTimeout(r, 500))
* )
*/
mockDelay: jest.MockedFunction<() => Promise<void>>;
mockDelay: jest.MockedFunction<(options: HttpFetchOptionsWithPath) => Promise<void>>;
};

/**
Expand Down Expand Up @@ -99,9 +101,9 @@ interface RouteMock<R extends ResponseProvidersInterface = ResponseProvidersInte
/**
* A function that returns a promise. The API response will be delayed until this promise is
* resolved. This can be helpful when wanting to test an intermediate UI state while the API
* call is inflight.
* call is inflight. The options provided to the `core.http.*` method will be provided on input
*/
delay?: () => Promise<void>;
delay?: (options: HttpFetchOptionsWithPath) => Promise<void>;
}

export type ApiHandlerMockFactoryProps<
Expand Down Expand Up @@ -134,14 +136,10 @@ export const httpHandlerMockFactory = <R extends ResponseProvidersInterface = {}
let inflightApiCalls = 0;
const { ignoreUnMockedApiRouteErrors = false } = options ?? {};
const apiDoneListeners: Array<() => void> = [];
const markApiCallAsHandled = async (delay?: RouteMock['delay']) => {
const markApiCallAsInFlight = () => {
inflightApiCalls++;

// If a delay was defined, then await that first
if (delay) {
await delay();
}

};
const markApiCallAsHandled = async () => {
// We always wait at least 1ms
await new Promise((r) => setTimeout(r, 1));

Expand Down Expand Up @@ -200,10 +198,7 @@ export const httpHandlerMockFactory = <R extends ResponseProvidersInterface = {}
// Use the handler defined for the HTTP Mocked interface (not the one passed on input to
// the factory) for retrieving the response value because that one could have had its
// response value manipulated by the individual test case.

markApiCallAsHandled(responseProvider[routeMock.id].mockDelay);
await responseProvider[routeMock.id].mockDelay();

const thisRouteResponseProvider = responseProvider[routeMock.id];
const fetchOptions: HttpFetchOptionsWithPath = isHttpFetchOptionsWithPath(args[0])
? args[0]
: {
Expand All @@ -215,7 +210,21 @@ export const httpHandlerMockFactory = <R extends ResponseProvidersInterface = {}
path: args[0],
};

return responseProvider[routeMock.id](fetchOptions);
markApiCallAsInFlight();

// If a delay was defined, then wait for that to complete
if (thisRouteResponseProvider.mockDelay) {
await thisRouteResponseProvider.mockDelay(fetchOptions);
}

try {
return thisRouteResponseProvider(fetchOptions);
} catch (err) {
err.stack += `\n${testContextStackTrace}`;
return Promise.reject(err);
} finally {
markApiCallAsHandled();
}
} else if (priorMockedFunction) {
return priorMockedFunction(...args);
}
Expand Down
Loading