mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-19 11:01:15 +00:00
refactor(editor): Move test files alongside tested files (no-changelog) (#11504)
This commit is contained in:
72
packages/editor-ui/src/components/RunDataJson.test.ts
Normal file
72
packages/editor-ui/src/components/RunDataJson.test.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
import { createTestingPinia } from '@pinia/testing';
|
||||
import { screen, cleanup } from '@testing-library/vue';
|
||||
import RunDataJson from '@/components/RunDataJson.vue';
|
||||
import { createComponentRenderer } from '@/__tests__/render';
|
||||
import { useElementSize } from '@vueuse/core'; // Import the composable to mock
|
||||
|
||||
vi.mock('@vueuse/core', async () => {
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
|
||||
const originalModule = await vi.importActual<typeof import('@vueuse/core')>('@vueuse/core');
|
||||
|
||||
return {
|
||||
...originalModule, // Keep all original exports
|
||||
useElementSize: vi.fn(), // Mock useElementSize
|
||||
};
|
||||
});
|
||||
|
||||
(useElementSize as jest.Mock).mockReturnValue({
|
||||
height: 500, // Mocked height value
|
||||
width: 300, // Mocked width value
|
||||
});
|
||||
|
||||
const renderComponent = createComponentRenderer(RunDataJson, {
|
||||
props: {
|
||||
mappingEnabled: true,
|
||||
editMode: { enabled: false },
|
||||
inputData: [
|
||||
{
|
||||
json: {
|
||||
list: [1, 2, 3],
|
||||
record: { name: 'Joe' },
|
||||
myNumber: 123,
|
||||
myStringNumber: '456',
|
||||
myStringText: 'abc',
|
||||
nil: null,
|
||||
d: undefined,
|
||||
},
|
||||
},
|
||||
],
|
||||
node: {
|
||||
parameters: {
|
||||
keepOnlySet: false,
|
||||
values: {},
|
||||
options: {},
|
||||
},
|
||||
id: '820ea733-d8a6-4379-8e73-88a2347ea003',
|
||||
name: 'Set',
|
||||
type: 'n8n-nodes-base.set',
|
||||
typeVersion: 1,
|
||||
position: [380, 1060],
|
||||
disabled: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
describe('RunDataJson.vue', () => {
|
||||
beforeEach(cleanup);
|
||||
|
||||
it('renders json values properly', () => {
|
||||
const { container } = renderComponent({
|
||||
global: {
|
||||
plugins: [createTestingPinia()],
|
||||
},
|
||||
});
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
expect(screen.getByText('123')).toBeInTheDocument();
|
||||
expect(screen.getByText('"456"')).toBeInTheDocument();
|
||||
expect(screen.getByText('"abc"')).toBeInTheDocument();
|
||||
expect(screen.getByText('null')).toBeInTheDocument();
|
||||
expect(screen.queryByText('undefined')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user