Improve validation with asynchronous pipeline#175
Improve validation with asynchronous pipeline#175Mosoc wants to merge 22 commits intoCannerCMS:canaryfrom
Conversation
abz53378
left a comment
There was a problem hiding this comment.
We can just use the wrapper.instance().validate(result) to test the async function.
some refs:
|
@abz53378 async componentDidMount() {
const {refId, validation = {}, onDeploy, required = false} = this.props;
if (isEmpty(validation) && !required) {
// no validation
return;
}
const key = refId.getPathArr()[0];
this.callbackId = onDeploy(key, await this.validate);
}Then run test with waiting this lifecycle, is it a good way? it('should onDeploy be called', async () => {
const wrapper = mount(<WrapperComponent
{...props}
required
/>);
const instance = wrapper.instance();
await instance.componentDidMount();
expect(onDeploy).toBeCalledWith('posts', wrapper.instance().validate);
}); |
|
@Mosoc , I don't think it's a good way to make the |
|
@abz53378 it('should use customized validator with unexpected error', async () => {
const result = {
data: {
0: { url: ''}
}
};
const wrapper = mount(<WrapperComponent
{...props}
validation={
{
validator: () => {
const value = 1;
value = 2;
}
}
}
/>);
await wrapper.instance().validate(result)
expect(wrapper.state()).toMatchObject({
error: true,
errorInfo: [{
message: 'Error: "value" is read-only'
}]
})
}); |
|
I rechecked, and found that only one place needs to be modified. In docs folder, there is a galleryValidation. export const galleryValidation = {
validator: (content, reject) => {
if (content.length === 0) {
return reject("should at least have one photo");
}
}
};Maybe it could be following snippet in new version: export const galleryValidation = {
validator: (content) => {
if (content.length === 0) {
return "should at least have one photo";
}
}
}; |
As reported in #173 #174
There are some todo:
schemaproperty to validation objectschemais verified as non-empty object