mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
fix(editor): Schema view shows checkbox in case of empty data (#4889)
* fix(editor): Schema view show nothing in case of empty data * fix(editor): Schema view test for empty data
This commit is contained in:
parent
07b2f7678c
commit
b0c158c64f
|
@ -250,7 +250,7 @@
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<run-data-schema
|
<run-data-schema
|
||||||
v-else-if="hasNodeRun && displayMode === 'schema' && jsonData?.length > 0"
|
v-else-if="hasNodeRun && displayMode === 'schema'"
|
||||||
:data="jsonData"
|
:data="jsonData"
|
||||||
:mappingEnabled="mappingEnabled"
|
:mappingEnabled="mappingEnabled"
|
||||||
:distanceFromActive="distanceFromActive"
|
:distanceFromActive="distanceFromActive"
|
||||||
|
|
|
@ -1,59 +1,69 @@
|
||||||
import { PiniaVuePlugin } from 'pinia';
|
import { PiniaVuePlugin } from 'pinia';
|
||||||
import { createTestingPinia } from '@pinia/testing';
|
import { createTestingPinia } from '@pinia/testing';
|
||||||
import { render } from '@testing-library/vue';
|
import { render, cleanup } from '@testing-library/vue';
|
||||||
import RunDataJsonSchema from '@/components/RunDataSchema.vue';
|
import RunDataJsonSchema from '@/components/RunDataSchema.vue';
|
||||||
import { STORES } from "@/constants";
|
import { STORES } from "@/constants";
|
||||||
|
|
||||||
describe('RunDataJsonSchema.vue', () => {
|
describe('RunDataJsonSchema.vue', () => {
|
||||||
it('renders json schema properly', () => {
|
const renderOptions = {
|
||||||
const { container } = render(RunDataJsonSchema, {
|
pinia: createTestingPinia({
|
||||||
pinia: createTestingPinia({
|
initialState: {
|
||||||
initialState: {
|
[STORES.SETTINGS]: {
|
||||||
[STORES.SETTINGS]: {
|
settings: {
|
||||||
settings: {
|
templates: {
|
||||||
templates: {
|
enabled: true,
|
||||||
enabled: true,
|
host: 'https://api.n8n.io/api/',
|
||||||
host: 'https://api.n8n.io/api/',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}),
|
|
||||||
stubs: ['font-awesome-icon'],
|
|
||||||
props: {
|
|
||||||
mappingEnabled: true,
|
|
||||||
distanceFromActive: 1,
|
|
||||||
runIndex: 1,
|
|
||||||
totalRuns: 2,
|
|
||||||
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,
|
|
||||||
},
|
|
||||||
data: [{ name: 'John', age: 22, hobbies: ['surfing', 'traveling'] }, { name: 'Joe', age: 33, hobbies: ['skateboarding', 'gaming'] }],
|
|
||||||
},
|
|
||||||
mocks: {
|
|
||||||
$locale: {
|
|
||||||
baseText() {
|
|
||||||
return '';
|
|
||||||
},
|
|
||||||
},
|
|
||||||
$store: {
|
|
||||||
getters: {},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
}),
|
||||||
|
stubs: ['font-awesome-icon'],
|
||||||
|
props: {
|
||||||
|
mappingEnabled: true,
|
||||||
|
distanceFromActive: 1,
|
||||||
|
runIndex: 1,
|
||||||
|
totalRuns: 2,
|
||||||
|
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,
|
||||||
|
},
|
||||||
|
data: [{}],
|
||||||
|
},
|
||||||
|
mocks: {
|
||||||
|
$locale: {
|
||||||
|
baseText() {
|
||||||
|
return '';
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeEach(cleanup);
|
||||||
|
|
||||||
|
it('renders schema for empty data', () => {
|
||||||
|
const { container } = render(RunDataJsonSchema, renderOptions,
|
||||||
|
vue => {
|
||||||
|
vue.use(PiniaVuePlugin);
|
||||||
|
});
|
||||||
|
expect(container).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders schema for data', () => {
|
||||||
|
renderOptions.props.data = [{ name: 'John', age: 22, hobbies: ['surfing', 'traveling'] }, { name: 'Joe', age: 33, hobbies: ['skateboarding', 'gaming'] }];
|
||||||
|
const { container } = render(RunDataJsonSchema, renderOptions,
|
||||||
vue => {
|
vue => {
|
||||||
vue.use(PiniaVuePlugin);
|
vue.use(PiniaVuePlugin);
|
||||||
});
|
});
|
||||||
|
|
|
@ -8,7 +8,7 @@ import { useWebhooksStore } from "@/stores/webhooks";
|
||||||
import { runExternalHook } from "@/mixins/externalHooks";
|
import { runExternalHook } from "@/mixins/externalHooks";
|
||||||
import { telemetry } from "@/plugins/telemetry";
|
import { telemetry } from "@/plugins/telemetry";
|
||||||
import { IDataObject } from "n8n-workflow";
|
import { IDataObject } from "n8n-workflow";
|
||||||
import { getSchema, mergeDeep } from "@/utils";
|
import { getSchema, isEmpty, mergeDeep } from "@/utils";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
data: IDataObject[]
|
data: IDataObject[]
|
||||||
|
@ -32,6 +32,10 @@ const schema = computed<Schema>(() => {
|
||||||
return getSchema(mergeDeep([head, ...tail, head]));
|
return getSchema(mergeDeep([head, ...tail, head]));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const isDataEmpty = computed(() => {
|
||||||
|
return isEmpty(props.data);
|
||||||
|
});
|
||||||
|
|
||||||
const onDragStart = (el: HTMLElement) => {
|
const onDragStart = (el: HTMLElement) => {
|
||||||
if (el && el.dataset?.path) {
|
if (el && el.dataset?.path) {
|
||||||
draggingPath.value = el.dataset.path;
|
draggingPath.value = el.dataset.path;
|
||||||
|
@ -67,7 +71,9 @@ const onDragEnd = (el: HTMLElement) => {
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div :class="$style.schemaWrapper">
|
<div :class="$style.schemaWrapper">
|
||||||
|
<div v-if="isDataEmpty" />
|
||||||
<draggable
|
<draggable
|
||||||
|
v-else
|
||||||
type="mapping"
|
type="mapping"
|
||||||
targetDataKey="mappable"
|
targetDataKey="mappable"
|
||||||
:disabled="!mappingEnabled"
|
:disabled="!mappingEnabled"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Vitest Snapshot v1
|
// Vitest Snapshot v1
|
||||||
|
|
||||||
exports[`RunDataJsonSchema.vue > renders json schema properly 1`] = `
|
exports[`RunDataJsonSchema.vue > renders schema for data 1`] = `
|
||||||
<div>
|
<div>
|
||||||
<div
|
<div
|
||||||
class="_schemaWrapper_1w572_1"
|
class="_schemaWrapper_1w572_1"
|
||||||
|
@ -251,3 +251,13 @@ exports[`RunDataJsonSchema.vue > renders json schema properly 1`] = `
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`RunDataJsonSchema.vue > renders schema for empty data 1`] = `
|
||||||
|
<div>
|
||||||
|
<div
|
||||||
|
class="_schemaWrapper_1w572_1"
|
||||||
|
>
|
||||||
|
<div />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
Loading…
Reference in a new issue