-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add banner for promoting GPU enabled machine (#1717)
* feat: add banner for promoting GPU enabled machine Fixes #1582 Signed-off-by: Jeff MAURY <[email protected]>
- Loading branch information
Showing
5 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
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
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
54 changes: 54 additions & 0 deletions
54
packages/frontend/src/lib/notification/GPUEnabledMachine.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,54 @@ | ||
/********************************************************************** | ||
* Copyright (C) 2024 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 { beforeEach, expect, test, vi } from 'vitest'; | ||
import { render, screen } from '@testing-library/svelte'; | ||
import { studioClient } from '/@/utils/client'; | ||
import GPUEnabledMachine from '/@/lib/notification/GPUEnabledMachine.svelte'; | ||
|
||
vi.mock('/@/utils/client', async () => { | ||
return { | ||
studioClient: { | ||
navigateToResources: vi.fn(), | ||
}, | ||
}; | ||
}); | ||
|
||
beforeEach(() => { | ||
vi.resetAllMocks(); | ||
vi.mocked(studioClient.navigateToResources).mockResolvedValue(undefined); | ||
}); | ||
|
||
test('should show navigation to resources', async () => { | ||
render(GPUEnabledMachine); | ||
|
||
const banner = screen.getByLabelText('GPU machine banner'); | ||
expect(banner).toBeInTheDocument(); | ||
const titleDiv = screen.getByLabelText('title'); | ||
expect(titleDiv).toBeInTheDocument(); | ||
expect(titleDiv.textContent).equals('Non GPU enabled machine'); | ||
const descriptionDiv = screen.getByLabelText('description'); | ||
expect(descriptionDiv).toBeInTheDocument(); | ||
expect(descriptionDiv.textContent).equals( | ||
`The selected Podman machine is not GPU enabled. On MacOS, you can run GPU workloads using the krunkit\n environment. Do you want to create a GPU enabled machine ?`, | ||
); | ||
|
||
const btnUpdate = screen.queryByRole('button', { name: 'Create GPU enabled machine' }); | ||
expect(btnUpdate).toBeInTheDocument(); | ||
}); |
31 changes: 31 additions & 0 deletions
31
packages/frontend/src/lib/notification/GPUEnabledMachine.svelte
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,31 @@ | ||
<script lang="ts"> | ||
import Fa from 'svelte-fa'; | ||
import { faTriangleExclamation } from '@fortawesome/free-solid-svg-icons'; | ||
import { Button } from '@podman-desktop/ui-svelte'; | ||
import { studioClient } from '/@/utils/client'; | ||
const actionName = 'Create GPU enabled machine'; | ||
function executeCommand(): void { | ||
studioClient.navigateToResources().catch(err => console.error('Error navigating to resources', err)); | ||
} | ||
</script> | ||
|
||
<div | ||
class="w-full bg-[var(--pd-content-card-bg)] text-[var(--pd-content-card-text)] border-t-[3px] border-amber-500 p-4 mt-5 shadow-inner" | ||
aria-label="GPU machine banner"> | ||
<div class="flex flex-row space-x-3"> | ||
<div class="flex"> | ||
<Fa icon={faTriangleExclamation} class="text-amber-400" /> | ||
</div> | ||
<div class="flex flex-col grow"> | ||
<span class="font-medium" aria-label="title">Non GPU enabled machine</span> | ||
<span aria-label="description" | ||
>The selected Podman machine is not GPU enabled. On MacOS, you can run GPU workloads using the krunkit | ||
environment. Do you want to create a GPU enabled machine ?</span> | ||
</div> | ||
<div class="flex items-center"> | ||
<Button class="grow text-gray-500" on:click={executeCommand} aria-label={actionName}>{actionName}</Button> | ||
</div> | ||
</div> | ||
</div> |
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