From cbf6fa4359050f10bf5e75be320321d926d952c5 Mon Sep 17 00:00:00 2001 From: "Ricardo M." Date: Fri, 19 Jul 2024 16:09:02 -0400 Subject: [PATCH] fix(loadBalancer): Fix loadBalancer breaking change After upgrading Camel to 4.7, the LoadBalancer types where renamed to include the "LoadBalancer" suffix. For instance, `roundRobin` was renamed to `roundRobinLoadBalancer` --- .../loadBalancerConfig.cy.ts | 4 +-- .../loadBalancer/LoadBalancerEditor.test.tsx | 2 +- .../loadBalancer/loadbalancer.service.test.ts | 24 +++++++------- .../Visualization/Canvas/CanvasForm.test.tsx | 10 +++--- .../RuntimeSelector/RuntimeSelector.test.tsx | 2 +- .../src/stubs/TestRuntimeProviderWrapper.tsx | 31 +++---------------- packages/ui/src/stubs/rest-configuration.ts | 2 +- 7 files changed, 28 insertions(+), 47 deletions(-) diff --git a/packages/ui-tests/cypress/e2e/designer/specialStepConfiguration/loadBalancerConfig.cy.ts b/packages/ui-tests/cypress/e2e/designer/specialStepConfiguration/loadBalancerConfig.cy.ts index 0cbd87412..8bc66de2a 100644 --- a/packages/ui-tests/cypress/e2e/designer/specialStepConfiguration/loadBalancerConfig.cy.ts +++ b/packages/ui-tests/cypress/e2e/designer/specialStepConfiguration/loadBalancerConfig.cy.ts @@ -12,7 +12,7 @@ describe('Tests for sidebar loadBalancer step configuration', () => { cy.openStepConfigurationTab('loadBalance'); cy.get('[data-testid="loadbalancer-config-card"] button').click(); - cy.get('[data-testid="loadbalancer-dropdownitem-roundRobin"] button').click(); + cy.get('[data-testid="loadbalancer-dropdownitem-roundRobinLoadBalancer"] button').click(); cy.get('[data-testid="metadata-editor-form-loadbalancer"]') .find('input[data-testid="text-field"]') @@ -41,7 +41,7 @@ describe('Tests for sidebar loadBalancer step configuration', () => { 'description: loadBalancerDescription', 'inheritErrorHandler: true', 'id: testId', - 'roundRobin:', + 'roundRobinLoadBalancer:', 'id: roundRobinId', ]; diff --git a/packages/ui/src/components/Form/loadBalancer/LoadBalancerEditor.test.tsx b/packages/ui/src/components/Form/loadBalancer/LoadBalancerEditor.test.tsx index d6af52f84..179d8a4d6 100644 --- a/packages/ui/src/components/Form/loadBalancer/LoadBalancerEditor.test.tsx +++ b/packages/ui/src/components/Form/loadBalancer/LoadBalancerEditor.test.tsx @@ -52,7 +52,7 @@ describe('LoadBalancerEditor', () => { await act(async () => { fireEvent.click(buttons[0]); }); - const failover = screen.getByTestId('loadbalancer-dropdownitem-failover'); + const failover = screen.getByTestId('loadbalancer-dropdownitem-failoverLoadBalancer'); await act(async () => { fireEvent.click(failover.getElementsByTagName('button')[0]); }); diff --git a/packages/ui/src/components/Form/loadBalancer/loadbalancer.service.test.ts b/packages/ui/src/components/Form/loadBalancer/loadbalancer.service.test.ts index 873b1abac..9360575c4 100644 --- a/packages/ui/src/components/Form/loadBalancer/loadbalancer.service.test.ts +++ b/packages/ui/src/components/Form/loadBalancer/loadbalancer.service.test.ts @@ -15,8 +15,8 @@ describe('LoadBalancerService', () => { describe('getLoadBalancerMap', () => { it('should return LoadBalancer map', () => { const loadBalancerMap = LoadBalancerService.getLoadBalancerMap(); - expect(loadBalancerMap.failover.model.title).toEqual('Failover'); - expect(loadBalancerMap.sticky.propertiesSchema.properties!.correlationExpression[`$comment`]).toEqual( + expect(loadBalancerMap.failoverLoadBalancer.model.title).toEqual('Failover Load Balancer'); + expect(loadBalancerMap.stickyLoadBalancer.propertiesSchema.properties!.correlationExpression[`$comment`]).toEqual( 'expression', ); expect(loadBalancerMap.customLoadBalancer.model.description).toContain('custom load balancer'); @@ -27,7 +27,7 @@ describe('LoadBalancerService', () => { describe('getLoadBalancerSchema', () => { it('should return LoadBalancer schema', () => { const loadBalancerMap = LoadBalancerService.getLoadBalancerMap(); - const jsonSchema = LoadBalancerService.getLoadBalancerSchema(loadBalancerMap.roundRobin); + const jsonSchema = LoadBalancerService.getLoadBalancerSchema(loadBalancerMap.roundRobinLoadBalancer); expect(jsonSchema!.properties!.id.type).toBe('string'); const customSchema = LoadBalancerService.getLoadBalancerSchema(loadBalancerMap.customLoadBalancer); expect(customSchema!.properties!.ref.type).toBe('string'); @@ -42,9 +42,9 @@ describe('LoadBalancerService', () => { it('should parse #1', () => { const { loadBalancer: loadBalancer, model } = LoadBalancerService.parseLoadBalancerModel(loadBalancerMap, { - roundRobin: { id: 'myRoundRobin' }, + roundRobinLoadBalancer: { id: 'myRoundRobin' }, }); - expect(loadBalancer).toEqual(loadBalancerMap.roundRobin); + expect(loadBalancer).toEqual(loadBalancerMap.roundRobinLoadBalancer); expect(model).toEqual({ id: 'myRoundRobin' }); }); @@ -70,18 +70,20 @@ describe('LoadBalancerService', () => { it('should write loadbalancer', () => { /* eslint-disable @typescript-eslint/no-explicit-any */ const parentModel: any = {}; - LoadBalancerService.setLoadBalancerModel(loadBalancerMap, parentModel, 'failover', { roundRobin: true }); - expect(parentModel.failover.roundRobin).toEqual(true); + LoadBalancerService.setLoadBalancerModel(loadBalancerMap, parentModel, 'failoverLoadBalancer', { + roundRobin: true, + }); + expect(parentModel.failoverLoadBalancer.roundRobin).toEqual(true); }); it('should write loadbalancer and remove existing', () => { /* eslint-disable @typescript-eslint/no-explicit-any */ - const parentModel: any = { failover: { roundRobin: true } }; - LoadBalancerService.setLoadBalancerModel(loadBalancerMap, parentModel, 'roundRobin', { + const parentModel: any = { failoverLoadBalancer: { roundRobin: true } }; + LoadBalancerService.setLoadBalancerModel(loadBalancerMap, parentModel, 'roundRobinLoadBalancer', { id: 'myRoundRobin', }); - expect(parentModel.failover).toBeUndefined(); - expect(parentModel.roundRobin.id).toEqual('myRoundRobin'); + expect(parentModel.failoverLoadBalancer).toBeUndefined(); + expect(parentModel.roundRobinLoadBalancer.id).toEqual('myRoundRobin'); }); it('should not write if empty', () => { diff --git a/packages/ui/src/components/Visualization/Canvas/CanvasForm.test.tsx b/packages/ui/src/components/Visualization/Canvas/CanvasForm.test.tsx index 3f5340cf5..ea30cc14c 100644 --- a/packages/ui/src/components/Visualization/Canvas/CanvasForm.test.tsx +++ b/packages/ui/src/components/Visualization/Canvas/CanvasForm.test.tsx @@ -550,18 +550,18 @@ describe('CanvasForm', () => { await act(async () => { fireEvent.click(button[0]); }); - const avro = screen.getByTestId('loadbalancer-dropdownitem-weighted'); + const avro = screen.getByTestId('loadbalancer-dropdownitem-weightedLoadBalancer'); await act(async () => { fireEvent.click(avro.getElementsByTagName('button')[0]); }); - expect(camelRoute.from.steps[0].loadBalance!.weighted).toBeDefined(); + expect(camelRoute.from.steps[0].loadBalance!.weightedLoadBalancer).toBeDefined(); expect(camelRoute.from.steps[0].loadBalance!.id).toEqual('lb'); const idInput = screen.getAllByRole('textbox').filter((textbox) => textbox.getAttribute('label') === 'Id'); await act(async () => { fireEvent.input(idInput[1], { target: { value: 'modified' } }); }); - expect(camelRoute.from.steps[0].loadBalance!.weighted).toBeDefined(); + expect(camelRoute.from.steps[0].loadBalance!.weightedLoadBalancer).toBeDefined(); expect(camelRoute.from.steps[0].loadBalance!.id).toEqual('modified'); }); @@ -607,11 +607,11 @@ describe('CanvasForm', () => { await act(async () => { fireEvent.click(button[0]); }); - const avro = screen.getByTestId('loadbalancer-dropdownitem-weighted'); + const avro = screen.getByTestId('loadbalancer-dropdownitem-weightedLoadBalancer'); await act(async () => { fireEvent.click(avro.getElementsByTagName('button')[0]); }); - expect(camelRoute.from.steps[0].loadBalance!.weighted).toBeDefined(); + expect(camelRoute.from.steps[0].loadBalance!.weightedLoadBalancer).toBeDefined(); expect(camelRoute.from.steps[0].loadBalance!.id).toEqual('modified'); }); }); diff --git a/packages/ui/src/components/Visualization/ContextToolbar/RuntimeSelector/RuntimeSelector.test.tsx b/packages/ui/src/components/Visualization/ContextToolbar/RuntimeSelector/RuntimeSelector.test.tsx index af51b6b5a..254edf7c8 100644 --- a/packages/ui/src/components/Visualization/ContextToolbar/RuntimeSelector/RuntimeSelector.test.tsx +++ b/packages/ui/src/components/Visualization/ContextToolbar/RuntimeSelector/RuntimeSelector.test.tsx @@ -37,7 +37,7 @@ describe('RuntimeSelector', () => { }); /** Click on first element */ - const element = await wrapper.findByRole('menuitem'); + const [element] = await wrapper.findAllByRole('menuitem'); await act(async () => { fireEvent.mouseEnter(element); fireEvent.click(element); diff --git a/packages/ui/src/stubs/TestRuntimeProviderWrapper.tsx b/packages/ui/src/stubs/TestRuntimeProviderWrapper.tsx index 575af3616..5ddc99a3a 100644 --- a/packages/ui/src/stubs/TestRuntimeProviderWrapper.tsx +++ b/packages/ui/src/stubs/TestRuntimeProviderWrapper.tsx @@ -1,3 +1,4 @@ +import catalogLibrary from '@kaoto/camel-catalog/index.json'; import { CatalogLibrary } from '@kaoto/camel-catalog/types'; import { FunctionComponent, PropsWithChildren } from 'react'; import { IRuntimeContext, RuntimeContext } from '../providers/runtime.provider'; @@ -8,31 +9,9 @@ interface TestRuntimeProviderWrapperResult extends IRuntimeContext { } export const TestRuntimeProviderWrapper = (): TestRuntimeProviderWrapperResult => { + const catalogLibraryCasted = catalogLibrary as CatalogLibrary; const basePath = CatalogSchemaLoader.DEFAULT_CATALOG_PATH; - const catalogLibrary: CatalogLibrary = { - name: 'Default Kaoto catalog', - definitions: [ - { - name: 'Camel Main 4.6.0', - version: '4.6.0', - runtime: 'Main', - fileName: 'camel-main/4.6.0/index-4eebd78f619ebc595d6ee2aecd066049.json', - }, - { - name: 'Camel Quarkus 3.8.0', - version: '3.8.0', - runtime: 'Quarkus', - fileName: 'camel-quarkus/3.8.0/index-4299a1eb1d45433b7f6362b514210370.json', - }, - { - name: 'Camel SpringBoot 4.6.0', - version: '4.6.0', - runtime: 'SpringBoot', - fileName: 'camel-springboot/4.6.0/index-630d8399b32380f6a533bf97f5203eaf.json', - }, - ], - }; - const selectedCatalog = catalogLibrary.definitions[0]; + const selectedCatalog = catalogLibraryCasted.definitions[0]; const setSelectedCatalog = jest.fn(); const Provider: FunctionComponent = (props) => ( @@ -40,7 +19,7 @@ export const TestRuntimeProviderWrapper = (): TestRuntimeProviderWrapperResult = key={Date.now()} value={{ basePath, - catalogLibrary, + catalogLibrary: catalogLibraryCasted, selectedCatalog, setSelectedCatalog, }} @@ -49,5 +28,5 @@ export const TestRuntimeProviderWrapper = (): TestRuntimeProviderWrapperResult = ); - return { Provider, basePath, catalogLibrary, selectedCatalog, setSelectedCatalog }; + return { Provider, basePath, catalogLibrary: catalogLibraryCasted, selectedCatalog, setSelectedCatalog }; }; diff --git a/packages/ui/src/stubs/rest-configuration.ts b/packages/ui/src/stubs/rest-configuration.ts index f5c89a869..f8a91d477 100644 --- a/packages/ui/src/stubs/rest-configuration.ts +++ b/packages/ui/src/stubs/rest-configuration.ts @@ -105,7 +105,7 @@ export const restConfigurationSchema: KaotoSchemaDefinition['schema'] = { description: 'If no hostname has been explicit configured, then this resolver is used to compute the hostname the REST service will be using.', default: 'allLocalIp', - enum: ['allLocalIp', 'localHostName', 'localIp'], + enum: ['allLocalIp', 'localHostName', 'localIp', 'none'], }, bindingMode: { type: 'string',