diff --git a/packages/renderer/src/lib/deployments/DeploymentColumnConditions.spec.ts b/packages/renderer/src/lib/deployments/DeploymentColumnConditions.spec.ts index b2f8b7b756134..377e35fe3b5ae 100644 --- a/packages/renderer/src/lib/deployments/DeploymentColumnConditions.spec.ts +++ b/packages/renderer/src/lib/deployments/DeploymentColumnConditions.spec.ts @@ -1,5 +1,5 @@ /********************************************************************** - * Copyright (C) 2023 Red Hat, Inc. + * Copyright (C) 2023-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. @@ -22,26 +22,25 @@ import { render, screen } from '@testing-library/svelte'; import { expect, test } from 'vitest'; import DeploymentColumnConditions from './DeploymentColumnConditions.svelte'; -import type { DeploymentUI } from './DeploymentUI'; - -const deployment: DeploymentUI = { - name: 'my-deployment', - status: '', - namespace: '', - replicas: 0, - ready: 0, - selected: false, - conditions: [ - { type: 'Available', message: 'Running fine' }, - { type: 'ReplicaFailure', message: 'It failed!' }, - { type: 'Progressing', message: 'Working on it' }, - ], -}; +import type { DeploymentCondition } from './DeploymentUI'; + +function createDeploymentUI(conditions: DeploymentCondition[]) { + return { + name: 'my-deployment', + status: '', + namespace: '', + replicas: 0, + ready: 0, + selected: false, + conditions: conditions, + }; +} test('Expect column styling available', async () => { + const deployment = createDeploymentUI([{ type: 'Available', message: 'Running fine' }]); render(DeploymentColumnConditions, { object: deployment }); - const text = screen.getByText(deployment.conditions[0].type); + const text = screen.getByText('Available'); expect(text).toBeInTheDocument(); expect(text).toHaveClass('text-gray-500'); @@ -51,9 +50,10 @@ test('Expect column styling available', async () => { }); test('Expect column styling failure', async () => { + const deployment = createDeploymentUI([{ type: 'ReplicaFailure', message: 'It failed!' }]); render(DeploymentColumnConditions, { object: deployment }); - const text = screen.getByText(deployment.conditions[1].type); + const text = screen.getByText('ReplicaFailure'); expect(text).toBeInTheDocument(); expect(text).toHaveClass('text-gray-500'); @@ -63,9 +63,25 @@ test('Expect column styling failure', async () => { }); test('Expect column styling progressing', async () => { + const deployment = createDeploymentUI([{ type: 'Progressing', message: 'Working on it', reason: '' }]); + render(DeploymentColumnConditions, { object: deployment }); + + const text = screen.getByText('Progressing'); + expect(text).toBeInTheDocument(); + expect(text).toHaveClass('text-gray-500'); + + const dot = text.parentElement?.children[0].children[0]; + expect(dot).toBeInTheDocument(); + expect(dot).toHaveClass('text-sky-400'); +}); + +test('Expect column styling progressed', async () => { + const deployment = createDeploymentUI([ + { type: 'Progressing', message: 'Successfully progressed', reason: 'NewReplicaSetAvailable' }, + ]); render(DeploymentColumnConditions, { object: deployment }); - const text = screen.getByText(deployment.conditions[2].type); + const text = screen.getByText('Progressed'); expect(text).toBeInTheDocument(); expect(text).toHaveClass('text-gray-500'); diff --git a/packages/renderer/src/lib/deployments/DeploymentColumnConditions.svelte b/packages/renderer/src/lib/deployments/DeploymentColumnConditions.svelte index 617bbc8240580..657a7e4ac86bf 100644 --- a/packages/renderer/src/lib/deployments/DeploymentColumnConditions.svelte +++ b/packages/renderer/src/lib/deployments/DeploymentColumnConditions.svelte @@ -3,25 +3,31 @@ import { faCheckCircle, faExclamationTriangle, faQuestionCircle, faSync } from ' import { Tooltip } from '@podman-desktop/ui-svelte'; import Fa from 'svelte-fa'; -import type { DeploymentUI } from './DeploymentUI'; +import type { DeploymentCondition, DeploymentUI } from './DeploymentUI'; export let object: DeploymentUI; // Determine both the icon and color based on the deployment condition -function getConditionAttributes(type: string) { - switch (type) { +function getConditionAttributes(condition: DeploymentCondition) { + let name = condition.type; + switch (condition.type) { case 'Available': // faCheckCircle: Indicates a successful state, typically used to denote availability and operational readiness - return { color: 'text-green-600', icon: faCheckCircle }; + return { color: 'text-green-600', icon: faCheckCircle, name }; case 'Progressing': // faSync: Often used to represent ongoing processes or operations, fitting for a "Progressing" state - return { color: 'text-sky-400', icon: faSync }; + // If reason has NewReplicaSetAvailable then it's progressed + if (condition.reason === 'NewReplicaSetAvailable') { + name = 'Progressed'; + } + + return { color: 'text-sky-400', icon: faSync, name }; case 'ReplicaFailure': // faExclamationTriangle: Alerts and warnings - return { color: 'text-amber-600', icon: faExclamationTriangle }; + return { color: 'text-amber-600', icon: faExclamationTriangle, name }; default: // faQuestionCircle: Uncertain / unknown - return { color: 'text-gray-900', icon: faQuestionCircle }; + return { color: 'text-gray-900', icon: faQuestionCircle, name }; } } @@ -33,9 +39,9 @@ function getConditionAttributes(type: string) {