Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

fix: [VS Code] Modifying beans is not marking editor dirty #2143

Merged
merged 2 commits into from
Jul 14, 2023
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
39 changes: 39 additions & 0 deletions src/kogito-integration/KogitoEditorIntegrationProvider.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { camelRouteMultiYaml } from '../stubs/source-code';
import { KogitoEditorIntegrationProvider } from './KogitoEditorIntegrationProvider';
import { fetchIntegrationSourceCode } from '@kaoto/api';
import { useFlowsStore } from '@kaoto/store';
import { act, render, screen } from '@testing-library/react';

describe('KogitoEditorIntegrationProvider', () => {
beforeEach(() => {
useFlowsStore.getState().deleteAllFlows();
useFlowsStore.getState().addNewFlow('Integration');
});

afterAll(() => {
jest.restoreAllMocks();
});

test('detects metadata update', async () => {
const sourceCode = camelRouteMultiYaml;
(fetchIntegrationSourceCode as jest.Mock).mockResolvedValue(sourceCode);
const onReady = jest.fn();
const onContentChanged = jest.fn();
render(
<KogitoEditorIntegrationProvider
children={<>keip-test</>}
content={sourceCode}
contentPath={''}
onContentChanged={onContentChanged}
onReady={onReady}
></KogitoEditorIntegrationProvider>,
);
const text = screen.getByText('keip-test');
expect(text).toHaveTextContent('keip-test');
expect(onContentChanged.mock.calls.length).toBe(0);
await act(() =>
useFlowsStore.getState().setMetadata('beans', [{ name: 'testBean', type: 'testBeanType' }]),
);
expect(onContentChanged.mock.calls.length).toBe(1);
});
});
10 changes: 8 additions & 2 deletions src/kogito-integration/KogitoEditorIntegrationProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,13 @@ function KogitoEditorIntegrationProviderInternal(
useCancelableEffect(
useCallback(
({ canceled }) => {
if (!flows || isEqual(previousFlowWrapper.current.flows, flows)) return;
if (
!flows ||
(isEqual(previousFlowWrapper.current.flows, flows) &&
isEqual(previousFlowWrapper.current.properties, properties) &&
isEqual(previousFlowWrapper.current.metadata, metadata))
)
return;

const updatedFlowWrapper: IFlowsWrapper = {
flows: flows.map((flow) => ({
Expand Down Expand Up @@ -170,7 +176,7 @@ function KogitoEditorIntegrationProviderInternal(
}
});
},
[flows],
[flows, properties, metadata],
),
);

Expand Down
19 changes: 19 additions & 0 deletions src/stubs/source-code.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export const camelRouteMultiYaml = `
- route:
id: camel route 1
from:
uri: timer:test
steps:
- set-header:
constant: test
name: test
- to:
uri: log:test
- route:
id: camel route 2
from:
uri: 'activemq:queue:'
steps:
- to:
uri: 'activemq:queue:'
`;