-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce85a85
commit 3a326ce
Showing
2 changed files
with
132 additions
and
9 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
assets/js/components/ExecutionResults/ExecutionResults.test.jsx
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,75 @@ | ||
import React from 'react'; | ||
import { act, screen } from '@testing-library/react'; | ||
|
||
import { renderWithRouter } from '@lib/test-utils'; | ||
import { | ||
hostnameFactory, | ||
checksExecutionFactory, | ||
catalogCheckFactory, | ||
} from '@lib/test-utils/factories'; | ||
|
||
import ExecutionResults from './ExecutionResults'; | ||
|
||
describe('ExecutionResults', () => { | ||
it('should render ExecutionResults with successfully fetched results', async () => { | ||
const hostnames = hostnameFactory.buildList(2); | ||
const [{ id: agentID, hostname }] = hostnames; | ||
const executionResult = checksExecutionFactory.build({ | ||
agentID, | ||
status: 'completed', | ||
result: 'passing', | ||
}); | ||
const { | ||
groupID: clusterID, | ||
execution_id: executionID, | ||
check_results: [{ check_id: checkID }], | ||
} = executionResult; | ||
const catalog = [catalogCheckFactory.build({ id: checkID })]; | ||
|
||
await act(async () => { | ||
renderWithRouter( | ||
<ExecutionResults | ||
clusterID={clusterID} | ||
executionID={executionID} | ||
onExecutionFetch={() => Promise.resolve({ data: executionResult })} | ||
onCatalogFetch={() => Promise.resolve({ data: { items: catalog } })} | ||
hostnames={hostnames} | ||
/> | ||
); | ||
}); | ||
|
||
expect(screen.getByText(hostname)).toBeTruthy(); | ||
expect(screen.getByText(checkID)).toBeTruthy(); | ||
}); | ||
|
||
it('should render ExecutionResults with running state', async () => { | ||
const hostnames = hostnameFactory.buildList(2); | ||
const [{ id: agentID }] = hostnames; | ||
const executionResult = checksExecutionFactory.build({ | ||
agentID, | ||
status: 'running', | ||
}); | ||
const { | ||
groupID: clusterID, | ||
execution_id: executionID, | ||
check_results: [{ check_id: checkID }], | ||
} = executionResult; | ||
const catalog = [catalogCheckFactory.build({ id: checkID })]; | ||
|
||
await act(async () => { | ||
renderWithRouter( | ||
<ExecutionResults | ||
clusterID={clusterID} | ||
executionID={executionID} | ||
onExecutionFetch={() => Promise.resolve({ data: executionResult })} | ||
onCatalogFetch={() => Promise.resolve({ data: { items: catalog } })} | ||
hostnames={hostnames} | ||
/> | ||
); | ||
}); | ||
|
||
expect( | ||
screen.getByText('Check execution currently running...') | ||
).toBeTruthy(); | ||
}); | ||
}); |
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