Fix tests

Signed-off-by: Heather Lee <heatherl@splunk.com>
This commit is contained in:
Heather Lee
2021-05-25 16:57:43 -07:00
parent 8eb2c2951c
commit bfa0908de0
2 changed files with 52 additions and 1 deletions
+6
View File
@@ -88,6 +88,12 @@ export const MOCK_TEAM: Team = {
isDefaultTeam: false,
};
export const MOCK_TEAM_NO_INCIDENTS: Team = {
...MOCK_TEAM,
name: 'test-noincidents',
slug: 'team-O9SqT13fsnCstjMj',
};
export const ESCALATION_POLICIES: EscalationPolicyInfo[] = [
{
policy: {
@@ -38,6 +38,7 @@ import {
MOCKED_USER,
MOCK_INCIDENT,
MOCK_TEAM,
MOCK_TEAM_NO_INCIDENTS,
} from '../api/mocks';
import { EntitySplunkOnCallCard } from './EntitySplunkOnCallCard';
@@ -82,16 +83,34 @@ const mockEntityData = {
} as Entity,
};
const mockEntityDataNoIncidents = {
loading: false,
error: undefined,
entity: {
apiVersion: 'backstage.io/v1alpha1',
kind: 'Component',
metadata: {
name: 'splunkoncall-test',
annotations: {
'splunk.com/on-call-team': 'test-noincidents',
},
},
} as Entity,
};
describe('SplunkOnCallCard', () => {
it('Render splunkoncall', async () => {
mockSplunkOnCallApi.getUsers = jest
.fn()
.mockImplementationOnce(async () => [MOCKED_USER]);
mockSplunkOnCallApi.getTeams = jest
.fn()
.mockImplementation(async () => [MOCK_TEAM_NO_INCIDENTS]);
const { getByText, queryByTestId } = render(
wrapInTestApp(
<ApiProvider apis={apis}>
<EntityContext.Provider value={mockEntityData}>
<EntityContext.Provider value={mockEntityDataNoIncidents}>
<EntitySplunkOnCallCard />
</EntityContext.Provider>
</ApiProvider>,
@@ -148,10 +167,36 @@ describe('SplunkOnCallCard', () => {
).toBeInTheDocument();
});
it('handles warning for incorrect team annotation', async () => {
mockSplunkOnCallApi.getUsers = jest
.fn()
.mockImplementationOnce(async () => [MOCKED_USER]);
mockSplunkOnCallApi.getTeams = jest
.fn()
.mockImplementationOnce(async () => []);
const { getByText, queryByTestId } = render(
wrapInTestApp(
<ApiProvider apis={apis}>
<EntityContext.Provider value={mockEntityData}>
<EntitySplunkOnCallCard />
</EntityContext.Provider>
</ApiProvider>,
),
);
await waitFor(() => !queryByTestId('progress'));
expect(
getByText('Could not find team named "test" in the Splunk On-Call API'),
).toBeInTheDocument();
});
it('opens the dialog when trigger button is clicked', async () => {
mockSplunkOnCallApi.getUsers = jest
.fn()
.mockImplementationOnce(async () => [MOCKED_USER]);
mockSplunkOnCallApi.getTeams = jest
.fn()
.mockImplementationOnce(async () => [MOCK_TEAM]);
const { getByText, queryByTestId, getByRole } = render(
wrapInTestApp(