Skip to content

Commit

Permalink
Test mock posts
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Chong <aaronchongth@gmail.com>
  • Loading branch information
aaronchongth committed Dec 4, 2024
1 parent bcdc611 commit cfe5bab
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fireEvent } from '@testing-library/react';
import { describe, expect, it } from 'vitest';
import { describe, expect, it, vi } from 'vitest';

import { RmfApiProvider } from '../../hooks';
import { MockRmfApi, render, TestProviders } from '../../utils/test-utils.test';
Expand All @@ -9,8 +9,16 @@ import { makeRobot } from './test-utils.test';
describe('Robot decommission button', () => {
const rmfApi = new MockRmfApi();
// mock out some api calls so they never resolves
rmfApi.fleetsApi.decommissionRobotFleetsNameDecommissionPost = () => new Promise(() => {});
rmfApi.fleetsApi.recommissionRobotFleetsNameRecommissionPost = () => new Promise(() => {});
const mockDecommission = vi.fn().mockImplementation(async () => {
// Simulate some asynchronous operation that has no return value
await new Promise((resolve) => setTimeout(resolve, 100));
});
const mockRecommission = vi.fn().mockImplementation(async () => {
// Simulate some asynchronous operation that has no return value
await new Promise((resolve) => setTimeout(resolve, 100));
});
rmfApi.fleetsApi.decommissionRobotFleetsNameDecommissionPost = mockDecommission;
rmfApi.fleetsApi.recommissionRobotFleetsNameRecommissionPost = mockRecommission;
const Base = (props: React.PropsWithChildren<{}>) => {
return (
<TestProviders>
Expand All @@ -32,6 +40,9 @@ describe('Robot decommission button', () => {
expect(root.getByText('Decommission')).toBeTruthy();
fireEvent.click(root.getByText('Decommission'));
expect(root.getByText('Decommission [test_fleet:test_robot]')).toBeTruthy();
expect(root.getByText('Confirm'));
fireEvent.click(root.getByText('Confirm'));
expect(mockDecommission).toHaveBeenCalledOnce();
});

it('Renders recommission button', () => {
Expand All @@ -54,5 +65,8 @@ describe('Robot decommission button', () => {
expect(root.getByText('Recommission')).toBeTruthy();
fireEvent.click(root.getByText('Recommission'));
expect(root.getByText('Recommission [test_fleet:test_robot]')).toBeTruthy();
expect(root.getByText('Confirm'));
fireEvent.click(root.getByText('Confirm'));
expect(mockRecommission).toHaveBeenCalledOnce();
});
});

0 comments on commit cfe5bab

Please sign in to comment.