Merge branch 'master' of https://github.com/backstage/backstage into marley/7641-consume-exported-ado-types

Signed-off-by: Marley Powell <Marley.Powell@exclaimer.com>
This commit is contained in:
Marley Powell
2021-11-04 08:19:08 +00:00
644 changed files with 12184 additions and 3694 deletions
@@ -0,0 +1,241 @@
/*
* Copyright 2021 The Backstage Authors
*
* 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.
*/
import {
BuildResult,
BuildStatus,
} from '@backstage/plugin-azure-devops-backend';
import { getBuildResultComponent, getBuildStateComponent } from './BuildTable';
import { renderInTestApp } from '@backstage/test-utils';
describe('getBuildResultComponent', () => {
describe('getBuildResultComponent with Succeeded result', () => {
it('should return Status ok Succeeded', async () => {
const { getByLabelText, getByText } = await renderInTestApp(
getBuildResultComponent(BuildResult.Succeeded),
);
expect(getByLabelText('Status ok')).toBeInTheDocument();
expect(getByText('Succeeded')).toBeInTheDocument();
});
});
describe('getBuildResultComponent with Partially Succeeded result', () => {
it('should return Status warning Partially Succeeded', async () => {
const { getByLabelText, getByText } = await renderInTestApp(
getBuildResultComponent(BuildResult.PartiallySucceeded),
);
expect(getByLabelText('Status warning')).toBeInTheDocument();
expect(getByText('Partially Succeeded')).toBeInTheDocument();
});
});
describe('getBuildResultComponent with Failed result', () => {
it('should return Status error Failed', async () => {
const { getByLabelText, getByText } = await renderInTestApp(
getBuildResultComponent(BuildResult.Failed),
);
expect(getByLabelText('Status error')).toBeInTheDocument();
expect(getByText('Failed')).toBeInTheDocument();
});
});
describe('getBuildResultComponent with Canceled result', () => {
it('should return Status aborted Canceled', async () => {
const { getByLabelText, getByText } = await renderInTestApp(
getBuildResultComponent(BuildResult.Canceled),
);
expect(getByLabelText('Status aborted')).toBeInTheDocument();
expect(getByText('Canceled')).toBeInTheDocument();
});
});
describe('getBuildResultComponent with None result', () => {
it('should return Status warning Unknown', async () => {
const { getByLabelText, getByText } = await renderInTestApp(
getBuildResultComponent(BuildResult.None),
);
expect(getByLabelText('Status warning')).toBeInTheDocument();
expect(getByText('Unknown')).toBeInTheDocument();
});
});
describe('getBuildResultComponent with undefined result', () => {
it('should return Status warning Unknown', async () => {
const { getByLabelText, getByText } = await renderInTestApp(
getBuildResultComponent(undefined),
);
expect(getByLabelText('Status warning')).toBeInTheDocument();
expect(getByText('Unknown')).toBeInTheDocument();
});
});
});
describe('getBuildStateComponent', () => {
describe('getBuildStateComponent with In Progress status and undefined result', () => {
it('should return Status running In Progress', async () => {
const { getByLabelText, getByText } = await renderInTestApp(
getBuildStateComponent(BuildStatus.InProgress, undefined),
);
expect(getByLabelText('Status running')).toBeInTheDocument();
expect(getByText('In Progress')).toBeInTheDocument();
});
});
describe('getBuildStateComponent with Completed status and Succeeded result', () => {
it('should return Status ok Succeeded', async () => {
const { getByLabelText, getByText } = await renderInTestApp(
getBuildStateComponent(BuildStatus.Completed, BuildResult.Succeeded),
);
expect(getByLabelText('Status ok')).toBeInTheDocument();
expect(getByText('Succeeded')).toBeInTheDocument();
});
});
describe('getBuildStateComponent with Completed status and Partially Succeeded result', () => {
it('should return Status warning Partially Succeeded', async () => {
const { getByLabelText, getByText } = await renderInTestApp(
getBuildStateComponent(
BuildStatus.Completed,
BuildResult.PartiallySucceeded,
),
);
expect(getByLabelText('Status warning')).toBeInTheDocument();
expect(getByText('Partially Succeeded')).toBeInTheDocument();
});
});
describe('getBuildStateComponent with Completed status and Failed result', () => {
it('should return Status error Failed', async () => {
const { getByLabelText, getByText } = await renderInTestApp(
getBuildStateComponent(BuildStatus.Completed, BuildResult.Failed),
);
expect(getByLabelText('Status error')).toBeInTheDocument();
expect(getByText('Failed')).toBeInTheDocument();
});
});
describe('getBuildStateComponent with Completed status and Canceled result', () => {
it('should return Status aborted Canceled', async () => {
const { getByLabelText, getByText } = await renderInTestApp(
getBuildStateComponent(BuildStatus.Completed, BuildResult.Canceled),
);
expect(getByLabelText('Status aborted')).toBeInTheDocument();
expect(getByText('Canceled')).toBeInTheDocument();
});
});
describe('getBuildStateComponent with Completed status and None result', () => {
it('should return Status warning Unknown', async () => {
const { getByLabelText, getByText } = await renderInTestApp(
getBuildStateComponent(BuildStatus.Completed, BuildResult.None),
);
expect(getByLabelText('Status warning')).toBeInTheDocument();
expect(getByText('Unknown')).toBeInTheDocument();
});
});
describe('getBuildStateComponent with Completed status and undefined result', () => {
it('should return Status warning Unknown', async () => {
const { getByLabelText, getByText } = await renderInTestApp(
getBuildStateComponent(BuildStatus.Completed, undefined),
);
expect(getByLabelText('Status warning')).toBeInTheDocument();
expect(getByText('Unknown')).toBeInTheDocument();
});
});
// TODO: Add remaining Completed iterations
describe('getBuildStateComponent with Cancelling status and undefined result', () => {
it('should return Status aborted Cancelling', async () => {
const { getByLabelText, getByText } = await renderInTestApp(
getBuildStateComponent(BuildStatus.Cancelling, undefined),
);
expect(getByLabelText('Status aborted')).toBeInTheDocument();
expect(getByText('Cancelling')).toBeInTheDocument();
});
});
describe('getBuildStateComponent with Postponed status and undefined result', () => {
it('should return Status pending Postponed', async () => {
const { getByLabelText, getByText } = await renderInTestApp(
getBuildStateComponent(BuildStatus.Postponed, undefined),
);
expect(getByLabelText('Status pending')).toBeInTheDocument();
expect(getByText('Postponed')).toBeInTheDocument();
});
});
describe('getBuildStateComponent with Not Started status and undefined result', () => {
it('should return Status aborted Not Started', async () => {
const { getByLabelText, getByText } = await renderInTestApp(
getBuildStateComponent(BuildStatus.NotStarted, undefined),
);
expect(getByLabelText('Status aborted')).toBeInTheDocument();
expect(getByText('Not Started')).toBeInTheDocument();
});
});
describe('getBuildStateComponent with None status and undefined result', () => {
it('should return Status warning Unknown', async () => {
const { getByLabelText, getByText } = await renderInTestApp(
getBuildStateComponent(BuildStatus.None, undefined),
);
expect(getByLabelText('Status warning')).toBeInTheDocument();
expect(getByText('Unknown')).toBeInTheDocument();
});
});
describe('getBuildStateComponent with undefined and undefined result', () => {
it('should return Status warning Unknown', async () => {
const { getByLabelText, getByText } = await renderInTestApp(
getBuildStateComponent(undefined, undefined),
);
expect(getByLabelText('Status warning')).toBeInTheDocument();
expect(getByText('Unknown')).toBeInTheDocument();
});
});
describe('getBuildStateComponent with undefined and any valid BuildResult', () => {
it('should return Status warning Unknown', async () => {
const { getByLabelText, getByText } = await renderInTestApp(
getBuildStateComponent(undefined, BuildResult.Succeeded),
);
expect(getByLabelText('Status warning')).toBeInTheDocument();
expect(getByText('Unknown')).toBeInTheDocument();
});
});
});
@@ -36,7 +36,7 @@ import { DateTime } from 'luxon';
import React from 'react';
import { RepoBuild } from '../../api/types';
const getBuildResultComponent = (result: number | undefined) => {
export const getBuildResultComponent = (result: number | undefined) => {
switch (result) {
case BuildResult.Succeeded:
return (
@@ -72,7 +72,7 @@ const getBuildResultComponent = (result: number | undefined) => {
}
};
const getBuildStateComponent = (
export const getBuildStateComponent = (
status: number | undefined,
result: number | undefined,
) => {
@@ -1,43 +0,0 @@
/*
* Copyright 2021 The Backstage Authors
*
* 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.
*/
import React from 'react';
import { Routes, Route } from 'react-router';
import { azureDevOpsRouteRef } from '../routes';
import { EntityPageAzurePipelines } from './EntityPageAzurePipelines';
import { AZURE_DEVOPS_ANNOTATION } from '../constants';
import { Entity } from '@backstage/catalog-model';
import { useEntity } from '@backstage/plugin-catalog-react';
import { MissingAnnotationEmptyState } from '@backstage/core-components';
export const isAzureDevOpsAvailable = (entity: Entity) =>
Boolean(entity.metadata.annotations?.[AZURE_DEVOPS_ANNOTATION]);
export const Router = ({ defaultLimit }: { defaultLimit?: number }) => {
const { entity } = useEntity();
if (!isAzureDevOpsAvailable(entity)) {
return <MissingAnnotationEmptyState annotation={AZURE_DEVOPS_ANNOTATION} />;
}
return (
<Routes>
<Route
path={`/${azureDevOpsRouteRef.path}`}
element={<EntityPageAzurePipelines defaultLimit={defaultLimit} />}
/>
</Routes>
);
};
+5 -2
View File
@@ -13,5 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export { azureDevOpsPlugin, EntityAzurePipelinesContent } from './plugin';
export { isAzureDevOpsAvailable } from './components/Router';
export {
azureDevOpsPlugin,
EntityAzurePipelinesContent,
isAzureDevOpsAvailable,
} from './plugin';
+12 -3
View File
@@ -14,8 +14,6 @@
* limitations under the License.
*/
import { azureDevOpsApiRef } from './api/AzureDevOpsApi';
import { AzureDevOpsClient } from './api/AzureDevOpsClient';
import {
createApiFactory,
createPlugin,
@@ -23,8 +21,16 @@ import {
discoveryApiRef,
identityApiRef,
} from '@backstage/core-plugin-api';
import { AZURE_DEVOPS_ANNOTATION } from './constants';
import { AzureDevOpsClient } from './api/AzureDevOpsClient';
import { Entity } from '@backstage/catalog-model';
import { azureDevOpsApiRef } from './api/AzureDevOpsApi';
import { azureDevOpsRouteRef } from './routes';
export const isAzureDevOpsAvailable = (entity: Entity) =>
Boolean(entity.metadata.annotations?.[AZURE_DEVOPS_ANNOTATION]);
export const azureDevOpsPlugin = createPlugin({
id: 'azureDevOps',
apis: [
@@ -43,7 +49,10 @@ export const azureDevOpsPlugin = createPlugin({
export const EntityAzurePipelinesContent = azureDevOpsPlugin.provide(
createRoutableExtension({
name: 'EntityAzurePipelinesContent',
component: () => import('./components/Router').then(m => m.Router),
component: () =>
import('./components/EntityPageAzurePipelines').then(
m => m.EntityPageAzurePipelines,
),
mountPoint: azureDevOpsRouteRef,
}),
);