forked from podman-desktop/podman-desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for container and compose actions. Signed-off-by: Tim deBoer <[email protected]>
- Loading branch information
1 parent
008cc0f
commit 183f243
Showing
3 changed files
with
215 additions
and
2 deletions.
There are no files selected for viewing
118 changes: 118 additions & 0 deletions
118
packages/renderer/src/lib/compose/ComposeActions.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/********************************************************************** | ||
* Copyright (C) 2023 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
***********************************************************************/ | ||
|
||
import '@testing-library/jest-dom/vitest'; | ||
import { test, expect, vi, beforeEach, afterEach } from 'vitest'; | ||
import { fireEvent, render, screen } from '@testing-library/svelte'; | ||
import ComposeActions from './ComposeActions.svelte'; | ||
import type { ComposeInfoUI } from './ComposeInfoUI'; | ||
import type { ContainerInfoUI } from '../container/ContainerInfoUI'; | ||
|
||
const compose: ComposeInfoUI = { | ||
engineId: 'podman', | ||
engineType: 'podman', | ||
name: 'my-compose-group', | ||
status: 'STOPPED', | ||
actionInProgress: false, | ||
actionError: undefined, | ||
containers: [ | ||
{ | ||
actionInProgress: false, | ||
actionError: undefined, | ||
state: 'STOPPED', | ||
} as ContainerInfoUI, | ||
], | ||
} as ComposeInfoUI; | ||
|
||
const getContributedMenusMock = vi.fn(); | ||
const updateMock = vi.fn(); | ||
|
||
beforeEach(() => { | ||
(window as any).startContainersByLabel = vi.fn(); | ||
(window as any).stopContainersByLabel = vi.fn(); | ||
(window as any).restartContainersByLabel = vi.fn(); | ||
(window as any).deleteContainersByLabel = vi.fn(); | ||
|
||
(window as any).getContributedMenus = getContributedMenusMock; | ||
getContributedMenusMock.mockImplementation(() => Promise.resolve([])); | ||
}); | ||
|
||
afterEach(() => { | ||
vi.resetAllMocks(); | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
test('Expect no error and status starting compose', async () => { | ||
const { component } = render(ComposeActions, { compose }); | ||
component.$on('update', updateMock); | ||
|
||
// click on start button | ||
const startButton = screen.getByRole('button', { name: 'Start Compose' }); | ||
await fireEvent.click(startButton); | ||
|
||
expect(compose.status).toEqual('STARTING'); | ||
expect(compose.actionError).toEqual(''); | ||
expect(compose.containers[0].state).toEqual('STARTING'); | ||
expect(compose.containers[0].actionError).toEqual(''); | ||
expect(updateMock).toHaveBeenCalled(); | ||
}); | ||
|
||
test('Expect no error and status stopping compose', async () => { | ||
const { component } = render(ComposeActions, { compose }); | ||
component.$on('update', updateMock); | ||
|
||
// click on stop button | ||
const stopButton = screen.getByRole('button', { name: 'Stop Compose' }); | ||
await fireEvent.click(stopButton); | ||
|
||
expect(compose.status).toEqual('STOPPING'); | ||
expect(compose.actionError).toEqual(''); | ||
expect(compose.containers[0].state).toEqual('STOPPING'); | ||
expect(compose.containers[0].actionError).toEqual(''); | ||
expect(updateMock).toHaveBeenCalled(); | ||
}); | ||
|
||
test('Expect no error and status restarting compose', async () => { | ||
const { component } = render(ComposeActions, { compose }); | ||
component.$on('update', updateMock); | ||
|
||
// click on restart button | ||
const restartButton = screen.getByRole('button', { name: 'Restart Compose' }); | ||
await fireEvent.click(restartButton); | ||
|
||
expect(compose.status).toEqual('RESTARTING'); | ||
expect(compose.actionError).toEqual(''); | ||
expect(compose.containers[0].state).toEqual('RESTARTING'); | ||
expect(compose.containers[0].actionError).toEqual(''); | ||
expect(updateMock).toHaveBeenCalled(); | ||
}); | ||
|
||
test('Expect no error and status deleting compose', async () => { | ||
const { component } = render(ComposeActions, { compose }); | ||
component.$on('update', updateMock); | ||
|
||
// click on delete button | ||
const deleteButton = screen.getByRole('button', { name: 'Delete Compose' }); | ||
await fireEvent.click(deleteButton); | ||
|
||
expect(compose.status).toEqual('DELETING'); | ||
expect(compose.actionError).toEqual(''); | ||
expect(compose.containers[0].state).toEqual('DELETING'); | ||
expect(compose.containers[0].actionError).toEqual(''); | ||
expect(updateMock).toHaveBeenCalled(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
packages/renderer/src/lib/container/ContainerActions.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/********************************************************************** | ||
* Copyright (C) 2023 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
***********************************************************************/ | ||
|
||
import '@testing-library/jest-dom/vitest'; | ||
import { test, expect, vi, beforeEach, afterEach } from 'vitest'; | ||
import { fireEvent, render, screen } from '@testing-library/svelte'; | ||
import ContainerActions from './ContainerActions.svelte'; | ||
import type { ContainerInfoUI } from './ContainerInfoUI'; | ||
|
||
const container: ContainerInfoUI = {} as ContainerInfoUI; | ||
|
||
const getContributedMenusMock = vi.fn(); | ||
const updateMock = vi.fn(); | ||
|
||
beforeEach(() => { | ||
(window as any).startContainer = vi.fn(); | ||
(window as any).stopContainer = vi.fn(); | ||
(window as any).restartContainer = vi.fn(); | ||
(window as any).deleteContainer = vi.fn(); | ||
|
||
(window as any).getContributedMenus = getContributedMenusMock; | ||
getContributedMenusMock.mockImplementation(() => Promise.resolve([])); | ||
}); | ||
|
||
afterEach(() => { | ||
vi.resetAllMocks(); | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
test('Expect no error and status starting container', async () => { | ||
const { component } = render(ContainerActions, { container }); | ||
component.$on('update', updateMock); | ||
|
||
// click on start button | ||
const startButton = screen.getByRole('button', { name: 'Start Container' }); | ||
await fireEvent.click(startButton); | ||
|
||
expect(container.state).toEqual('STARTING'); | ||
expect(container.actionError).toEqual(''); | ||
expect(updateMock).toHaveBeenCalled(); | ||
}); | ||
|
||
test('Expect no error and status stopping container', async () => { | ||
const { component } = render(ContainerActions, { container }); | ||
component.$on('update', updateMock); | ||
|
||
// click on stop button | ||
const stopButton = screen.getByRole('button', { name: 'Stop Container' }); | ||
await fireEvent.click(stopButton); | ||
|
||
expect(container.state).toEqual('STOPPING'); | ||
expect(container.actionError).toEqual(''); | ||
expect(updateMock).toHaveBeenCalled(); | ||
}); | ||
|
||
test('Expect no error and status restarting container', async () => { | ||
const { component } = render(ContainerActions, { container }); | ||
component.$on('update', updateMock); | ||
|
||
// click on restart button | ||
const restartButton = screen.getByRole('button', { name: 'Restart Container' }); | ||
await fireEvent.click(restartButton); | ||
|
||
expect(container.state).toEqual('RESTARTING'); | ||
expect(container.actionError).toEqual(''); | ||
expect(updateMock).toHaveBeenCalled(); | ||
}); | ||
|
||
test('Expect no error and status deleting container', async () => { | ||
const { component } = render(ContainerActions, { container }); | ||
component.$on('update', updateMock); | ||
|
||
// click on delete button | ||
const deleteButton = screen.getByRole('button', { name: 'Delete Container' }); | ||
await fireEvent.click(deleteButton); | ||
|
||
expect(container.state).toEqual('DELETING'); | ||
expect(container.actionError).toEqual(''); | ||
expect(updateMock).toHaveBeenCalled(); | ||
}); |