Skip to content

Commit

Permalink
test: fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Charlie Drage <charlie@charliedrage.com>
  • Loading branch information
cdrage committed Jan 25, 2024
1 parent 37f8de9 commit 1ab69f0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
10 changes: 9 additions & 1 deletion packages/renderer/src/lib/deployments/DeploymentDetails.spec.ts
Expand Up @@ -18,7 +18,7 @@

import '@testing-library/jest-dom/vitest';
import { test, expect, vi, beforeAll } from 'vitest';
import { fireEvent, render, screen } from '@testing-library/svelte';
import { fireEvent, render, screen, waitFor } from '@testing-library/svelte';

import DeploymentDetails from './DeploymentDetails.svelte';

Expand Down Expand Up @@ -49,6 +49,10 @@ beforeAll(() => {
});

test('Expect redirect to previous page if deployment is deleted', async () => {
const showMessageBoxMock = vi.fn();
(window as any).showMessageBox = showMessageBoxMock;
showMessageBoxMock.mockResolvedValue({ response: 0 });

const routerGotoSpy = vi.spyOn(router, 'goto');
deployments.set([deployment]);

Expand All @@ -71,6 +75,10 @@ test('Expect redirect to previous page if deployment is deleted', async () => {
// click on delete button
const deleteButton = screen.getByRole('button', { name: 'Delete Deployment' });
await fireEvent.click(deleteButton);
expect(showMessageBoxMock).toHaveBeenCalledOnce();

// Wait for confirmation modal to disappear after clicking on delete
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument());

// check that delete method has been called
expect(kubernetesDeleteDeploymentMock).toHaveBeenCalled();
Expand Down
11 changes: 10 additions & 1 deletion packages/renderer/src/lib/service/ServiceDetails.spec.ts
Expand Up @@ -18,7 +18,7 @@

import '@testing-library/jest-dom/vitest';
import { test, expect, vi, beforeAll } from 'vitest';
import { fireEvent, render, screen } from '@testing-library/svelte';
import { fireEvent, render, screen, waitFor } from '@testing-library/svelte';

import ServiceDetails from './ServiceDetails.svelte';

Expand All @@ -43,6 +43,10 @@ beforeAll(() => {
});

test('Expect redirect to previous page if service is deleted', async () => {
const showMessageBoxMock = vi.fn();
(window as any).showMessageBox = showMessageBoxMock;
showMessageBoxMock.mockResolvedValue({ response: 0 });

const routerGotoSpy = vi.spyOn(router, 'goto');
services.set([service]);

Expand All @@ -66,6 +70,11 @@ test('Expect redirect to previous page if service is deleted', async () => {
const deleteButton = screen.getByRole('button', { name: 'Delete Service' });
await fireEvent.click(deleteButton);

expect(showMessageBoxMock).toHaveBeenCalledOnce();

// Wait for confirmation modal to disappear after clicking on delete
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument());

// check that delete method has been called
expect(kubernetesDeleteServiceMock).toHaveBeenCalled();

Expand Down

0 comments on commit 1ab69f0

Please sign in to comment.