Skip to content

fix(KFLUXBUGS-1751): release status replies on status and reason of the release type #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/Releases/__tests__/ReleaseOverviewTab.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { render, screen } from '@testing-library/react';
import { createK8sWatchResourceMock, createUseWorkspaceInfoMock } from '../../../utils/test-utils';
import { mockReleases, mockReleaseWithManagedProcessing } from '../__data__/mock-release-data';
import { mockReleases } from '../__data__/mock-release-data';
import ReleaseOverviewTab from '../ReleaseOverviewTab';

jest.mock('react-router-dom', () => ({
Expand Down Expand Up @@ -57,7 +57,7 @@ describe('ReleaseOverviewTab', () => {
});

it('should render correct details if managedProcessing', () => {
render(<ReleaseOverviewTab release={mockReleaseWithManagedProcessing} />);
render(<ReleaseOverviewTab />);
expect(screen.getByText('Pipeline Run')).toBeVisible();
expect(screen.getByRole('link', { name: 'test-pipelinerun' }).getAttribute('href')).toBe(
'/workspaces/target-ws/applications/test-app/pipelineruns/test-pipelinerun',
Expand Down
2 changes: 2 additions & 0 deletions src/components/Releases/__tests__/ReleasesListRow.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { render } from '@testing-library/react';
import { ReleaseCondition } from '../../../types';
import ReleasesListRow from '../ReleasesListRow';

jest.mock('react-router-dom', () => ({
Expand All @@ -21,6 +22,7 @@ const mockRelease = {
{
reason: 'Succeeded',
status: 'True',
type: ReleaseCondition.Released,
},
],
},
Expand Down
22 changes: 11 additions & 11 deletions src/hooks/__tests__/useReleaseStatus.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { renderHook } from '@testing-library/react-hooks';
import { ReleaseCondition } from '../../types';
import { useReleaseStatus } from '../useReleaseStatus';

const mockRelease = {
Expand All @@ -19,46 +20,45 @@ describe('useApplicationSnapshots', () => {
expect(result.current).toEqual('Unknown');
});

it('should return in progress if any of the conditions is progressing', () => {
it('should return in progress if release condition is progressing', () => {
const { result } = renderHook(() =>
useReleaseStatus({
...mockRelease,
status: {
conditions: [
{ reason: 'Progressing' },
{ reason: 'Succeeded', status: 'True' },
{ reason: 'Failed', status: 'False' },
{ reason: 'Succeeded', status: 'True', type: ReleaseCondition.Validated },
{ reason: 'Progressing', status: 'True', type: ReleaseCondition.Released },
],
},
}),
);
expect(result.current).toEqual('In Progress');
});

it('should return in succeeded if all of the conditions pass', () => {
it('should return in succeeded if release condition pass', () => {
const { result } = renderHook(() =>
useReleaseStatus({
...mockRelease,
status: {
conditions: [
{ reason: 'Succeeded', status: 'True' },
{ reason: 'Succeeded', status: 'True' },
{ reason: 'Succeeded', status: 'True', type: ReleaseCondition.Released },
{ reason: 'Progressing', status: 'True', type: ReleaseCondition.Validated },
],
},
}),
);
expect(result.current).toEqual('Succeeded');
});

it('should return in failed if any of the conditions fail', () => {
it('should return in failed if release condition is fail', () => {
const { result } = renderHook(() =>
useReleaseStatus({
...mockRelease,
status: {
conditions: [
{ reason: 'Succeeded', status: 'True' },
{ reason: 'Succeeded', status: 'True' },
{ reason: 'Failed', status: 'False' },
{ reason: 'Succeeded', status: 'True', type: ReleaseCondition.Processed },
{ reason: 'Succeeded', status: 'True', type: ReleaseCondition.Validated },
{ reason: 'Failed', status: 'False', type: ReleaseCondition.Released },
],
},
}),
Expand Down
22 changes: 11 additions & 11 deletions src/hooks/useReleaseStatus.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { ReleaseKind } from '../types';
import { ReleaseCondition, ReleaseKind } from '../types';
import { runStatus } from '../utils/pipeline-utils';

export const useReleaseStatus = (release: ReleaseKind) => {
Expand All @@ -8,21 +8,21 @@ export const useReleaseStatus = (release: ReleaseKind) => {
return runStatus.Unknown;
}

const progressing = release.status.conditions.some((c) => c.reason === 'Progressing');
if (progressing) {
return runStatus['In Progress'];
}

const succeeded = release.status.conditions.every(
(c) => c.reason === 'Succeeded' && c.status === 'True',
const releasedCondition = release.status.conditions.find(
(c) => c.type === ReleaseCondition.Released,
);

const succeeded =
releasedCondition.status === 'True' && releasedCondition.reason === 'Succeeded';
if (succeeded) {
return runStatus.Succeeded;
}
const progressing = releasedCondition.reason === 'Progressing';
if (progressing) {
return runStatus['In Progress'];
}

const failed = release.status.conditions.some(
(c) => c.reason === 'Failed' && c.status === 'False',
);
const failed = releasedCondition.reason === 'Failed' && releasedCondition.status === 'False';
if (failed) {
return runStatus.Failed;
}
Expand Down
Loading