Skip to content

Commit

Permalink
fix(loadBalancer): Fix loadBalancer breaking change
Browse files Browse the repository at this point in the history
After upgrading Camel to 4.7, the LoadBalancer types where renamed to
include the "LoadBalancer" suffix.

For instance, `roundRobin` was renamed to `roundRobinLoadBalancer`
  • Loading branch information
lordrip committed Jul 19, 2024
1 parent 46877ec commit cbf6fa4
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"]')
Expand Down Expand Up @@ -41,7 +41,7 @@ describe('Tests for sidebar loadBalancer step configuration', () => {
'description: loadBalancerDescription',
'inheritErrorHandler: true',
'id: testId',
'roundRobin:',
'roundRobinLoadBalancer:',
'id: roundRobinId',
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
Expand All @@ -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' });
});

Expand All @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

Expand Down Expand Up @@ -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');
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
31 changes: 5 additions & 26 deletions packages/ui/src/stubs/TestRuntimeProviderWrapper.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -8,39 +9,17 @@ 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<PropsWithChildren> = (props) => (
<RuntimeContext.Provider
key={Date.now()}
value={{
basePath,
catalogLibrary,
catalogLibrary: catalogLibraryCasted,
selectedCatalog,
setSelectedCatalog,
}}
Expand All @@ -49,5 +28,5 @@ export const TestRuntimeProviderWrapper = (): TestRuntimeProviderWrapperResult =
</RuntimeContext.Provider>
);

return { Provider, basePath, catalogLibrary, selectedCatalog, setSelectedCatalog };
return { Provider, basePath, catalogLibrary: catalogLibraryCasted, selectedCatalog, setSelectedCatalog };
};
2 changes: 1 addition & 1 deletion packages/ui/src/stubs/rest-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit cbf6fa4

Please sign in to comment.