chore: fix tests after changing allowed emotions

This commit is contained in:
Twirre Meulenbelt
2026-01-27 17:44:02 +01:00
parent 1708a02b8f
commit 618bbd3356

View File

@@ -2,7 +2,7 @@
import { describe, it, beforeEach } from '@jest/globals'; import { describe, it, beforeEach } from '@jest/globals';
import { screen, waitFor } from '@testing-library/react'; import { screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event'; import userEvent from '@testing-library/user-event';
import { renderWithProviders } from '../.././/./../../test-utils/test-utils'; import { renderWithProviders } from '../../../../test-utils/test-utils.tsx';
import BasicBeliefNode, { type BasicBeliefNodeData } from '../../../../../src/pages/VisProgPage/visualProgrammingUI/nodes/BasicBeliefNode.tsx'; import BasicBeliefNode, { type BasicBeliefNodeData } from '../../../../../src/pages/VisProgPage/visualProgrammingUI/nodes/BasicBeliefNode.tsx';
import useFlowStore from '../../../../../src/pages/VisProgPage/visualProgrammingUI/VisProgStores'; import useFlowStore from '../../../../../src/pages/VisProgPage/visualProgrammingUI/VisProgStores';
import type { Node } from '@xyflow/react'; import type { Node } from '@xyflow/react';
@@ -150,7 +150,7 @@ describe('BasicBeliefNode', () => {
expect(screen.getByDisplayValue('Emotion recognised:')).toBeInTheDocument(); expect(screen.getByDisplayValue('Emotion recognised:')).toBeInTheDocument();
// For emotion type, we should check that the select has the correct value selected // For emotion type, we should check that the select has the correct value selected
const selectElement = screen.getByDisplayValue('Happy'); const selectElement = screen.getByDisplayValue('happy');
expect(selectElement).toBeInTheDocument(); expect(selectElement).toBeInTheDocument();
expect((selectElement as HTMLSelectElement).value).toBe('happy'); expect((selectElement as HTMLSelectElement).value).toBe('happy');
}); });
@@ -185,14 +185,14 @@ describe('BasicBeliefNode', () => {
/> />
); );
const selectElement = screen.getByDisplayValue('Happy'); const selectElement = screen.getByDisplayValue('happy');
expect(selectElement).toBeInTheDocument(); expect(selectElement).toBeInTheDocument();
// Check that all emotion options are present // Check that all emotion options are present
expect(screen.getByText('Happy')).toBeInTheDocument(); expect(screen.getByText('happy')).toBeInTheDocument();
expect(screen.getByText('Angry')).toBeInTheDocument(); expect(screen.getByText('angry')).toBeInTheDocument();
expect(screen.getByText('Sad')).toBeInTheDocument(); expect(screen.getByText('sad')).toBeInTheDocument();
expect(screen.getByText('Cheerful')).toBeInTheDocument(); expect(screen.getByText('surprise')).toBeInTheDocument();
}); });
it('should render without wrapping quotes for object type', () => { it('should render without wrapping quotes for object type', () => {
@@ -382,7 +382,7 @@ describe('BasicBeliefNode', () => {
data: { data: {
label: 'Belief', label: 'Belief',
droppable: true, droppable: true,
belief: { type: 'emotion', id: 'em1', value: 'happy', label: 'Emotion recognised:' }, belief: { type: 'emotion', id: 'em1', value: 'sad', label: 'Emotion recognised:' },
hasReduce: true, hasReduce: true,
}, },
}; };
@@ -409,13 +409,13 @@ describe('BasicBeliefNode', () => {
/> />
); );
const select = screen.getByDisplayValue('Happy'); const select = screen.getByDisplayValue('sad');
await user.selectOptions(select, 'sad'); await user.selectOptions(select, 'happy');
await waitFor(() => { await waitFor(() => {
const state = useFlowStore.getState(); const state = useFlowStore.getState();
const updatedNode = state.nodes.find(n => n.id === 'belief-1') as Node<BasicBeliefNodeData>; const updatedNode = state.nodes.find(n => n.id === 'belief-1') as Node<BasicBeliefNodeData>;
expect(updatedNode?.data.belief.value).toBe('sad'); expect(updatedNode?.data.belief.value).toBe('happy');
}); });
}); });
@@ -511,13 +511,11 @@ describe('BasicBeliefNode', () => {
expect(updatedNode?.data.belief.type).toBe('emotion'); expect(updatedNode?.data.belief.type).toBe('emotion');
// The component doesn't reset the value when changing types // The component doesn't reset the value when changing types
// So it keeps the old value even though it doesn't make sense for emotion type // So it keeps the old value even though it doesn't make sense for emotion type
expect(updatedNode?.data.belief.value).toBe('Happy'); expect(updatedNode?.data.belief.value).toBe('sad');
}); });
}); });
}); });
// ... rest of the tests remain the same, just fixing the Integration with Store section ...
describe('Integration with Store', () => { describe('Integration with Store', () => {
it('should properly update the store when changing belief value', async () => { it('should properly update the store when changing belief value', async () => {
const mockNode: Node<BasicBeliefNodeData> = { const mockNode: Node<BasicBeliefNodeData> = {