Merge pull request #19954 from backstage/freben/render

🧹  use `renderInTestApp`
This commit is contained in:
Fredrik Adelöw
2023-09-15 10:18:15 +02:00
committed by GitHub
72 changed files with 2587 additions and 2982 deletions
@@ -15,8 +15,8 @@
*/
import React from 'react';
import { render } from '@testing-library/react';
import { wrapInTestApp } from '@backstage/test-utils';
import { screen } from '@testing-library/react';
import { renderInTestApp } from '@backstage/test-utils';
import { Cluster } from './Cluster';
jest.mock('../../hooks');
@@ -24,38 +24,36 @@ import * as oneDeployment from '../../__fixtures__/1-deployments.json';
describe('Cluster', () => {
it('render 1 cluster', async () => {
const { getByText } = render(
wrapInTestApp(
<Cluster
{...({
clusterObjects: {
cluster: {
name: 'cluster-1',
},
resources: [
{
type: 'deployments',
resources: oneDeployment.deployments,
},
{
type: 'replicasets',
resources: oneDeployment.replicaSets,
},
{
type: 'pods',
resources: oneDeployment.pods,
},
],
podMetrics: [],
errors: [],
await renderInTestApp(
<Cluster
{...({
clusterObjects: {
cluster: {
name: 'cluster-1',
},
podsWithErrors: new Set<string>(),
} as any)}
/>,
),
resources: [
{
type: 'deployments',
resources: oneDeployment.deployments,
},
{
type: 'replicasets',
resources: oneDeployment.replicaSets,
},
{
type: 'pods',
resources: oneDeployment.pods,
},
],
podMetrics: [],
errors: [],
},
podsWithErrors: new Set<string>(),
} as any)}
/>,
);
expect(getByText('cluster-1')).toBeInTheDocument();
expect(getByText('10 pods')).toBeInTheDocument();
expect(screen.getByText('cluster-1')).toBeInTheDocument();
expect(screen.getByText('10 pods')).toBeInTheDocument();
});
});
@@ -13,38 +13,35 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React from 'react';
import { render } from '@testing-library/react';
import { screen } from '@testing-library/react';
import { CronJobsAccordions } from './CronJobsAccordions';
import * as oneCronJobsFixture from '../../__fixtures__/1-cronjobs.json';
import * as twoCronJobsFixture from '../../__fixtures__/2-cronjobs.json';
import { wrapInTestApp } from '@backstage/test-utils';
import { renderInTestApp } from '@backstage/test-utils';
import { kubernetesProviders } from '../../hooks/test-utils';
describe('CronJobsAccordions', () => {
it('should render 1 active cronjobs', async () => {
const wrapper = kubernetesProviders(oneCronJobsFixture, new Set<string>());
const { getByText } = render(
wrapper(wrapInTestApp(<CronJobsAccordions />)),
);
await renderInTestApp(wrapper(<CronJobsAccordions />));
expect(getByText('dice-roller-cronjob')).toBeInTheDocument();
expect(getByText('CronJob')).toBeInTheDocument();
expect(getByText('namespace: default')).toBeInTheDocument();
expect(getByText('Active')).toBeInTheDocument();
expect(screen.getByText('dice-roller-cronjob')).toBeInTheDocument();
expect(screen.getByText('CronJob')).toBeInTheDocument();
expect(screen.getByText('namespace: default')).toBeInTheDocument();
expect(screen.getByText('Active')).toBeInTheDocument();
});
it('should render 1 suspended cronjobs', async () => {
const wrapper = kubernetesProviders(twoCronJobsFixture, new Set<string>());
const { getByText } = render(
wrapper(wrapInTestApp(<CronJobsAccordions />)),
);
await renderInTestApp(wrapper(<CronJobsAccordions />));
expect(getByText('dice-roller-cronjob')).toBeInTheDocument();
expect(getByText('CronJob')).toBeInTheDocument();
expect(getByText('namespace: default')).toBeInTheDocument();
expect(getByText('Suspended')).toBeInTheDocument();
expect(screen.getByText('dice-roller-cronjob')).toBeInTheDocument();
expect(screen.getByText('CronJob')).toBeInTheDocument();
expect(screen.getByText('namespace: default')).toBeInTheDocument();
expect(screen.getByText('Suspended')).toBeInTheDocument();
});
});
@@ -15,8 +15,8 @@
*/
import React from 'react';
import { render } from '@testing-library/react';
import { wrapInTestApp } from '@backstage/test-utils';
import { screen } from '@testing-library/react';
import { renderInTestApp } from '@backstage/test-utils';
import { kubernetesProviders } from '../../../hooks/test-utils';
import * as rollout from './__fixtures__/rollout.json';
import * as pausedRollout from './__fixtures__/paused-rollout.json';
@@ -29,32 +29,34 @@ describe('Rollout', () => {
it('should render RolloutAccordion', async () => {
const wrapper = kubernetesProviders(groupedResources, new Set([]));
const { getByText, queryByText } = render(
wrapper(wrapInTestApp(<RolloutAccordions rollouts={[rollout] as any} />)),
await renderInTestApp(
wrapper(<RolloutAccordions rollouts={[rollout] as any} />),
);
expect(getByText('dice-roller')).toBeInTheDocument();
expect(getByText('Rollout')).toBeInTheDocument();
expect(getByText('2 pods')).toBeInTheDocument();
expect(getByText('No pods with errors')).toBeInTheDocument();
expect(queryByText('Paused')).toBeNull();
expect(screen.getByText('dice-roller')).toBeInTheDocument();
expect(screen.getByText('Rollout')).toBeInTheDocument();
expect(screen.getByText('2 pods')).toBeInTheDocument();
expect(screen.getByText('No pods with errors')).toBeInTheDocument();
expect(screen.queryByText('Paused')).toBeNull();
});
it('should render RolloutAccordion with error', async () => {
const wrapper = kubernetesProviders(
groupedResources,
new Set(['dice-roller-6c8646bfd-2m5hv']),
);
const { getByText, queryByText } = render(
wrapper(wrapInTestApp(<RolloutAccordions rollouts={[rollout] as any} />)),
await renderInTestApp(
wrapper(<RolloutAccordions rollouts={[rollout] as any} />),
);
expect(getByText('dice-roller')).toBeInTheDocument();
expect(getByText('Rollout')).toBeInTheDocument();
expect(getByText('2 pods')).toBeInTheDocument();
expect(getByText('1 pod with errors')).toBeInTheDocument();
expect(queryByText('Paused')).toBeNull();
expect(screen.getByText('dice-roller')).toBeInTheDocument();
expect(screen.getByText('Rollout')).toBeInTheDocument();
expect(screen.getByText('2 pods')).toBeInTheDocument();
expect(screen.getByText('1 pod with errors')).toBeInTheDocument();
expect(screen.queryByText('Paused')).toBeNull();
});
it('should render Paused Rollout with pause text', async () => {
const wrapper = kubernetesProviders(groupedResources, new Set([]));
@@ -63,41 +65,38 @@ describe('Rollout', () => {
// millis * secs * mins = 45 mins
.minus(Duration.fromMillis(1000 * 60 * 45));
const { getByText } = render(
wrapper(
wrapInTestApp(<RolloutAccordions rollouts={[pausedRollout] as any} />),
),
await renderInTestApp(
wrapper(<RolloutAccordions rollouts={[pausedRollout] as any} />),
);
expect(getByText('dice-roller')).toBeInTheDocument();
expect(getByText('Rollout')).toBeInTheDocument();
expect(getByText('2 pods')).toBeInTheDocument();
expect(getByText('No pods with errors')).toBeInTheDocument();
expect(getByText('Paused (45 minutes ago)')).toBeInTheDocument();
expect(screen.getByText('dice-roller')).toBeInTheDocument();
expect(screen.getByText('Rollout')).toBeInTheDocument();
expect(screen.getByText('2 pods')).toBeInTheDocument();
expect(screen.getByText('No pods with errors')).toBeInTheDocument();
expect(screen.getByText('Paused (45 minutes ago)')).toBeInTheDocument();
});
it('should render aborted Rollout with aborted text', async () => {
const wrapper = kubernetesProviders(groupedResources, new Set([]));
const { getByText, getAllByText, queryByText } = render(
await renderInTestApp(
wrapper(
wrapInTestApp(
<RolloutAccordions
defaultExpanded
rollouts={[abortedRollout] as any}
/>,
),
<RolloutAccordions
defaultExpanded
rollouts={[abortedRollout] as any}
/>,
),
);
expect(getByText('dice-roller')).toBeInTheDocument();
expect(getByText('Rollout')).toBeInTheDocument();
expect(getByText('2 pods')).toBeInTheDocument();
expect(getByText('No pods with errors')).toBeInTheDocument();
expect(queryByText('Paused')).toBeNull();
expect(getByText('Rollout status')).toBeInTheDocument();
expect(getAllByText('Aborted')).toHaveLength(2);
expect(screen.getByText('dice-roller')).toBeInTheDocument();
expect(screen.getByText('Rollout')).toBeInTheDocument();
expect(screen.getByText('2 pods')).toBeInTheDocument();
expect(screen.getByText('No pods with errors')).toBeInTheDocument();
expect(screen.queryByText('Paused')).toBeNull();
expect(screen.getByText('Rollout status')).toBeInTheDocument();
expect(screen.getAllByText('Aborted')).toHaveLength(2);
expect(
getByText('some metric related failure message'),
screen.getByText('some metric related failure message'),
).toBeInTheDocument();
});
});
@@ -15,125 +15,113 @@
*/
import React from 'react';
import { render } from '@testing-library/react';
import { screen } from '@testing-library/react';
import pauseSteps from './__fixtures__/pause-steps';
import setWeightSteps from './__fixtures__/setweight-steps';
import analysisSteps from './__fixtures__/analysis-steps';
import { wrapInTestApp } from '@backstage/test-utils';
import { renderInTestApp } from '@backstage/test-utils';
import { StepsProgress } from './StepsProgress';
describe('StepsProgress', () => {
it('should render Pause step text', async () => {
const { getByText } = render(
wrapInTestApp(
<StepsProgress
currentStepIndex={0}
aborted={false}
steps={pauseSteps}
/>,
),
await renderInTestApp(
<StepsProgress currentStepIndex={0} aborted={false} steps={pauseSteps} />,
);
expect(getByText('pause for 1h')).toBeInTheDocument();
expect(getByText('infinite pause')).toBeInTheDocument();
expect(screen.getByText('pause for 1h')).toBeInTheDocument();
expect(screen.getByText('infinite pause')).toBeInTheDocument();
});
it('should render SetWeight step text', async () => {
const { getByText } = render(
wrapInTestApp(
<StepsProgress
currentStepIndex={0}
aborted={false}
steps={setWeightSteps}
/>,
),
await renderInTestApp(
<StepsProgress
currentStepIndex={0}
aborted={false}
steps={setWeightSteps}
/>,
);
expect(getByText('setWeight 10%')).toBeInTheDocument();
expect(getByText('setWeight 95%')).toBeInTheDocument();
expect(screen.getByText('setWeight 10%')).toBeInTheDocument();
expect(screen.getByText('setWeight 95%')).toBeInTheDocument();
});
it('should render Analysis step text', async () => {
const { getAllByText, getByText } = render(
wrapInTestApp(
<StepsProgress
currentStepIndex={0}
aborted={false}
steps={analysisSteps}
/>,
),
await renderInTestApp(
<StepsProgress
currentStepIndex={0}
aborted={false}
steps={analysisSteps}
/>,
);
expect(getAllByText('analysis templates:')).toHaveLength(2);
expect(getByText('always-pass')).toBeInTheDocument();
expect(getByText('always-fail')).toBeInTheDocument();
expect(getByText('req-rate (cluster scoped)')).toBeInTheDocument();
expect(screen.getAllByText('analysis templates:')).toHaveLength(2);
expect(screen.getByText('always-pass')).toBeInTheDocument();
expect(screen.getByText('always-fail')).toBeInTheDocument();
expect(screen.getByText('req-rate (cluster scoped)')).toBeInTheDocument();
});
it('should render 3 different steps', async () => {
const { getByText } = render(
wrapInTestApp(
<StepsProgress
currentStepIndex={0}
aborted={false}
steps={[setWeightSteps[0], pauseSteps[0], analysisSteps[0]]}
/>,
),
await renderInTestApp(
<StepsProgress
currentStepIndex={0}
aborted={false}
steps={[setWeightSteps[0], pauseSteps[0], analysisSteps[0]]}
/>,
);
expect(getByText('setWeight 10%')).toBeInTheDocument();
expect(getByText('pause for 1h')).toBeInTheDocument();
expect(getByText('analysis templates:')).toBeInTheDocument();
expect(getByText('always-pass')).toBeInTheDocument();
expect(getByText('Canary promoted')).toBeInTheDocument();
expect(screen.getByText('setWeight 10%')).toBeInTheDocument();
expect(screen.getByText('pause for 1h')).toBeInTheDocument();
expect(screen.getByText('analysis templates:')).toBeInTheDocument();
expect(screen.getByText('always-pass')).toBeInTheDocument();
expect(screen.getByText('Canary promoted')).toBeInTheDocument();
});
it('current step is highlighted, previous steps are ticked', async () => {
const { getByText, queryByText } = render(
wrapInTestApp(
<StepsProgress
currentStepIndex={1}
aborted={false}
steps={[setWeightSteps[0], pauseSteps[0], analysisSteps[0]]}
/>,
),
await renderInTestApp(
<StepsProgress
currentStepIndex={1}
aborted={false}
steps={[setWeightSteps[0], pauseSteps[0], analysisSteps[0]]}
/>,
);
// It is ticked, so it's not visible
expect(queryByText('1')).toBeNull();
expect(screen.queryByText('1')).toBeNull();
// The current step
expect(getByText('2')).toBeInTheDocument();
expect(screen.getByText('2')).toBeInTheDocument();
// The future step
expect(getByText('3')).toBeInTheDocument();
expect(screen.getByText('3')).toBeInTheDocument();
// The canary promoted step should always be added at the end
expect(getByText('4')).toBeInTheDocument();
expect(screen.getByText('4')).toBeInTheDocument();
});
it('aborted canary has all steps grey', async () => {
const { getByText } = render(
wrapInTestApp(
<StepsProgress
currentStepIndex={2}
aborted
steps={[setWeightSteps[0], pauseSteps[0], analysisSteps[0]]}
/>,
),
await renderInTestApp(
<StepsProgress
currentStepIndex={2}
aborted
steps={[setWeightSteps[0], pauseSteps[0], analysisSteps[0]]}
/>,
);
expect(getByText('1')).toBeInTheDocument();
expect(getByText('2')).toBeInTheDocument();
expect(getByText('3')).toBeInTheDocument();
expect(getByText('4')).toBeInTheDocument();
expect(screen.getByText('1')).toBeInTheDocument();
expect(screen.getByText('2')).toBeInTheDocument();
expect(screen.getByText('3')).toBeInTheDocument();
expect(screen.getByText('4')).toBeInTheDocument();
});
it('promoted canary has all steps ticked', async () => {
const { queryByText } = render(
wrapInTestApp(
<StepsProgress
currentStepIndex={3}
aborted={false}
steps={[setWeightSteps[0], pauseSteps[0], analysisSteps[0]]}
/>,
),
await renderInTestApp(
<StepsProgress
currentStepIndex={3}
aborted={false}
steps={[setWeightSteps[0], pauseSteps[0], analysisSteps[0]]}
/>,
);
expect(queryByText('1')).toBeNull();
expect(queryByText('2')).toBeNull();
expect(queryByText('3')).toBeNull();
expect(queryByText('4')).toBeNull();
expect(screen.queryByText('1')).toBeNull();
expect(screen.queryByText('2')).toBeNull();
expect(screen.queryByText('3')).toBeNull();
expect(screen.queryByText('4')).toBeNull();
});
});
@@ -15,8 +15,8 @@
*/
import React from 'react';
import { render } from '@testing-library/react';
import { wrapInTestApp } from '@backstage/test-utils';
import { screen } from '@testing-library/react';
import { renderInTestApp } from '@backstage/test-utils';
import { kubernetesProviders } from '../../hooks/test-utils';
import * as ar from './__fixtures__/analysis-run.json';
import { DefaultCustomResourceAccordions } from './DefaultCustomResource';
@@ -25,17 +25,15 @@ describe('DefaultCustomResource', () => {
it('should render DefaultCustomResource Accordion', async () => {
const wrapper = kubernetesProviders({}, new Set([]));
const { getByText } = render(
await renderInTestApp(
wrapper(
wrapInTestApp(
<DefaultCustomResourceAccordions
customResources={[ar] as any}
customResourceName="AnalysisRun"
/>,
),
<DefaultCustomResourceAccordions
customResources={[ar] as any}
customResourceName="AnalysisRun"
/>,
),
);
expect(getByText('dice-roller-546c476497-4-1')).toBeInTheDocument();
expect(getByText('AnalysisRun')).toBeInTheDocument();
expect(screen.getByText('dice-roller-546c476497-4-1')).toBeInTheDocument();
expect(screen.getByText('AnalysisRun')).toBeInTheDocument();
});
});
@@ -15,10 +15,10 @@
*/
import React from 'react';
import { render } from '@testing-library/react';
import { screen } from '@testing-library/react';
import { DeploymentsAccordions } from './DeploymentsAccordions';
import * as twoDeployFixture from '../../__fixtures__/2-deployments.json';
import { wrapInTestApp } from '@backstage/test-utils';
import { renderInTestApp } from '@backstage/test-utils';
import { kubernetesProviders } from '../../hooks/test-utils';
describe('DeploymentsAccordions', () => {
@@ -28,19 +28,19 @@ describe('DeploymentsAccordions', () => {
new Set(['dice-roller-canary-7d64cd756c-vtbdx']),
);
const { getByText } = render(
wrapper(wrapInTestApp(<DeploymentsAccordions />)),
);
await renderInTestApp(wrapper(<DeploymentsAccordions />));
expect(getByText('dice-roller')).toBeInTheDocument();
expect(getByText('10 pods')).toBeInTheDocument();
expect(getByText('No pods with errors')).toBeInTheDocument();
expect(getByText('min replicas 10 / max replicas 15')).toBeInTheDocument();
expect(getByText('current CPU usage: 30%')).toBeInTheDocument();
expect(getByText('target CPU usage: 50%')).toBeInTheDocument();
expect(screen.getByText('dice-roller')).toBeInTheDocument();
expect(screen.getByText('10 pods')).toBeInTheDocument();
expect(screen.getByText('No pods with errors')).toBeInTheDocument();
expect(
screen.getByText('min replicas 10 / max replicas 15'),
).toBeInTheDocument();
expect(screen.getByText('current CPU usage: 30%')).toBeInTheDocument();
expect(screen.getByText('target CPU usage: 50%')).toBeInTheDocument();
expect(getByText('dice-roller-canary')).toBeInTheDocument();
expect(getByText('2 pods')).toBeInTheDocument();
expect(getByText('1 pod with errors')).toBeInTheDocument();
expect(screen.getByText('dice-roller-canary')).toBeInTheDocument();
expect(screen.getByText('2 pods')).toBeInTheDocument();
expect(screen.getByText('1 pod with errors')).toBeInTheDocument();
});
});
@@ -15,106 +15,99 @@
*/
import React from 'react';
import { render } from '@testing-library/react';
import { wrapInTestApp } from '@backstage/test-utils';
import { screen } from '@testing-library/react';
import { renderInTestApp } from '@backstage/test-utils';
import { ErrorPanel } from './ErrorPanel';
describe('ErrorPanel', () => {
it('displays path and status code when a cluster has an HTTP error', async () => {
const { getByText } = render(
wrapInTestApp(
<ErrorPanel
entityName="THIS_ENTITY"
clustersWithErrors={[
{
cluster: { name: 'THIS_CLUSTER' },
resources: [],
podMetrics: [],
errors: [
{
errorType: 'SYSTEM_ERROR',
statusCode: 500,
resourcePath: 'some/resource',
},
],
},
]}
/>,
),
await renderInTestApp(
<ErrorPanel
entityName="THIS_ENTITY"
clustersWithErrors={[
{
cluster: { name: 'THIS_CLUSTER' },
resources: [],
podMetrics: [],
errors: [
{
errorType: 'SYSTEM_ERROR',
statusCode: 500,
resourcePath: 'some/resource',
},
],
},
]}
/>,
);
// title
expect(
getByText(
screen.getByText(
'There was a problem retrieving some Kubernetes resources for the entity: THIS_ENTITY. This could mean that the Error Reporting card is not completely accurate.',
),
).toBeInTheDocument();
// message
expect(getByText('Errors:')).toBeInTheDocument();
expect(getByText('Cluster: THIS_CLUSTER')).toBeInTheDocument();
expect(screen.getByText('Errors:')).toBeInTheDocument();
expect(screen.getByText('Cluster: THIS_CLUSTER')).toBeInTheDocument();
expect(
getByText(
screen.getByText(
"Error fetching Kubernetes resource: 'some/resource', error: SYSTEM_ERROR, status code: 500",
),
).toBeInTheDocument();
});
it('displays message for non-HTTP-status-related fetch errors', async () => {
const { getByText } = render(
wrapInTestApp(
<ErrorPanel
entityName="THIS_ENTITY"
clustersWithErrors={[
{
cluster: { name: 'THIS_CLUSTER' },
resources: [],
podMetrics: [],
errors: [
{
errorType: 'FETCH_ERROR',
message: 'description of error',
},
],
},
]}
/>,
),
await renderInTestApp(
<ErrorPanel
entityName="THIS_ENTITY"
clustersWithErrors={[
{
cluster: { name: 'THIS_CLUSTER' },
resources: [],
podMetrics: [],
errors: [
{
errorType: 'FETCH_ERROR',
message: 'description of error',
},
],
},
]}
/>,
);
// title
expect(
getByText(
screen.getByText(
'There was a problem retrieving some Kubernetes resources for the entity: THIS_ENTITY. This could mean that the Error Reporting card is not completely accurate.',
),
).toBeInTheDocument();
// message
expect(getByText('Errors:')).toBeInTheDocument();
expect(getByText('Cluster: THIS_CLUSTER')).toBeInTheDocument();
expect(screen.getByText('Errors:')).toBeInTheDocument();
expect(screen.getByText('Cluster: THIS_CLUSTER')).toBeInTheDocument();
expect(
getByText(
screen.getByText(
'Error communicating with Kubernetes: FETCH_ERROR, message: description of error',
),
).toBeInTheDocument();
});
it('displays error message', async () => {
const { getByText } = render(
wrapInTestApp(
<ErrorPanel
entityName="THIS_ENTITY"
errorMessage="SOME_ERROR_MESSAGE"
/>,
),
await renderInTestApp(
<ErrorPanel entityName="THIS_ENTITY" errorMessage="SOME_ERROR_MESSAGE" />,
);
// title
expect(
getByText(
screen.getByText(
'There was a problem retrieving some Kubernetes resources for the entity: THIS_ENTITY. This could mean that the Error Reporting card is not completely accurate.',
),
).toBeInTheDocument();
// message
expect(getByText('Errors: SOME_ERROR_MESSAGE')).toBeInTheDocument();
expect(screen.getByText('Errors: SOME_ERROR_MESSAGE')).toBeInTheDocument();
});
});
@@ -15,36 +15,38 @@
*/
import React from 'react';
import { render } from '@testing-library/react';
import { screen } from '@testing-library/react';
import * as hpas from './__fixtures__/horizontalpodautoscalers.json';
import { wrapInTestApp } from '@backstage/test-utils';
import { renderInTestApp } from '@backstage/test-utils';
import { HorizontalPodAutoscalerDrawer } from './HorizontalPodAutoscalerDrawer';
describe('HorizontalPodAutoscalersDrawer', () => {
it('should render hpa drawer', async () => {
const { getByText } = render(
wrapInTestApp(
<HorizontalPodAutoscalerDrawer hpa={hpas[0] as any} expanded>
<h1>CHILD</h1>
</HorizontalPodAutoscalerDrawer>,
),
await renderInTestApp(
<HorizontalPodAutoscalerDrawer hpa={hpas[0] as any} expanded>
<h1>CHILD</h1>
</HorizontalPodAutoscalerDrawer>,
);
expect(getByText('dice-roller')).toBeInTheDocument();
expect(getByText('CHILD')).toBeInTheDocument();
expect(getByText('HorizontalPodAutoscaler')).toBeInTheDocument();
expect(getByText('YAML')).toBeInTheDocument();
expect(getByText('Target CPU Utilization Percentage')).toBeInTheDocument();
expect(getByText('50')).toBeInTheDocument();
expect(getByText('Current CPU Utilization Percentage')).toBeInTheDocument();
expect(getByText('30')).toBeInTheDocument();
expect(getByText('Min Replicas')).toBeInTheDocument();
expect(getByText('10')).toBeInTheDocument();
expect(getByText('Max Replicas')).toBeInTheDocument();
expect(getByText('15')).toBeInTheDocument();
expect(getByText('Current Replicas')).toBeInTheDocument();
expect(getByText('13')).toBeInTheDocument();
expect(getByText('Desired Replicas')).toBeInTheDocument();
expect(getByText('14')).toBeInTheDocument();
expect(screen.getByText('dice-roller')).toBeInTheDocument();
expect(screen.getByText('CHILD')).toBeInTheDocument();
expect(screen.getByText('HorizontalPodAutoscaler')).toBeInTheDocument();
expect(screen.getByText('YAML')).toBeInTheDocument();
expect(
screen.getByText('Target CPU Utilization Percentage'),
).toBeInTheDocument();
expect(screen.getByText('50')).toBeInTheDocument();
expect(
screen.getByText('Current CPU Utilization Percentage'),
).toBeInTheDocument();
expect(screen.getByText('30')).toBeInTheDocument();
expect(screen.getByText('Min Replicas')).toBeInTheDocument();
expect(screen.getByText('10')).toBeInTheDocument();
expect(screen.getByText('Max Replicas')).toBeInTheDocument();
expect(screen.getByText('15')).toBeInTheDocument();
expect(screen.getByText('Current Replicas')).toBeInTheDocument();
expect(screen.getByText('13')).toBeInTheDocument();
expect(screen.getByText('Desired Replicas')).toBeInTheDocument();
expect(screen.getByText('14')).toBeInTheDocument();
});
});
@@ -14,31 +14,29 @@
* limitations under the License.
*/
import { renderInTestApp, textContentMatcher } from '@backstage/test-utils';
import { screen } from '@testing-library/react';
import React from 'react';
import { render } from '@testing-library/react';
import * as ingresses from './__fixtures__/2-ingresses.json';
import { textContentMatcher, wrapInTestApp } from '@backstage/test-utils';
import { IngressDrawer } from './IngressDrawer';
import * as ingresses from './__fixtures__/2-ingresses.json';
describe('IngressDrawer', () => {
it('should render ingress drawer', async () => {
const { getByText, getAllByText } = render(
wrapInTestApp(
<IngressDrawer ingress={(ingresses as any).ingresses[0]} expanded />,
),
await renderInTestApp(
<IngressDrawer ingress={(ingresses as any).ingresses[0]} expanded />,
);
expect(getAllByText('awesome-service')).toHaveLength(4);
expect(getByText('YAML')).toBeInTheDocument();
expect(getByText('Rules')).toBeInTheDocument();
expect(screen.getAllByText('awesome-service')).toHaveLength(4);
expect(screen.getByText('YAML')).toBeInTheDocument();
expect(screen.getByText('Rules')).toBeInTheDocument();
expect(
getByText(textContentMatcher('Host: api.awesome-host.io')),
screen.getByText(textContentMatcher('Host: api.awesome-host.io')),
).toBeInTheDocument();
expect(getAllByText(textContentMatcher('Service Port: 80'))).toHaveLength(
2,
);
expect(
getAllByText(textContentMatcher('Service Name: awesome-service')),
screen.getAllByText(textContentMatcher('Service Port: 80')),
).toHaveLength(2);
expect(
screen.getAllByText(textContentMatcher('Service Name: awesome-service')),
).toHaveLength(2);
});
});
@@ -15,9 +15,9 @@
*/
import React from 'react';
import { render } from '@testing-library/react';
import { screen } from '@testing-library/react';
import * as oneIngressFixture from './__fixtures__/2-ingresses.json';
import { wrapInTestApp } from '@backstage/test-utils';
import { renderInTestApp } from '@backstage/test-utils';
import { IngressesAccordions } from './IngressesAccordions';
import { kubernetesProviders } from '../../hooks/test-utils';
@@ -25,11 +25,9 @@ describe('IngressesAccordions', () => {
it('should render 1 ingress', async () => {
const wrapper = kubernetesProviders(oneIngressFixture, new Set());
const { getByText } = render(
wrapper(wrapInTestApp(<IngressesAccordions />)),
);
await renderInTestApp(wrapper(<IngressesAccordions />));
expect(getByText('awesome-service')).toBeInTheDocument();
expect(getByText('Ingress')).toBeInTheDocument();
expect(screen.getByText('awesome-service')).toBeInTheDocument();
expect(screen.getByText('Ingress')).toBeInTheDocument();
});
});
@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React from 'react';
import { render } from '@testing-library/react';
import { screen } from '@testing-library/react';
import { JobsAccordions } from './JobsAccordions';
import * as oneCronJobsFixture from '../../__fixtures__/1-cronjobs.json';
import { wrapInTestApp } from '@backstage/test-utils';
import { renderInTestApp } from '@backstage/test-utils';
import { kubernetesProviders } from '../../hooks/test-utils';
import { V1Job, ObjectSerializer } from '@kubernetes/client-node';
@@ -29,14 +30,16 @@ describe('JobsAccordions', () => {
job => ObjectSerializer.deserialize(job, 'V1Job') as V1Job,
);
const { getByText } = render(
wrapper(wrapInTestApp(<JobsAccordions jobs={jobs} />)),
);
await renderInTestApp(wrapper(<JobsAccordions jobs={jobs} />));
expect(getByText('dice-roller-cronjob-1637028600')).toBeInTheDocument();
expect(getByText('Running')).toBeInTheDocument();
expect(
screen.getByText('dice-roller-cronjob-1637028600'),
).toBeInTheDocument();
expect(screen.getByText('Running')).toBeInTheDocument();
expect(getByText('dice-roller-cronjob-1637025000')).toBeInTheDocument();
expect(getByText('Succeeded')).toBeInTheDocument();
expect(
screen.getByText('dice-roller-cronjob-1637025000'),
).toBeInTheDocument();
expect(screen.getByText('Succeeded')).toBeInTheDocument();
});
});
@@ -15,8 +15,8 @@
*/
import React from 'react';
import { render } from '@testing-library/react';
import { wrapInTestApp } from '@backstage/test-utils';
import { screen } from '@testing-library/react';
import { renderInTestApp } from '@backstage/test-utils';
import { KubernetesContent } from './KubernetesContent';
import { useKubernetesObjects } from '../hooks';
@@ -32,22 +32,21 @@ describe('KubernetesContent', () => {
},
error: undefined,
});
const { getByText } = render(
wrapInTestApp(
<KubernetesContent
entity={
{
metadata: {
name: 'some-entity',
},
} as any
}
/>,
),
await renderInTestApp(
<KubernetesContent
entity={
{
metadata: {
name: 'some-entity',
},
} as any
}
/>,
);
expect(getByText('Your Clusters')).toBeInTheDocument();
expect(screen.getByText('Your Clusters')).toBeInTheDocument();
// TODO add a prompt for the user to configure their clusters
});
it('render 1 cluster happy path', async () => {
(useKubernetesObjects as any).mockReturnValue({
kubernetesObjects: {
@@ -75,25 +74,24 @@ describe('KubernetesContent', () => {
},
error: undefined,
});
const { getByText } = render(
wrapInTestApp(
<KubernetesContent
entity={
{
metadata: {
name: 'some-entity',
},
} as any
}
/>,
),
await renderInTestApp(
<KubernetesContent
entity={
{
metadata: {
name: 'some-entity',
},
} as any
}
/>,
);
expect(getByText('cluster-1')).toBeInTheDocument();
expect(getByText('Cluster')).toBeInTheDocument();
expect(getByText('10 pods')).toBeInTheDocument();
expect(getByText('No pods with errors')).toBeInTheDocument();
expect(screen.getByText('cluster-1')).toBeInTheDocument();
expect(screen.getByText('Cluster')).toBeInTheDocument();
expect(screen.getByText('10 pods')).toBeInTheDocument();
expect(screen.getByText('No pods with errors')).toBeInTheDocument();
});
it('render 2 clusters happy path, one with errors', async () => {
(useKubernetesObjects as any).mockReturnValue({
kubernetesObjects: {
@@ -140,26 +138,24 @@ describe('KubernetesContent', () => {
},
error: undefined,
});
const { getByText, getAllByText } = render(
wrapInTestApp(
<KubernetesContent
entity={
{
metadata: {
name: 'some-entity',
},
} as any
}
/>,
),
await renderInTestApp(
<KubernetesContent
entity={
{
metadata: {
name: 'some-entity',
},
} as any
}
/>,
);
expect(getAllByText('Cluster')).toHaveLength(2);
expect(getByText('cluster-a')).toBeInTheDocument();
expect(getByText('10 pods')).toBeInTheDocument();
expect(getByText('No pods with errors')).toBeInTheDocument();
expect(screen.getAllByText('Cluster')).toHaveLength(2);
expect(screen.getByText('cluster-a')).toBeInTheDocument();
expect(screen.getByText('10 pods')).toBeInTheDocument();
expect(screen.getByText('No pods with errors')).toBeInTheDocument();
expect(getAllByText('cluster-1')).toHaveLength(6);
expect(getByText('12 pods')).toBeInTheDocument();
expect(getByText('2 pods with errors')).toBeInTheDocument();
expect(screen.getAllByText('cluster-1')).toHaveLength(6);
expect(screen.getByText('12 pods')).toBeInTheDocument();
expect(screen.getByText('2 pods with errors')).toBeInTheDocument();
});
});
@@ -15,10 +15,10 @@
*/
import React from 'react';
import { render } from '@testing-library/react';
import { screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import { wrapInTestApp } from '@backstage/test-utils';
import { renderInTestApp } from '@backstage/test-utils';
import { ContainerCard } from './ContainerCard';
import { DateTime } from 'luxon';
@@ -30,110 +30,106 @@ const twoHoursAgo = now.minus({ hours: 2 }).toISO();
describe('ContainerCard', () => {
it('show healthy when all checks pass', async () => {
const { getByText, queryByText, getAllByText } = render(
wrapInTestApp(
<ContainerCard
{...({
podScope: {
name: 'some-name',
namespace: 'some-namespace',
clusterName: 'some-cluster',
},
containerSpec: {
readinessProbe: {},
},
containerStatus: {
name: 'some-name',
image: 'gcr.io/some-proj/some-image',
started: true,
ready: true,
restartCount: 0,
state: {
running: {
startedAt: oneHourAgo,
},
await renderInTestApp(
<ContainerCard
{...({
podScope: {
name: 'some-name',
namespace: 'some-namespace',
clusterName: 'some-cluster',
},
containerSpec: {
readinessProbe: {},
},
containerStatus: {
name: 'some-name',
image: 'gcr.io/some-proj/some-image',
started: true,
ready: true,
restartCount: 0,
state: {
running: {
startedAt: oneHourAgo,
},
},
} as any)}
/>,
),
},
} as any)}
/>,
);
expect(getByText('Started: 1 hour ago')).toBeInTheDocument();
expect(getByText('Status: Running')).toBeInTheDocument();
expect(getByText('some-name')).toBeInTheDocument();
expect(getByText('gcr.io/some-proj/some-image')).toBeInTheDocument();
expect(getAllByText('✅')).toHaveLength(5);
expect(queryByText('❌')).toBeNull();
expect(screen.getByText('Started: 1 hour ago')).toBeInTheDocument();
expect(screen.getByText('Status: Running')).toBeInTheDocument();
expect(screen.getByText('some-name')).toBeInTheDocument();
expect(screen.getByText('gcr.io/some-proj/some-image')).toBeInTheDocument();
expect(screen.getAllByText('✅')).toHaveLength(5);
expect(screen.queryByText('❌')).toBeNull();
});
it('show unhealthy when all checks fail', async () => {
const { getByText, queryByText, getAllByText } = render(
wrapInTestApp(
<ContainerCard
{...({
podScope: {
podName: 'some-name',
podNamespace: 'some-namespace',
clusterName: 'some-cluster',
await renderInTestApp(
<ContainerCard
{...({
podScope: {
podName: 'some-name',
podNamespace: 'some-namespace',
clusterName: 'some-cluster',
},
containerSpec: {},
containerStatus: {
name: 'some-name',
image: 'gcr.io/some-proj/some-image',
started: false,
ready: false,
restartCount: 12,
state: {
waiting: {},
},
containerSpec: {},
containerStatus: {
name: 'some-name',
image: 'gcr.io/some-proj/some-image',
started: false,
ready: false,
restartCount: 12,
state: {
waiting: {},
},
},
} as any)}
/>,
),
},
} as any)}
/>,
);
expect(getByText('some-name')).toBeInTheDocument();
expect(getByText('gcr.io/some-proj/some-image')).toBeInTheDocument();
expect(getAllByText('❌')).toHaveLength(5);
expect(queryByText('✅')).toBeNull();
expect(screen.getByText('some-name')).toBeInTheDocument();
expect(screen.getByText('gcr.io/some-proj/some-image')).toBeInTheDocument();
expect(screen.getAllByText('❌')).toHaveLength(5);
expect(screen.queryByText('✅')).toBeNull();
});
it('show correct checks for completed container', async () => {
const { getByText, queryByText, getAllByText } = render(
wrapInTestApp(
<ContainerCard
{...({
podScope: {
podName: 'some-name',
podNamespace: 'some-namespace',
clusterName: 'some-cluster',
},
containerSpec: {},
containerStatus: {
name: 'some-name',
image: 'gcr.io/some-proj/some-image',
started: false,
ready: false,
restartCount: 0,
state: {
terminated: {
exitCode: 0,
reason: 'Completed',
startedAt: twoHoursAgo,
finishedAt: oneHourAgo,
},
await renderInTestApp(
<ContainerCard
{...({
podScope: {
podName: 'some-name',
podNamespace: 'some-namespace',
clusterName: 'some-cluster',
},
containerSpec: {},
containerStatus: {
name: 'some-name',
image: 'gcr.io/some-proj/some-image',
started: false,
ready: false,
restartCount: 0,
state: {
terminated: {
exitCode: 0,
reason: 'Completed',
startedAt: twoHoursAgo,
finishedAt: oneHourAgo,
},
},
} as any)}
/>,
),
},
} as any)}
/>,
);
expect(getByText('some-name')).toBeInTheDocument();
expect(getByText('gcr.io/some-proj/some-image')).toBeInTheDocument();
expect(getByText('Started: 2 hours ago')).toBeInTheDocument();
expect(getByText('Completed: 1 hour ago')).toBeInTheDocument();
expect(screen.getByText('some-name')).toBeInTheDocument();
expect(screen.getByText('gcr.io/some-proj/some-image')).toBeInTheDocument();
expect(screen.getByText('Started: 2 hours ago')).toBeInTheDocument();
expect(screen.getByText('Completed: 1 hour ago')).toBeInTheDocument();
expect(
getByText('Execution time: 1 hour, 0 minutes, 0 seconds'),
screen.getByText('Execution time: 1 hour, 0 minutes, 0 seconds'),
).toBeInTheDocument();
expect(getByText('Status: Completed')).toBeInTheDocument();
expect(getAllByText('✅')).toHaveLength(2);
expect(queryByText('❌')).toBeNull();
expect(screen.getByText('Status: Completed')).toBeInTheDocument();
expect(screen.getAllByText('✅')).toHaveLength(2);
expect(screen.queryByText('❌')).toBeNull();
});
});
@@ -16,10 +16,10 @@
import React from 'react';
import { render } from '@testing-library/react';
import { screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import { wrapInTestApp } from '@backstage/test-utils';
import { renderInTestApp } from '@backstage/test-utils';
import { PendingPodContent } from './PendingPodContent';
import { IPodCondition } from 'kubernetes-models/v1';
import { DateTime } from 'luxon';
@@ -46,141 +46,141 @@ const podWithConditions = (conditions: IPodCondition[]): any => {
describe('PendingPodContent', () => {
it('show startup conditions - all healthy', async () => {
const oneDayAgo = DateTime.now().minus({ days: 1 }).toISO()!;
const { getByText, queryByLabelText, queryAllByLabelText } = render(
wrapInTestApp(
<PendingPodContent
{...{
pod: podWithConditions([
{
type: 'Initialized',
status: 'True',
lastTransitionTime: oneDayAgo,
},
{
type: 'PodScheduled',
status: 'True',
lastTransitionTime: oneDayAgo,
},
{
type: 'ContainersReady',
status: 'True',
lastTransitionTime: oneDayAgo,
},
{
type: 'Ready',
status: 'True',
lastTransitionTime: oneDayAgo,
},
]),
}}
/>,
),
await renderInTestApp(
<PendingPodContent
{...{
pod: podWithConditions([
{
type: 'Initialized',
status: 'True',
lastTransitionTime: oneDayAgo,
},
{
type: 'PodScheduled',
status: 'True',
lastTransitionTime: oneDayAgo,
},
{
type: 'ContainersReady',
status: 'True',
lastTransitionTime: oneDayAgo,
},
{
type: 'Ready',
status: 'True',
lastTransitionTime: oneDayAgo,
},
]),
}}
/>,
);
expect(getByText('Pod is Pending. Conditions:')).toBeInTheDocument();
expect(screen.getByText('Pod is Pending. Conditions:')).toBeInTheDocument();
expect(getByText('Initialized - (1 day ago)')).toBeInTheDocument();
expect(getByText('PodScheduled - (1 day ago)')).toBeInTheDocument();
expect(getByText('ContainersReady - (1 day ago)')).toBeInTheDocument();
expect(getByText('Ready - (1 day ago)')).toBeInTheDocument();
expect(screen.getByText('Initialized - (1 day ago)')).toBeInTheDocument();
expect(screen.getByText('PodScheduled - (1 day ago)')).toBeInTheDocument();
expect(
screen.getByText('ContainersReady - (1 day ago)'),
).toBeInTheDocument();
expect(screen.getByText('Ready - (1 day ago)')).toBeInTheDocument();
expect(queryAllByLabelText('Status ok')).toHaveLength(4);
expect(queryByLabelText('Status warning')).not.toBeInTheDocument();
expect(queryByLabelText('Status error')).not.toBeInTheDocument();
expect(screen.queryAllByLabelText('Status ok')).toHaveLength(4);
expect(screen.queryByLabelText('Status warning')).not.toBeInTheDocument();
expect(screen.queryByLabelText('Status error')).not.toBeInTheDocument();
});
it('show startup conditions - all fail', async () => {
const oneHourAgo = DateTime.now().minus({ hours: 1 }).toISO()!;
const { getByText, queryByLabelText, queryAllByLabelText } = render(
wrapInTestApp(
<PendingPodContent
{...{
pod: podWithConditions([
{
type: 'Initialized',
status: 'False',
reason: 'InitializedFailureReason',
message: 'reason why Initialized failed',
lastTransitionTime: oneHourAgo,
},
{
type: 'PodScheduled',
status: 'False',
reason: 'PodScheduledFailureReason',
message: 'reason why PodScheduled failed',
lastTransitionTime: oneHourAgo,
},
{
type: 'ContainersReady',
status: 'False',
reason: 'ContainersReadyFailureReason',
message: 'reason why ContainersReady failed',
lastTransitionTime: oneHourAgo,
},
{
type: 'Ready',
status: 'False',
reason: 'ReadyFailureReason',
message: 'reason why Ready failed',
lastTransitionTime: oneHourAgo,
},
]),
}}
/>,
),
await renderInTestApp(
<PendingPodContent
{...{
pod: podWithConditions([
{
type: 'Initialized',
status: 'False',
reason: 'InitializedFailureReason',
message: 'reason why Initialized failed',
lastTransitionTime: oneHourAgo,
},
{
type: 'PodScheduled',
status: 'False',
reason: 'PodScheduledFailureReason',
message: 'reason why PodScheduled failed',
lastTransitionTime: oneHourAgo,
},
{
type: 'ContainersReady',
status: 'False',
reason: 'ContainersReadyFailureReason',
message: 'reason why ContainersReady failed',
lastTransitionTime: oneHourAgo,
},
{
type: 'Ready',
status: 'False',
reason: 'ReadyFailureReason',
message: 'reason why Ready failed',
lastTransitionTime: oneHourAgo,
},
]),
}}
/>,
);
expect(getByText('Pod is Pending. Conditions:')).toBeInTheDocument();
expect(screen.getByText('Pod is Pending. Conditions:')).toBeInTheDocument();
expect(
getByText(
screen.getByText(
'Initialized - (InitializedFailureReason 1 hour ago) - reason why Initialized failed',
),
).toBeInTheDocument();
expect(
getByText(
screen.getByText(
'PodScheduled - (PodScheduledFailureReason 1 hour ago) - reason why PodScheduled failed',
),
).toBeInTheDocument();
expect(
getByText(
screen.getByText(
'ContainersReady - (ContainersReadyFailureReason 1 hour ago) - reason why ContainersReady failed',
),
).toBeInTheDocument();
expect(
getByText(
screen.getByText(
'Ready - (ReadyFailureReason 1 hour ago) - reason why Ready failed',
),
).toBeInTheDocument();
expect(queryByLabelText('Status ok')).not.toBeInTheDocument();
expect(queryByLabelText('Status warning')).not.toBeInTheDocument();
expect(queryAllByLabelText('Status error')).toHaveLength(4);
expect(screen.queryByLabelText('Status ok')).not.toBeInTheDocument();
expect(screen.queryByLabelText('Status warning')).not.toBeInTheDocument();
expect(screen.queryAllByLabelText('Status error')).toHaveLength(4);
});
it('show startup conditions - show unknown', async () => {
const oneHourAgo = DateTime.now().minus({ hours: 1 }).toISO()!;
const { getByText, queryByLabelText, getByLabelText } = render(
wrapInTestApp(
<PendingPodContent
{...{
pod: podWithConditions([
{
type: 'Initialized',
status: 'Unknown',
reason: 'InitializedUnknownReason',
message: 'dont know what is happening',
lastTransitionTime: oneHourAgo,
},
]),
}}
/>,
),
await renderInTestApp(
<PendingPodContent
{...{
pod: podWithConditions([
{
type: 'Initialized',
status: 'Unknown',
reason: 'InitializedUnknownReason',
message: 'dont know what is happening',
lastTransitionTime: oneHourAgo,
},
]),
}}
/>,
);
expect(getByText('Pod is Pending. Conditions:')).toBeInTheDocument();
expect(screen.getByText('Pod is Pending. Conditions:')).toBeInTheDocument();
expect(
getByText('Initialized - (1 hour ago) dont know what is happening'),
screen.getByText(
'Initialized - (1 hour ago) dont know what is happening',
),
).toBeInTheDocument();
expect(queryByLabelText('Status ok')).not.toBeInTheDocument();
expect(getByLabelText('Status warning')).toBeInTheDocument();
expect(queryByLabelText('Status error')).not.toBeInTheDocument();
expect(screen.queryByLabelText('Status ok')).not.toBeInTheDocument();
expect(screen.getByLabelText('Status warning')).toBeInTheDocument();
expect(screen.queryByLabelText('Status error')).not.toBeInTheDocument();
});
});
@@ -16,11 +16,11 @@
import React from 'react';
import { render } from '@testing-library/react';
import { TestApiProvider, wrapInTestApp } from '@backstage/test-utils';
import { screen } from '@testing-library/react';
import { TestApiProvider, renderInTestApp } from '@backstage/test-utils';
import '@testing-library/jest-dom';
import { PodDrawer } from '.';
import { PodDrawer } from './PodDrawer';
import { DiscoveryApi, discoveryApiRef } from '@backstage/core-plugin-api';
jest.mock('../../../hooks/useIsPodExecTerminalSupported');
@@ -31,69 +31,67 @@ describe('PodDrawer', () => {
getBaseUrl: () => Promise.resolve('http://localhost'),
};
const { getAllByText, getByText } = render(
wrapInTestApp(
<TestApiProvider apis={[[discoveryApiRef, mockDiscoveryApi]]}>
<PodDrawer
{...({
open: true,
podAndErrors: {
clusterName: 'some-cluster-1',
pod: {
metadata: {
name: 'some-pod',
},
spec: {
containers: [
{
name: 'some-container',
},
],
},
status: {
podIP: '127.0.0.1',
containerStatuses: [
{
name: 'some-container',
},
],
},
await renderInTestApp(
<TestApiProvider apis={[[discoveryApiRef, mockDiscoveryApi]]}>
<PodDrawer
{...({
open: true,
podAndErrors: {
clusterName: 'some-cluster-1',
pod: {
metadata: {
name: 'some-pod',
},
errors: [
{
type: 'some-error',
severity: 10,
message: 'some error message',
occurrenceCount: 1,
sourceRef: {
name: 'some-pod',
namespace: 'some-namespace',
kind: 'Pod',
apiGroup: 'v1',
spec: {
containers: [
{
name: 'some-container',
},
proposedFix: [
{
type: 'logs',
container: 'some-container',
errorType: 'some error type',
rootCauseExplanation: 'some root cause',
actions: ['fix1', 'fix2'],
},
],
},
],
],
},
status: {
podIP: '127.0.0.1',
containerStatuses: [
{
name: 'some-container',
},
],
},
},
} as any)}
/>
</TestApiProvider>,
),
errors: [
{
type: 'some-error',
severity: 10,
message: 'some error message',
occurrenceCount: 1,
sourceRef: {
name: 'some-pod',
namespace: 'some-namespace',
kind: 'Pod',
apiGroup: 'v1',
},
proposedFix: [
{
type: 'logs',
container: 'some-container',
errorType: 'some error type',
rootCauseExplanation: 'some root cause',
actions: ['fix1', 'fix2'],
},
],
},
],
},
} as any)}
/>
</TestApiProvider>,
);
expect(getAllByText('some-pod')).toHaveLength(3);
expect(getByText('Pod (127.0.0.1)')).toBeInTheDocument();
expect(getByText('YAML')).toBeInTheDocument();
expect(getByText('Containers')).toBeInTheDocument();
expect(getByText('some-container')).toBeInTheDocument();
expect(getByText('some error message')).toBeInTheDocument();
expect(screen.getAllByText('some-pod')).toHaveLength(3);
expect(screen.getByText('Pod (127.0.0.1)')).toBeInTheDocument();
expect(screen.getByText('YAML')).toBeInTheDocument();
expect(screen.getByText('Containers')).toBeInTheDocument();
expect(screen.getByText('some-container')).toBeInTheDocument();
expect(screen.getByText('some error message')).toBeInTheDocument();
});
});
+82 -92
View File
@@ -15,52 +15,49 @@
*/
import React from 'react';
import { render } from '@testing-library/react';
import { screen } from '@testing-library/react';
import * as pod from './__fixtures__/pod.json';
import * as crashingPod from './__fixtures__/crashing-pod.json';
import { wrapInTestApp } from '@backstage/test-utils';
import { renderInTestApp } from '@backstage/test-utils';
import { PodsTable, READY_COLUMNS, RESOURCE_COLUMNS } from './PodsTable';
import { kubernetesProviders } from '../../hooks/test-utils';
import { ClientPodStatus } from '@backstage/plugin-kubernetes-common';
describe('PodsTable', () => {
it('should render pod', async () => {
const { getByText } = render(
wrapInTestApp(<PodsTable pods={[pod as any]} />),
);
await renderInTestApp(<PodsTable pods={[pod as any]} />);
// titles
expect(getByText('name')).toBeInTheDocument();
expect(getByText('phase')).toBeInTheDocument();
expect(getByText('status')).toBeInTheDocument();
expect(screen.getByText('name')).toBeInTheDocument();
expect(screen.getByText('phase')).toBeInTheDocument();
expect(screen.getByText('status')).toBeInTheDocument();
// values
expect(getByText('dice-roller-6c8646bfd-2m5hv')).toBeInTheDocument();
expect(getByText('Running')).toBeInTheDocument();
expect(getByText('OK')).toBeInTheDocument();
expect(screen.getByText('dice-roller-6c8646bfd-2m5hv')).toBeInTheDocument();
expect(screen.getByText('Running')).toBeInTheDocument();
expect(screen.getByText('OK')).toBeInTheDocument();
});
it('should render pod with extra columns', async () => {
const { getByText } = render(
wrapInTestApp(
<PodsTable pods={[pod as any]} extraColumns={[READY_COLUMNS]} />,
),
await renderInTestApp(
<PodsTable pods={[pod as any]} extraColumns={[READY_COLUMNS]} />,
);
// titles
expect(getByText('name')).toBeInTheDocument();
expect(getByText('phase')).toBeInTheDocument();
expect(getByText('containers ready')).toBeInTheDocument();
expect(getByText('total restarts')).toBeInTheDocument();
expect(getByText('status')).toBeInTheDocument();
expect(screen.getByText('name')).toBeInTheDocument();
expect(screen.getByText('phase')).toBeInTheDocument();
expect(screen.getByText('containers ready')).toBeInTheDocument();
expect(screen.getByText('total restarts')).toBeInTheDocument();
expect(screen.getByText('status')).toBeInTheDocument();
// values
expect(getByText('dice-roller-6c8646bfd-2m5hv')).toBeInTheDocument();
expect(getByText('Running')).toBeInTheDocument();
expect(getByText('1/1')).toBeInTheDocument();
expect(getByText('0')).toBeInTheDocument();
expect(getByText('OK')).toBeInTheDocument();
expect(screen.getByText('dice-roller-6c8646bfd-2m5hv')).toBeInTheDocument();
expect(screen.getByText('Running')).toBeInTheDocument();
expect(screen.getByText('1/1')).toBeInTheDocument();
expect(screen.getByText('0')).toBeInTheDocument();
expect(screen.getByText('OK')).toBeInTheDocument();
});
it('should render pod, with metrics context', async () => {
const clusterToClientPodStatus = new Map<string, ClientPodStatus[]>();
@@ -93,37 +90,36 @@ describe('PodsTable', () => {
name: 'some-cluster',
},
);
const { getByText } = render(
await renderInTestApp(
wrapper(
wrapInTestApp(
<PodsTable
pods={[pod as any]}
extraColumns={[READY_COLUMNS, RESOURCE_COLUMNS]}
/>,
),
<PodsTable
pods={[pod as any]}
extraColumns={[READY_COLUMNS, RESOURCE_COLUMNS]}
/>,
),
);
// titles
expect(getByText('name')).toBeInTheDocument();
expect(getByText('phase')).toBeInTheDocument();
expect(getByText('containers ready')).toBeInTheDocument();
expect(getByText('total restarts')).toBeInTheDocument();
expect(getByText('status')).toBeInTheDocument();
expect(getByText('CPU usage %')).toBeInTheDocument();
expect(getByText('Memory usage %')).toBeInTheDocument();
expect(screen.getByText('name')).toBeInTheDocument();
expect(screen.getByText('phase')).toBeInTheDocument();
expect(screen.getByText('containers ready')).toBeInTheDocument();
expect(screen.getByText('total restarts')).toBeInTheDocument();
expect(screen.getByText('status')).toBeInTheDocument();
expect(screen.getByText('CPU usage %')).toBeInTheDocument();
expect(screen.getByText('Memory usage %')).toBeInTheDocument();
// values
expect(getByText('dice-roller-6c8646bfd-2m5hv')).toBeInTheDocument();
expect(getByText('Running')).toBeInTheDocument();
expect(getByText('1/1')).toBeInTheDocument();
expect(getByText('0')).toBeInTheDocument();
expect(getByText('OK')).toBeInTheDocument();
expect(getByText('requests: 99% of 50m')).toBeInTheDocument();
expect(getByText('limits: 99% of 50m')).toBeInTheDocument();
expect(getByText('requests: 1% of 64MiB')).toBeInTheDocument();
expect(getByText('limits: 0% of 128MiB')).toBeInTheDocument();
expect(screen.getByText('dice-roller-6c8646bfd-2m5hv')).toBeInTheDocument();
expect(screen.getByText('Running')).toBeInTheDocument();
expect(screen.getByText('1/1')).toBeInTheDocument();
expect(screen.getByText('0')).toBeInTheDocument();
expect(screen.getByText('OK')).toBeInTheDocument();
expect(screen.getByText('requests: 99% of 50m')).toBeInTheDocument();
expect(screen.getByText('limits: 99% of 50m')).toBeInTheDocument();
expect(screen.getByText('requests: 1% of 64MiB')).toBeInTheDocument();
expect(screen.getByText('limits: 0% of 128MiB')).toBeInTheDocument();
});
it('should render placeholder when empty metrics context', async () => {
const podNameToClientPodStatus = new Map<string, ClientPodStatus[]>();
@@ -132,60 +128,54 @@ describe('PodsTable', () => {
undefined,
podNameToClientPodStatus,
);
const { getByText, getAllByText } = render(
await renderInTestApp(
wrapper(
wrapInTestApp(
<PodsTable
pods={[pod as any]}
extraColumns={[READY_COLUMNS, RESOURCE_COLUMNS]}
/>,
),
),
);
// titles
expect(getByText('name')).toBeInTheDocument();
expect(getByText('phase')).toBeInTheDocument();
expect(getByText('containers ready')).toBeInTheDocument();
expect(getByText('total restarts')).toBeInTheDocument();
expect(getByText('status')).toBeInTheDocument();
expect(getByText('CPU usage %')).toBeInTheDocument();
expect(getByText('Memory usage %')).toBeInTheDocument();
// values
expect(getByText('dice-roller-6c8646bfd-2m5hv')).toBeInTheDocument();
expect(getByText('Running')).toBeInTheDocument();
expect(getByText('1/1')).toBeInTheDocument();
expect(getByText('0')).toBeInTheDocument();
expect(getByText('OK')).toBeInTheDocument();
expect(getAllByText('unknown')).toHaveLength(2);
});
it('should render crashing pod with extra columns', async () => {
const { getByText, getAllByText } = render(
wrapInTestApp(
<PodsTable
pods={[crashingPod as any]}
extraColumns={[READY_COLUMNS]}
pods={[pod as any]}
extraColumns={[READY_COLUMNS, RESOURCE_COLUMNS]}
/>,
),
);
// titles
expect(getByText('name')).toBeInTheDocument();
expect(getByText('phase')).toBeInTheDocument();
expect(getByText('containers ready')).toBeInTheDocument();
expect(getByText('total restarts')).toBeInTheDocument();
expect(getByText('status')).toBeInTheDocument();
expect(screen.getByText('name')).toBeInTheDocument();
expect(screen.getByText('phase')).toBeInTheDocument();
expect(screen.getByText('containers ready')).toBeInTheDocument();
expect(screen.getByText('total restarts')).toBeInTheDocument();
expect(screen.getByText('status')).toBeInTheDocument();
expect(screen.getByText('CPU usage %')).toBeInTheDocument();
expect(screen.getByText('Memory usage %')).toBeInTheDocument();
// values
expect(screen.getByText('dice-roller-6c8646bfd-2m5hv')).toBeInTheDocument();
expect(screen.getByText('Running')).toBeInTheDocument();
expect(screen.getByText('1/1')).toBeInTheDocument();
expect(screen.getByText('0')).toBeInTheDocument();
expect(screen.getByText('OK')).toBeInTheDocument();
expect(screen.getAllByText('unknown')).toHaveLength(2);
});
it('should render crashing pod with extra columns', async () => {
await renderInTestApp(
<PodsTable pods={[crashingPod as any]} extraColumns={[READY_COLUMNS]} />,
);
// titles
expect(screen.getByText('name')).toBeInTheDocument();
expect(screen.getByText('phase')).toBeInTheDocument();
expect(screen.getByText('containers ready')).toBeInTheDocument();
expect(screen.getByText('total restarts')).toBeInTheDocument();
expect(screen.getByText('status')).toBeInTheDocument();
// values
expect(
getByText('dice-roller-canary-7d64cd756c-55rfq'),
screen.getByText('dice-roller-canary-7d64cd756c-55rfq'),
).toBeInTheDocument();
expect(getByText('Running')).toBeInTheDocument();
expect(getByText('1/3')).toBeInTheDocument();
expect(getByText('76')).toBeInTheDocument();
expect(getByText('Container: side-car')).toBeInTheDocument();
expect(getByText('Container: other-side-car')).toBeInTheDocument();
expect(getAllByText('CrashLoopBackOff')).toHaveLength(2);
expect(screen.getByText('Running')).toBeInTheDocument();
expect(screen.getByText('1/3')).toBeInTheDocument();
expect(screen.getByText('76')).toBeInTheDocument();
expect(screen.getByText('Container: side-car')).toBeInTheDocument();
expect(screen.getByText('Container: other-side-car')).toBeInTheDocument();
expect(screen.getAllByText('CrashLoopBackOff')).toHaveLength(2);
});
});
@@ -15,40 +15,37 @@
*/
import React from 'react';
import { render } from '@testing-library/react';
import { screen } from '@testing-library/react';
import { ResourceUtilization } from './ResourceUtilization';
import { wrapInTestApp } from '@backstage/test-utils';
import { renderInTestApp } from '@backstage/test-utils';
describe('ResourceUtilization', () => {
it('should render utilization', async () => {
const { getByText } = render(
wrapInTestApp(
<ResourceUtilization
title="some-title"
usage="1000"
total="10000"
totalFormatted="15%"
/>,
),
await renderInTestApp(
<ResourceUtilization
title="some-title"
usage="1000"
total="10000"
totalFormatted="15%"
/>,
);
expect(getByText('some-title: 15%')).toBeInTheDocument();
expect(getByText('usage: 10%')).toBeInTheDocument();
expect(screen.getByText('some-title: 15%')).toBeInTheDocument();
expect(screen.getByText('usage: 10%')).toBeInTheDocument();
});
it('no usage when compressed', async () => {
const { getByText, queryByText } = render(
wrapInTestApp(
<ResourceUtilization
compressed
title="some-title"
usage="1000"
total="10000"
totalFormatted="15%"
/>,
),
await renderInTestApp(
<ResourceUtilization
compressed
title="some-title"
usage="1000"
total="10000"
totalFormatted="15%"
/>,
);
expect(getByText('some-title: 15%')).toBeInTheDocument();
expect(queryByText('usage: 10%')).toBeNull();
expect(screen.getByText('some-title: 15%')).toBeInTheDocument();
expect(screen.queryByText('usage: 10%')).toBeNull();
});
});
@@ -15,29 +15,27 @@
*/
import React from 'react';
import { render } from '@testing-library/react';
import { screen } from '@testing-library/react';
import * as services from './__fixtures__/2-services.json';
import { textContentMatcher, wrapInTestApp } from '@backstage/test-utils';
import { textContentMatcher, renderInTestApp } from '@backstage/test-utils';
import { ServiceDrawer } from './ServiceDrawer';
describe('ServiceDrawer', () => {
it('should render deployment drawer', async () => {
const { getByText, getAllByText } = render(
wrapInTestApp(
<ServiceDrawer service={(services as any).services[0]} expanded />,
),
await renderInTestApp(
<ServiceDrawer service={(services as any).services[0]} expanded />,
);
expect(getAllByText('awesome-service-grpc')).toHaveLength(2);
expect(getAllByText('Service')).toHaveLength(2);
expect(getByText('YAML')).toBeInTheDocument();
expect(getByText('Cluster IP')).toBeInTheDocument();
expect(getByText('Ports')).toBeInTheDocument();
expect(screen.getAllByText('awesome-service-grpc')).toHaveLength(2);
expect(screen.getAllByText('Service')).toHaveLength(2);
expect(screen.getByText('YAML')).toBeInTheDocument();
expect(screen.getByText('Cluster IP')).toBeInTheDocument();
expect(screen.getByText('Ports')).toBeInTheDocument();
expect(
getByText(textContentMatcher('Target Port: 1997')),
screen.getByText(textContentMatcher('Target Port: 1997')),
).toBeInTheDocument();
expect(
getByText(textContentMatcher('App: awesome-service')),
screen.getByText(textContentMatcher('App: awesome-service')),
).toBeInTheDocument();
});
});
@@ -15,9 +15,9 @@
*/
import React from 'react';
import { render } from '@testing-library/react';
import { screen } from '@testing-library/react';
import * as twoDeployFixture from './__fixtures__/2-services.json';
import { wrapInTestApp } from '@backstage/test-utils';
import { renderInTestApp } from '@backstage/test-utils';
import { ServicesAccordions } from './ServicesAccordions';
import { kubernetesProviders } from '../../hooks/test-utils';
@@ -25,14 +25,12 @@ describe('ServicesAccordions', () => {
it('should render 2 services', async () => {
const wrapper = kubernetesProviders(twoDeployFixture, new Set());
const { getByText } = render(
wrapper(wrapInTestApp(<ServicesAccordions />)),
);
await renderInTestApp(wrapper(<ServicesAccordions />));
expect(getByText('awesome-service-grpc')).toBeInTheDocument();
expect(getByText('Type: ClusterIP')).toBeInTheDocument();
expect(screen.getByText('awesome-service-grpc')).toBeInTheDocument();
expect(screen.getByText('Type: ClusterIP')).toBeInTheDocument();
expect(getByText('awesome-service-pg')).toBeInTheDocument();
expect(getByText('Type: ExternalName')).toBeInTheDocument();
expect(screen.getByText('awesome-service-pg')).toBeInTheDocument();
expect(screen.getByText('Type: ExternalName')).toBeInTheDocument();
});
});
@@ -15,10 +15,10 @@
*/
import React from 'react';
import { render } from '@testing-library/react';
import { screen } from '@testing-library/react';
import { StatefulSetsAccordions } from './StatefulSetsAccordions';
import * as twoStatefulSetsFixture from '../../__fixtures__/2-statefulsets.json';
import { wrapInTestApp } from '@backstage/test-utils';
import { renderInTestApp } from '@backstage/test-utils';
import { kubernetesProviders } from '../../hooks/test-utils';
describe('StatefulSetsAccordions', () => {
@@ -28,18 +28,16 @@ describe('StatefulSetsAccordions', () => {
new Set(['dice-roller-canary-7d64cd756c-vtbdx']),
);
const { getByText, getAllByText } = render(
wrapper(wrapInTestApp(<StatefulSetsAccordions />)),
);
await renderInTestApp(wrapper(<StatefulSetsAccordions />));
expect(getByText('dice-roller')).toBeInTheDocument();
expect(getByText('10 pods')).toBeInTheDocument();
expect(getByText('No pods with errors')).toBeInTheDocument();
expect(screen.getByText('dice-roller')).toBeInTheDocument();
expect(screen.getByText('10 pods')).toBeInTheDocument();
expect(screen.getByText('No pods with errors')).toBeInTheDocument();
expect(getByText('dice-roller-canary')).toBeInTheDocument();
expect(getByText('2 pods')).toBeInTheDocument();
expect(getByText('1 pod with errors')).toBeInTheDocument();
expect(screen.getByText('dice-roller-canary')).toBeInTheDocument();
expect(screen.getByText('2 pods')).toBeInTheDocument();
expect(screen.getByText('1 pod with errors')).toBeInTheDocument();
expect(getAllByText('namespace: default')).toHaveLength(2);
expect(screen.getAllByText('namespace: default')).toHaveLength(2);
});
});