tests(splunk-on-call-plugin): update tests
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
import { Incident, Team, User } from '../components/types';
|
||||
|
||||
/*
|
||||
* Copyright 2021 Spotify AB
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
export const MOCKED_USER: User = {
|
||||
createdAt: '2021-02-01T23:38:38Z',
|
||||
displayName: 'Test User',
|
||||
email: 'test@example.com',
|
||||
firstName: 'FirstNameTest',
|
||||
lastName: 'LastNameTest',
|
||||
passwordLastUpdated: '2021-02-01T23:38:38Z',
|
||||
username: 'test_user',
|
||||
verified: true,
|
||||
_selfUrl: '/api-public/v1/user/test_user',
|
||||
};
|
||||
|
||||
export const MOCKED_ON_CALL = [
|
||||
{
|
||||
team: { name: 'team_example', slug: 'team-zEalMCgwYSA0Lt40' },
|
||||
oncallNow: [
|
||||
{
|
||||
escalationPolicy: { name: 'Example', slug: 'team-zEalMCgwYSA0Lt40' },
|
||||
users: [{ onCalluser: { username: 'test_user' } }],
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export const MOCK_INCIDENT: Incident = {
|
||||
alertCount: 1,
|
||||
currentPhase: 'ACKED',
|
||||
entityDisplayName: 'test-incident',
|
||||
entityId: 'entityId',
|
||||
entityState: 'CRITICAL',
|
||||
entityType: 'SERVICE',
|
||||
incidentNumber: '1',
|
||||
lastAlertId: 'lastAlertId',
|
||||
lastAlertTime: '2021-02-03T00:13:11Z',
|
||||
routingKey: 'routingdefault',
|
||||
service: 'test',
|
||||
startTime: '2021-02-03T00:13:11Z',
|
||||
pagedTeams: ['team-O9SqT13fsnCstjMi'],
|
||||
pagedUsers: [],
|
||||
pagedPolicies: [
|
||||
{
|
||||
policy: {
|
||||
name: 'Generated Direct User Policy for test',
|
||||
slug: 'directUserPolicySlug-test',
|
||||
_selfUrl: '/test',
|
||||
},
|
||||
},
|
||||
],
|
||||
transitions: [{ name: 'ACKED', at: '2021-02-03T01:20:00Z', by: 'test' }],
|
||||
monitorName: 'vouser-user',
|
||||
monitorType: 'Manual',
|
||||
firstAlertUuid: 'firstAlertUuid',
|
||||
incidentLink: 'https://portal.victorops.com/example',
|
||||
};
|
||||
|
||||
export const MOCK_TEAM: Team = {
|
||||
_selfUrl: '/api-public/v1/team/team-O9SqT13fsnCstjMi',
|
||||
_membersUrl: '/api-public/v1/team/team-O9SqT13fsnCstjMi/members',
|
||||
_policiesUrl: '/api-public/v1/team/team-O9SqT13fsnCstjMi/policies',
|
||||
_adminsUrl: '/api-public/v1/team/team-O9SqT13fsnCstjMi/admins',
|
||||
name: 'test',
|
||||
slug: 'team-O9SqT13fsnCstjMi',
|
||||
memberCount: 1,
|
||||
version: 1,
|
||||
isDefaultTeam: false,
|
||||
};
|
||||
@@ -17,33 +17,9 @@ import React from 'react';
|
||||
import { render, waitFor } from '@testing-library/react';
|
||||
import { EscalationPolicy } from './EscalationPolicy';
|
||||
import { wrapInTestApp } from '@backstage/test-utils';
|
||||
import { User } from '../types';
|
||||
import { ApiProvider, ApiRegistry } from '@backstage/core';
|
||||
import { splunkOnCallApiRef } from '../../api';
|
||||
|
||||
const MOCKED_USER: User = {
|
||||
createdAt: '2021-02-01T23:38:38Z',
|
||||
displayName: 'Test User',
|
||||
email: 'test@example.com',
|
||||
firstName: 'FirstNameTest',
|
||||
lastName: 'LastNameTest',
|
||||
passwordLastUpdated: '2021-02-01T23:38:38Z',
|
||||
username: 'test_user',
|
||||
verified: true,
|
||||
_selfUrl: '/api-public/v1/user/test_user',
|
||||
};
|
||||
|
||||
const MOCKED_ON_CALL = [
|
||||
{
|
||||
team: { name: 'team_example', slug: 'team-zEalMCgwYSA0Lt40' },
|
||||
oncallNow: [
|
||||
{
|
||||
escalationPolicy: { name: 'Example', slug: 'team-zEalMCgwYSA0Lt40' },
|
||||
users: [{ onCalluser: { username: 'test_user' } }],
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
import { MOCKED_ON_CALL, MOCKED_USER } from '../../api/mocks';
|
||||
|
||||
const mockSplunkOnCallApi = {
|
||||
getOnCallUsers: () => [],
|
||||
|
||||
@@ -18,56 +18,15 @@ import { render, waitFor } from '@testing-library/react';
|
||||
import { Incidents } from './Incidents';
|
||||
import { wrapInTestApp } from '@backstage/test-utils';
|
||||
import {
|
||||
alertApiRef,
|
||||
ApiProvider,
|
||||
ApiRegistry,
|
||||
createApiRef,
|
||||
IdentityApi,
|
||||
identityApiRef,
|
||||
} from '@backstage/core';
|
||||
import { splunkOnCallApiRef } from '../../api';
|
||||
import { Incident, Team } from '../types';
|
||||
|
||||
const MOCK_INCIDENT: Incident = {
|
||||
alertCount: 1,
|
||||
currentPhase: 'ACKED',
|
||||
entityDisplayName: 'test-incident',
|
||||
entityId: 'entityId',
|
||||
entityState: 'CRITICAL',
|
||||
entityType: 'SERVICE',
|
||||
incidentNumber: '1',
|
||||
lastAlertId: 'lastAlertId',
|
||||
lastAlertTime: '2021-02-03T00:13:11Z',
|
||||
routingKey: 'routingdefault',
|
||||
service: 'test',
|
||||
startTime: '2021-02-03T00:13:11Z',
|
||||
pagedTeams: ['team-O9SqT13fsnCstjMi'],
|
||||
pagedUsers: [],
|
||||
pagedPolicies: [
|
||||
{
|
||||
policy: {
|
||||
name: 'Generated Direct User Policy for test',
|
||||
slug: 'directUserPolicySlug-test',
|
||||
_selfUrl: '/test',
|
||||
},
|
||||
},
|
||||
],
|
||||
transitions: [{ name: 'ACKED', at: '2021-02-03T01:20:00Z', by: 'test' }],
|
||||
monitorName: 'vouser-user',
|
||||
monitorType: 'Manual',
|
||||
firstAlertUuid: 'firstAlertUuid',
|
||||
incidentLink: 'https://portal.victorops.com/example',
|
||||
};
|
||||
|
||||
const MOCK_TEAM: Team = {
|
||||
_selfUrl: '/api-public/v1/team/team-O9SqT13fsnCstjMi',
|
||||
_membersUrl: '/api-public/v1/team/team-O9SqT13fsnCstjMi/members',
|
||||
_policiesUrl: '/api-public/v1/team/team-O9SqT13fsnCstjMi/policies',
|
||||
_adminsUrl: '/api-public/v1/team/team-O9SqT13fsnCstjMi/admins',
|
||||
name: 'test',
|
||||
slug: 'team-O9SqT13fsnCstjMi',
|
||||
memberCount: 1,
|
||||
version: 1,
|
||||
isDefaultTeam: false,
|
||||
};
|
||||
import { MOCK_TEAM, MOCK_INCIDENT } from '../../api/mocks';
|
||||
|
||||
const mockIdentityApi: Partial<IdentityApi> = {
|
||||
getUserId: () => 'test',
|
||||
@@ -78,6 +37,13 @@ const mockSplunkOnCallApi = {
|
||||
getTeams: () => [],
|
||||
};
|
||||
const apis = ApiRegistry.from([
|
||||
[
|
||||
alertApiRef,
|
||||
createApiRef({
|
||||
id: 'core.alert',
|
||||
description: 'Used to report alerts and forward them to the app',
|
||||
}),
|
||||
],
|
||||
[identityApiRef, mockIdentityApi],
|
||||
[splunkOnCallApiRef, mockSplunkOnCallApi],
|
||||
]);
|
||||
@@ -121,7 +87,11 @@ describe('Incidents', () => {
|
||||
),
|
||||
);
|
||||
await waitFor(() => !queryByTestId('progress'));
|
||||
expect(getByText('user')).toBeInTheDocument();
|
||||
expect(
|
||||
getByText('user', {
|
||||
exact: false,
|
||||
}),
|
||||
).toBeInTheDocument();
|
||||
expect(getByText('test-incident')).toBeInTheDocument();
|
||||
expect(getByTitle('ACKED')).toBeInTheDocument();
|
||||
expect(getByLabelText('Status warning')).toBeInTheDocument();
|
||||
|
||||
@@ -29,22 +29,18 @@ import {
|
||||
UnauthorizedError,
|
||||
SplunkOnCallClient,
|
||||
} from '../api';
|
||||
import { User } from './types';
|
||||
|
||||
const MOCKED_USER: User = {
|
||||
createdAt: '2021-02-01T23:38:38Z',
|
||||
displayName: 'Test User',
|
||||
email: 'remi.d45@gmail.com',
|
||||
firstName: 'FirstNameTest',
|
||||
lastName: 'LastNameTest',
|
||||
passwordLastUpdated: '2021-02-01T23:38:38Z',
|
||||
username: 'test_user',
|
||||
verified: true,
|
||||
_selfUrl: '/api-public/v1/user/test_user',
|
||||
};
|
||||
import {
|
||||
MOCKED_ON_CALL,
|
||||
MOCKED_USER,
|
||||
MOCK_INCIDENT,
|
||||
MOCK_TEAM,
|
||||
} from '../api/mocks';
|
||||
|
||||
const mockSplunkOnCallApi: Partial<SplunkOnCallClient> = {
|
||||
getUsers: async () => [],
|
||||
getIncidents: async () => [MOCK_INCIDENT],
|
||||
getOnCallUsers: async () => MOCKED_ON_CALL,
|
||||
getTeams: async () => [MOCK_TEAM],
|
||||
};
|
||||
|
||||
const apis = ApiRegistry.from([
|
||||
|
||||
@@ -26,19 +26,7 @@ import {
|
||||
} from '@backstage/core';
|
||||
import { splunkOnCallApiRef } from '../../api';
|
||||
import { TriggerDialog } from './TriggerDialog';
|
||||
import { User } from '../types';
|
||||
|
||||
const MOCKED_USER: User = {
|
||||
createdAt: '2021-02-01T23:38:38Z',
|
||||
displayName: 'Test User',
|
||||
email: 'remi.d45@gmail.com',
|
||||
firstName: 'FirstNameTest',
|
||||
lastName: 'LastNameTest',
|
||||
passwordLastUpdated: '2021-02-01T23:38:38Z',
|
||||
username: 'test_user',
|
||||
verified: true,
|
||||
_selfUrl: '/api-public/v1/user/test_user',
|
||||
};
|
||||
import { MOCKED_USER } from '../../api/mocks';
|
||||
|
||||
describe('TriggerDialog', () => {
|
||||
const mockIdentityApi: Partial<IdentityApi> = {
|
||||
@@ -48,18 +36,16 @@ describe('TriggerDialog', () => {
|
||||
const mockTriggerAlarmFn = jest.fn();
|
||||
const mockSplunkOnCallApi = {
|
||||
triggerAlarm: mockTriggerAlarmFn,
|
||||
getEscalationPolicies: async () => ({
|
||||
policies: [
|
||||
{
|
||||
policy: {
|
||||
name: 'Example',
|
||||
slug: 'team-zEalMCgwYSA0Lt40',
|
||||
_selfUrl: '/api-public/v1/policies/team-zEalMCgwYSA0Lt40',
|
||||
},
|
||||
team: { name: 'Example', slug: 'team-zEalMCgwYSA0Lt40' },
|
||||
getEscalationPolicies: async () => [
|
||||
{
|
||||
policy: {
|
||||
name: 'Example',
|
||||
slug: 'team-zEalMCgwYSA0Lt40',
|
||||
_selfUrl: '/api-public/v1/policies/team-zEalMCgwYSA0Lt40',
|
||||
},
|
||||
],
|
||||
}),
|
||||
team: { name: 'Example', slug: 'team-zEalMCgwYSA0Lt40' },
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const apis = ApiRegistry.from([
|
||||
@@ -103,8 +89,8 @@ describe('TriggerDialog', () => {
|
||||
await act(async () => {
|
||||
fireEvent.change(summary, { target: { value: description } });
|
||||
fireEvent.change(body, { target: { value: description } });
|
||||
fireEvent.change(userTarget, { target: { value: ['test_user'] } });
|
||||
fireEvent.change(behavior, { target: { value: '0' } });
|
||||
fireEvent.change(userTarget, { target: { value: ['test_user'] } });
|
||||
fireEvent.change(policiesTarget, {
|
||||
target: { value: ['team-zEalMCgwYSA0Lt40'] },
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user