Skip to content

Commit

Permalink
Use factorized/faked data in the trigger checks comp tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arbulu89 committed Dec 19, 2022
1 parent 0f908ee commit 57a90f0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,43 @@ import React from 'react';

import { screen, act } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { faker } from '@faker-js/faker';
import { withState, renderWithRouter } from '@lib/test-utils';

import { clusterFactory, hostFactory } from '@lib/test-utils/factories';

import TriggerChecksExecutionRequest from './TriggerChecksExecutionRequest';

describe('TriggerChecksExecutionRequest', () => {
it('should dispatch execution requested on click', async () => {
const user = userEvent.setup();
const cluster1 = clusterFactory.build({
selected_checks: [faker.datatype.uuid(), faker.datatype.uuid()],
});
const cluster2 = clusterFactory.build({
selected_checks: [faker.datatype.uuid(), faker.datatype.uuid()],
});
const { id: clusterID1, selected_checks: clusterSelectedChecks1 } =
cluster1;
const { id: clusterID2 } = cluster2;

const host1 = hostFactory.build({ cluster_id: clusterID1 });
const host2 = hostFactory.build({ cluster_id: clusterID1 });
const host3 = hostFactory.build({ cluster_id: clusterID2 });
const { id: hostID1 } = host1;
const { id: hostID2 } = host2;

const initialState = {
clustersList: {
clusters: [
{
id: 'cluster1',
selected_checks: ['check1', 'check3'],
},
{
id: 'cluster2',
selected_checks: ['check3', 'check4'],
},
],
clusters: [cluster1, cluster2],
},
hostsList: {
hosts: [
{
id: 'host1',
cluster_id: 'cluster1',
},
{
id: 'host2',
cluster_id: 'cluster1',
},
{
id: 'host3',
cluster_id: 'cluster2',
},
],
hosts: [host1, host2, host3],
},
};

const [statefulView, store] = withState(
<TriggerChecksExecutionRequest clusterId="cluster1" usingWanda />,
<TriggerChecksExecutionRequest clusterId={clusterID1} usingWanda />,
initialState
);

Expand All @@ -56,9 +52,9 @@ describe('TriggerChecksExecutionRequest', () => {
{
type: 'EXECUTION_REQUESTED',
payload: {
clusterID: 'cluster1',
hosts: ['host1', 'host2'],
checks: ['check1', 'check3'],
clusterID: clusterID1,
hosts: [hostID1, hostID2],
checks: clusterSelectedChecks1,
},
},
];
Expand Down
5 changes: 5 additions & 0 deletions assets/js/lib/test-utils/factories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ export const catalogFactory = Factory.define(() => ({
error: null,
}));

export const hostFactory = Factory.define(() => ({
id: faker.datatype.uuid(),
cluster_id: faker.datatype.uuid(),
}));

export const hostnameFactory = Factory.define(() => ({
id: faker.datatype.uuid(),
hostname: faker.hacker.noun(),
Expand Down

0 comments on commit 57a90f0

Please sign in to comment.