@tomino/dynamic-form-semantic-ui
Version:
Semantic UI form renderer based on dynamic form generation
139 lines • 4.04 kB
JavaScript
import { prepareComponent } from '../../semantic/tests/common';
import { create } from '../../semantic/tests/form_query_data';
const schema = {
type: 'object',
properties: {
people: {
type: 'array',
items: {
type: 'object',
properties: {
name: { type: 'string' },
sex: { type: 'string' }
}
}
}
}
};
const withFakeData = (data) => [
{
control: 'Stack',
props: {
layout: 'column',
gap: '3px'
},
elements: [
{
control: 'ApolloMutation',
props: {
fakeData: data,
clickHandler: 'mutate',
mutation: `mutation Mutate {
mutate {
name
sex
}
}`,
target: 'people',
loadingText: 'Loading ...'
},
elements: [
{
control: 'Button',
props: {
content: 'Mutate',
onClick: 'mutate'
}
},
{
control: 'Repeater',
props: { value: { source: 'people' } },
elements: [
{
control: 'Stack',
elements: [
{
control: 'Text',
props: { value: { source: 'name' } }
},
{
control: 'Text',
props: { value: ':\xa0' }
},
{
control: 'Text',
props: { value: { source: 'sex' } }
}
]
},
null,
null
]
}
]
}
]
}
];
const formDefinition = create.stack({
elements: [
{
control: 'Text',
props: {
value: 'Empty'
}
},
{
control: 'ApolloProvider',
props: {
server: 'http://localhost:4000/graphql',
auth: false
},
elements: []
},
{
control: 'Text',
props: {
value: 'Real Data'
}
},
{
control: 'ApolloProvider',
props: {
server: 'http://localhost:4000/graphql',
auth: false,
disable: false
},
elements: withFakeData(null)
},
{
control: 'Text',
props: {
value: 'Fake Data'
}
},
{
control: 'ApolloProvider',
props: {
server: 'http://localhost:4000/graphql',
auth: false,
disable: false
},
elements: withFakeData(JSON.stringify({
mutate: [
{ __typename: 'Person', name: 'Tomas', sex: 'Male' },
{ __typename: 'Person', name: 'Valeria', sex: 'Female' }
]
}))
}
]
});
const formData = {};
describe('Apollo', () => {
describe('Mutation', () => {
return {
component: prepareComponent(formDefinition, schema, formData, { addEditor: true })
};
});
});
//# sourceMappingURL=apollo_mutation.test.js.map