-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: introduce reusable functions for validating agent API requests …
…and endpoint rendering in various system collector tables
- Loading branch information
1 parent
2f357df
commit 924e8e6
Showing
8 changed files
with
140 additions
and
221 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
...in/public/components/agents/syscollector/components/check-endpoint-for-given-agent-id.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
|
||
const AGENT_000 = '000'; | ||
const AGENT_001 = '001'; | ||
|
||
export function shouldRenderTableWithCorrectEndpointForAgent( | ||
mocked: jest.Mock, | ||
Component: React.ComponentType<{ | ||
agent: { id: string }; | ||
soPlatform?: string; | ||
}>, | ||
endpoint: string, | ||
soPlatform: string = 'linux', | ||
) { | ||
const { rerender } = render( | ||
<Component agent={{ id: AGENT_000 }} soPlatform={soPlatform} />, | ||
); | ||
|
||
expect(mocked.mock.calls[0][0].endpoint).toContain( | ||
`/syscollector/${AGENT_000}/${endpoint}`, | ||
); | ||
|
||
mocked.mockClear(); | ||
|
||
rerender(<Component agent={{ id: AGENT_001 }} soPlatform={soPlatform} />); | ||
|
||
expect(mocked.mock.calls[0][0].endpoint).toContain( | ||
`/syscollector/${AGENT_001}/${endpoint}`, | ||
); | ||
} | ||
|
||
export function shouldFetchDataForGivenAgentId( | ||
mocked: jest.Mock, | ||
Component: React.ComponentType<{ | ||
agent: { id: string }; | ||
soPlatform?: string; | ||
}>, | ||
endpoint: string, | ||
soPlatform: string = 'linux', | ||
) { | ||
const { rerender } = render( | ||
<Component agent={{ id: AGENT_000 }} soPlatform={soPlatform} />, | ||
); | ||
|
||
expect(mocked.mock.calls[0][0]).toEqual('GET'); | ||
expect(mocked.mock.calls[0][1]).toEqual( | ||
`/syscollector/${AGENT_000}/${endpoint}`, | ||
); | ||
|
||
mocked.mockClear(); | ||
|
||
rerender(<Component agent={{ id: AGENT_001 }} soPlatform={soPlatform} />); | ||
|
||
expect(mocked.mock.calls[0][0]).toEqual('GET'); | ||
expect(mocked.mock.calls[0][1]).toEqual( | ||
`/syscollector/${AGENT_001}/${endpoint}`, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.