Skip to content

Commit

Permalink
[refactor] GH-15 Story test data
Browse files Browse the repository at this point in the history
  • Loading branch information
amivanoff committed Sep 22, 2021
1 parent 34f5878 commit c2d809b
Showing 1 changed file with 52 additions and 55 deletions.
107 changes: 52 additions & 55 deletions stories/Form.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Meta, Story } from '@storybook/react';

import { Provider } from 'react-redux';
import { asReduxStore, connectReduxDevtools } from 'mst-middlewares';
import { SparqlClientImpl, rootModelInitialState, CollState } from '@agentlab/sparql-jsld-client';
import { SparqlClientImpl, rootModelInitialState, CollState, JsObject } from '@agentlab/sparql-jsld-client';

import {
RendererRegistryEntry,
Expand Down Expand Up @@ -98,30 +98,44 @@ const viewDescrs = [
},
];

const createAdditionalColls = (viewKinds: any, colls: CollState[]): CollState[] => [
// ViewKinds Collection
{
constr: viewKindCollConstr,
data: viewKinds,
opt: {
updPeriod: undefined,
lastSynced: moment.now(),
//resolveCollConstrs: false, // disable data loading from the server for viewKinds.collConstrs
const createAdditionalColls = (viewKinds: any, data: JsObject[] | undefined): CollState[] => {
const additionalColls = [
// ViewKinds Collection
{
constr: viewKindCollConstr,
data: viewKinds,
opt: {
updPeriod: undefined,
lastSynced: moment.now(),
//resolveCollConstrs: false, // disable data loading from the server for viewKinds.collConstrs
},
},
},
// ViewDescrs Collection
{
constr: viewDescrCollConstr,
data: viewDescrs,
opt: {
updPeriod: undefined,
lastSynced: moment.now(),
//resolveCollConstrs: false, // 'true' here (by default) triggers data loading from the server
// for viewDescrs.collConstrs (it loads lazily -- after the first access)
// ViewDescrs Collection
{
constr: viewDescrCollConstr,
data: viewDescrs,
opt: {
updPeriod: undefined,
lastSynced: moment.now(),
//resolveCollConstrs: false, // 'true' here (by default) triggers data loading from the server
// for viewDescrs.collConstrs (it loads lazily -- after the first access)
},
},
},
...colls,
];
];
if (data) {
additionalColls.push({
constr: viewKinds[0].collsConstrs[0],
data,
opt: {
updPeriod: undefined,
lastSynced: moment.now(),
//resolveCollConstrs: false, // 'true' here (by default) triggers data loading from the server
// for viewDescrs.collConstrs (it loads lazily -- after the first access)
},
});
}
return additionalColls;
};

export default {
title: 'Form/ArtifactForm',
Expand All @@ -139,7 +153,7 @@ const Template: Story<any> = (args: any) => {
'reqs2',
client,
rootModelInitialState,
createAdditionalColls(args.viewKinds || viewKinds, args.colls || []),
createAdditionalColls(args.viewKinds || viewKinds, args.data),
);
const store: any = asReduxStore(rootStore);
// eslint-disable-next-line @typescript-eslint/no-var-requires
Expand All @@ -158,40 +172,23 @@ const Template: Story<any> = (args: any) => {
export const RemoteData = Template.bind({});
RemoteData.args = {};

export const FormWithNullProperty = Template.bind({});
FormWithNullProperty.args = {
colls: [
export const ObjectWithNullProperty = Template.bind({});
ObjectWithNullProperty.args = {
data: [
{
constr: viewKinds[0].collsConstrs[0],
data: [
{
creator: null,
assetFolder: null,
description: 'TestDescr',
},
],
opt: {
updPeriod: undefined,
lastSynced: moment.now(),
//resolveCollConstrs: false, // 'true' here (by default) triggers data loading from the server
// for viewDescrs.collConstrs (it loads lazily -- after the first access)
},
creator: null,
assetFolder: null,
description: 'TestDescr',
},
],
};

export const FormWithUndefinedProperty = Template.bind({});
FormWithUndefinedProperty.args = {
colls: [
{
constr: viewKinds[0].collsConstrs[0],
data: [{}],
opt: {
updPeriod: undefined,
lastSynced: moment.now(),
//resolveCollConstrs: false, // 'true' here (by default) triggers data loading from the server
// for viewDescrs.collConstrs (it loads lazily -- after the first access)
},
},
],
export const EmptyObject = Template.bind({});
EmptyObject.args = {
data: [{}],
};

export const NoObject = Template.bind({});
NoObject.args = {
data: [{}],
};

0 comments on commit c2d809b

Please sign in to comment.