From febef64201badda07531b185672cb47dc5c42bd7 Mon Sep 17 00:00:00 2001 From: Sam Mans Date: Thu, 5 Dec 2024 15:20:13 -0500 Subject: [PATCH] fix: [UIE-8194] dbaas maintenance pending updates state should display when any pending updates are available and disable version upgrade --- .../DatabaseSettingsMaintenance.test.tsx | 54 +++++++++++++++++-- .../DatabaseSettingsMaintenance.tsx | 2 +- .../src/features/Databases/utilities.test.ts | 34 +++++++++++- .../src/features/Databases/utilities.ts | 4 +- 4 files changed, 85 insertions(+), 9 deletions(-) diff --git a/packages/manager/src/features/Databases/DatabaseDetail/DatabaseSettings/DatabaseSettingsMaintenance.test.tsx b/packages/manager/src/features/Databases/DatabaseDetail/DatabaseSettings/DatabaseSettingsMaintenance.test.tsx index 2672c02b16d..336b5b53d3a 100644 --- a/packages/manager/src/features/Databases/DatabaseDetail/DatabaseSettings/DatabaseSettingsMaintenance.test.tsx +++ b/packages/manager/src/features/Databases/DatabaseDetail/DatabaseSettings/DatabaseSettingsMaintenance.test.tsx @@ -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(); @@ -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(); @@ -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( + + ); + + 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: { diff --git a/packages/manager/src/features/Databases/DatabaseDetail/DatabaseSettings/DatabaseSettingsMaintenance.tsx b/packages/manager/src/features/Databases/DatabaseDetail/DatabaseSettings/DatabaseSettingsMaintenance.tsx index 2572ee3d9f5..8d766787413 100644 --- a/packages/manager/src/features/Databases/DatabaseDetail/DatabaseSettings/DatabaseSettingsMaintenance.tsx +++ b/packages/manager/src/features/Databases/DatabaseDetail/DatabaseSettings/DatabaseSettingsMaintenance.tsx @@ -40,7 +40,7 @@ export const DatabaseSettingsMaintenance = (props: Props) => { {engineVersion} Upgrade Version diff --git a/packages/manager/src/features/Databases/utilities.test.ts b/packages/manager/src/features/Databases/utilities.test.ts index 468c2702039..216b7867e1a 100644 --- a/packages/manager/src/features/Databases/utilities.test.ts +++ b/packages/manager/src/features/Databases/utilities.test.ts @@ -8,6 +8,7 @@ import { } from 'src/factories'; import { getDatabasesDescription, + hasPendingUpdates, isDateOutsideBackup, isDefaultDatabase, isLegacyDatabase, @@ -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) => { @@ -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({ diff --git a/packages/manager/src/features/Databases/utilities.ts b/packages/manager/src/features/Databases/utilities.ts index 217ab155cda..db26bf086cd 100644 --- a/packages/manager/src/features/Databases/utilities.ts +++ b/packages/manager/src/features/Databases/utilities.ts @@ -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