Skip to content

Commit

Permalink
fix: [UIE-8194] dbaas maintenance pending updates state should displa…
Browse files Browse the repository at this point in the history
…y when any pending updates are available and disable version upgrade
  • Loading branch information
smans-akamai committed Dec 9, 2024
1 parent 85d62d3 commit febef64
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,19 @@ describe('Database Settings Maintenance', () => {
expect(button).toBeDisabled();
});

it('should enable upgrade version modal button when there are upgrades available', async () => {
it('should disable upgrade version modal button when there are upgrades available, but there are still updates available', async () => {
const database = databaseFactory.build({
engine: 'postgresql',
version: '13',
updates: {
pending: [
{
deadline: null,
description: 'Log configuration options changes required',
planned_for: null,
},
],
},
});

const onReviewUpdates = vi.fn();
Expand All @@ -94,11 +103,17 @@ describe('Database Settings Maintenance', () => {

const button = await findByRole('button', { name: UPGRADE_VERSION });

expect(button).toBeEnabled();
expect(button).toBeDisabled();
});

it('should show review text and modal button when there are updates', async () => {
const database = databaseFactory.build();
it('should enable upgrade version modal button when there are upgrades available, and there are no pending updates', async () => {
const database = databaseFactory.build({
engine: 'postgresql',
version: '13',
updates: {
pending: [],
},
});

const onReviewUpdates = vi.fn();
const onUpgradeVersion = vi.fn();
Expand All @@ -118,6 +133,37 @@ describe('Database Settings Maintenance', () => {
expect(button).toBeEnabled();
});

it('should show review text and modal button when there are updates ', async () => {
const database = databaseFactory.build({
updates: {
pending: [
{
deadline: null,
description: 'Log configuration options changes required',
planned_for: null,
},
],
},
});

const onReviewUpdates = vi.fn();
const onUpgradeVersion = vi.fn();

const { queryByRole } = renderWithTheme(
<DatabaseSettingsMaintenance
databaseEngine={database.engine}
databasePendingUpdates={database.updates.pending}
databaseVersion={database.version}
onReviewUpdates={onReviewUpdates}
onUpgradeVersion={onUpgradeVersion}
/>
);

const button = queryByRole('button', { name: 'Click to review' });

expect(button).toBeInTheDocument();
});

it('should not show review text and modal button when there are no updates', async () => {
const database = databaseFactory.build({
updates: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const DatabaseSettingsMaintenance = (props: Props) => {
<StyledTypography>{engineVersion}</StyledTypography>
<StyledLinkButton
data-testid="upgrade"
disabled={!versions?.length}
disabled={!versions?.length || hasUpdates}
onClick={onUpgradeVersion}
>
Upgrade Version
Expand Down
34 changes: 33 additions & 1 deletion packages/manager/src/features/Databases/utilities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from 'src/factories';
import {
getDatabasesDescription,
hasPendingUpdates,
isDateOutsideBackup,
isDefaultDatabase,
isLegacyDatabase,
Expand All @@ -19,7 +20,12 @@ import {
import { HttpResponse, http, server } from 'src/mocks/testServer';
import { wrapWithTheme } from 'src/utilities/testHelpers';

import type { AccountCapability, Database, Engine } from '@linode/api-v4';
import type {
AccountCapability,
Database,
Engine,
PendingUpdates,
} from '@linode/api-v4';
import type { TimeOption } from 'src/features/Databases/DatabaseDetail/DatabaseBackups/DatabaseBackups';

const setup = (capabilities: AccountCapability[], flags: any) => {
Expand Down Expand Up @@ -419,6 +425,32 @@ describe('getDatabasesDescription', () => {
});
});

describe('hasPendingUpdates', () => {
it('should return false when there are no pending updates provided', () => {
expect(hasPendingUpdates()).toBe(false);
});

it('should return false when pendingUpdates param is undefined', () => {
expect(hasPendingUpdates(undefined)).toBe(false);
});

it('should return false when pending updates is an empty array', () => {
const updates: PendingUpdates[] = [];
expect(hasPendingUpdates(updates)).toBe(false);
});

it('should return true when there are pending updates', () => {
const updates: PendingUpdates[] = [
{
deadline: null,
description: 'Log configuration options changes required',
planned_for: null,
},
];
expect(hasPendingUpdates(updates)).toBe(true);
});
});

describe('isDefaultDatabase', () => {
it('should return true for default platform database', () => {
const db: Database = databaseFactory.build({
Expand Down
4 changes: 1 addition & 3 deletions packages/manager/src/features/Databases/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,7 @@ export const getDatabasesDescription = (
};

export const hasPendingUpdates = (pendingUpdates?: PendingUpdates[]) =>
Boolean(
pendingUpdates?.some((update) => update.deadline || update.planned_for)
);
Boolean(pendingUpdates && pendingUpdates?.length > 0);

export const isDefaultDatabase = (
database: Pick<DatabaseInstance, 'platform'>
Expand Down

0 comments on commit febef64

Please sign in to comment.