Skip to content

Commit

Permalink
fixed failing unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaileshParmar11 committed Nov 10, 2023
1 parent 19f2268 commit 7426eaf
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jest.mock('../../utils/DataInsightUtils', () => ({
getGraphDataByEntityType: jest
.fn()
.mockImplementation(() => DUMMY_GRAPH_DATA),
sortEntityByValue: jest.fn().mockImplementation((entities) => entities),
}));
jest.mock('./EntitySummaryProgressBar.component', () => {
return jest.fn().mockImplementation(({ label, entity }) => (
Expand All @@ -58,40 +59,44 @@ jest.mock('react-i18next', () => ({
describe('Test DescriptionInsight Component', () => {
it('Should render the graph', async () => {
await act(async () => {
const { container } = render(<DescriptionInsight {...mockProps} />);
const card = screen.getByTestId('entity-description-percentage-card');
render(<DescriptionInsight {...mockProps} />);
});
const card = await screen.findByTestId(
'entity-description-percentage-card'
);

const graph = queryByAttribute(
'id',
container,
`${mockProps.dataInsightChartName}-graph`
);
const graph = queryByAttribute(
'id',
card,
`${mockProps.dataInsightChartName}-graph`
);

expect(card).toBeInTheDocument();
expect(graph).toBeInTheDocument();
});
expect(card).toBeInTheDocument();
expect(graph).toBeInTheDocument();
});

it('Should render the graph and progress bar even if one entity dont have values', async () => {
(getGraphDataByEntityType as jest.Mock).mockImplementationOnce(
() => DUMMY_GRAPH_DATA_WITH_MISSING_ENTITY
);
await act(async () => {
const { container } = render(<DescriptionInsight {...mockProps} />);
const card = screen.getByTestId('entity-description-percentage-card');
render(<DescriptionInsight {...mockProps} />);
});
const card = await screen.findByTestId(
'entity-description-percentage-card'
);

const graph = queryByAttribute(
'id',
container,
`${mockProps.dataInsightChartName}-graph`
);
const missingEntityValue = await screen.findByTestId('Table');
const graph = queryByAttribute(
'id',
card,
`${mockProps.dataInsightChartName}-graph`
);
const missingEntityValue = await screen.findByTestId('Table');

expect(card).toBeInTheDocument();
expect(graph).toBeInTheDocument();
expect(missingEntityValue).toBeInTheDocument();
expect(missingEntityValue.textContent).toBe('0');
});
expect(card).toBeInTheDocument();
expect(graph).toBeInTheDocument();
expect(missingEntityValue).toBeInTheDocument();
expect(missingEntityValue.textContent).toBe('0');
});

it('Should fetch data based on dataInsightChartName props', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jest.mock('../../utils/DataInsightUtils', () => ({
getGraphDataByEntityType: jest
.fn()
.mockImplementation(() => DUMMY_GRAPH_DATA),
sortEntityByValue: jest.fn().mockImplementation((entities) => entities),
}));
jest.mock('./EntitySummaryProgressBar.component', () => {
return jest.fn().mockImplementation(({ label, entity }) => (
Expand All @@ -59,40 +60,40 @@ jest.mock('react-i18next', () => ({
describe('Test DescriptionInsight Component', () => {
it('Should render the graph', async () => {
await act(async () => {
const { container } = render(<OwnerInsight {...mockProps} />);
const card = screen.getByTestId('entity-summary-card-percentage');
render(<OwnerInsight {...mockProps} />);
});
const card = await screen.findByTestId('entity-summary-card-percentage');

const graph = queryByAttribute(
'id',
container,
`${mockProps.dataInsightChartName}-graph`
);
const graph = queryByAttribute(
'id',
card,
`${mockProps.dataInsightChartName}-graph`
);

expect(card).toBeInTheDocument();
expect(graph).toBeInTheDocument();
});
expect(card).toBeInTheDocument();
expect(graph).toBeInTheDocument();
});

it('Should render the graph and progress bar even if one entity dont have values', async () => {
(getGraphDataByEntityType as jest.Mock).mockImplementationOnce(
() => DUMMY_GRAPH_DATA_WITH_MISSING_ENTITY
);
await act(async () => {
const { container } = render(<OwnerInsight {...mockProps} />);
const card = screen.getByTestId('entity-summary-card-percentage');
render(<OwnerInsight {...mockProps} />);
});
const card = await screen.findByTestId('entity-summary-card-percentage');

const graph = queryByAttribute(
'id',
container,
`${mockProps.dataInsightChartName}-graph`
);
const missingEntityValue = await screen.findByTestId('Table');
const graph = queryByAttribute(
'id',
card,
`${mockProps.dataInsightChartName}-graph`
);
const missingEntityValue = await screen.findByTestId('Table');

expect(card).toBeInTheDocument();
expect(graph).toBeInTheDocument();
expect(missingEntityValue).toBeInTheDocument();
expect(missingEntityValue.textContent).toBe('0');
});
expect(card).toBeInTheDocument();
expect(graph).toBeInTheDocument();
expect(missingEntityValue).toBeInTheDocument();
expect(missingEntityValue.textContent).toBe('0');
});

it('Should fetch data based on dataInsightChartName props', async () => {
Expand Down

0 comments on commit 7426eaf

Please sign in to comment.