Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('components data should not infulence each other, and push item', done => {
store.addAction('for-connect-5', email => {
let builder = updateBuilder().push('persons[0].emails', email);
return builder;
});
let MyComponent = connect.san({
name: 'persons[0].name',
emails: 'persons[0].emails'
})(
san.defineComponent({
template: '<dl><dt title="{{name}}">{{name}}</dt><dd title="{{email}}">{{email}}</dd></dl>'
})
);
store.dispatch('for-connect-persons', [
{name: 'erik', emails: ['erik168@163.com', 'errorrik@gmail.com']}
]);
let wrap = document.createElement('div');
document.body.appendChild(wrap);
let myComponent1 = new MyComponent();
myComponent1.attach(wrap);
let myComponent2 = new MyComponent();
myComponent2.attach(wrap);
let dts = wrap.getElementsByTagName('dt');
let dds = wrap.getElementsByTagName('dd');
expect(dts.length).toBe(2);
expect(dds.length).toBe(4);
expect(dts[0].title).toBe('erik');
it('set errors and clear errors', () => {
store.dispatch(Types.ERRORS_SET, {title: 'one'});
let errors = store.getState('errors');
expect(errors.length).toBe(1);
expect(errors[0]).toBe('title one');
store.dispatch(Types.ERRORS_CLEAR);
expect(store.getState('errors') == null).toBeTruthy();
});
});
it('set errors and clear errors', () => {
store.dispatch(Types.ERRORS_SET, {title: 'one'});
let errors = store.getState('errors');
expect(errors.length).toBe(1);
expect(errors[0]).toBe('title one');
store.dispatch(Types.ERRORS_CLEAR);
expect(store.getState('errors') == null).toBeTruthy();
});
});
it('fetch list', done => {
let fetchPromise = store.dispatch(Types.FETCH);
expect(store.getState('articlesLoading')).toBeTruthy();
fetchPromise.then(() => {
expect(store.getState('articlesLoading')).toBeFalsy();
expect(store.getState('articleCount')).toBe(500);
expect(store.getState('articlePageCount') >= store.getState('articleCount') / Conf.PAGE_SIZE).toBeTruthy();
expect(store.getState('articles') instanceof Array).toBeTruthy();
done();
});
});
});
beforeEach(done => {
store.dispatch('reset-for-connect');
setTimeout(done, 1);
});
}
})(
san.defineComponent({
template: '<u title="{{name}}-{{email}}">{{name}}-{{email}}</u>'
})
);
let myComponent = new MyComponent();
let wrap = document.createElement('div');
document.body.appendChild(wrap);
myComponent.attach(wrap);
let u = wrap.getElementsByTagName('u')[0];
expect(u.title).toBe('errorrik-errorrik@gmail.com');
store.dispatch('for-connect-2', {
name: 'erik',
email: 'erik@gmail.com'
});
san.nextTick(() => {
let u = wrap.getElementsByTagName('u')[0];
expect(u.title).toBe('erik-erik@gmail.com');
myComponent.dispose();
document.body.removeChild(wrap);
done();
});
});
let myComponent2 = new MyComponent();
myComponent2.attach(wrap);
let dts = wrap.getElementsByTagName('dt');
let dds = wrap.getElementsByTagName('dd');
expect(dts.length).toBe(2);
expect(dds.length).toBe(4);
expect(dts[0].title).toBe('erik');
expect(dts[1].title).toBe('erik');
expect(dds[0].title).toBe('erik168@163.com');
expect(dds[1].title).toBe('errorrik@gmail.com');
expect(dds[2].title).toBe('erik168@163.com');
expect(dds[3].title).toBe('errorrik@gmail.com');
store.dispatch('for-connect-6', 'erik168@163.com');
san.nextTick(() => {
let dts = wrap.getElementsByTagName('dt');
let dds = wrap.getElementsByTagName('dd');
expect(dts.length).toBe(2);
expect(dds.length).toBe(2);
expect(dds[0].title).toBe('errorrik@gmail.com');
expect(dds[1].title).toBe('errorrik@gmail.com');
myComponent2.data.push('person.emails', 'erik@erik.com');
san.nextTick(() => {
let dts = wrap.getElementsByTagName('dt');
let dds = wrap.getElementsByTagName('dd');
expect(dts.length).toBe(2);
expect(dds.length).toBe(3);
email: 'emails[0]'
})(
san.defineComponent({
template: '<u title="{{name}}-{{email}}">{{name}}-{{email}}</u>'
})
);
let myComponent = new MyComponent();
let wrap = document.createElement('div');
document.body.appendChild(wrap);
myComponent.attach(wrap);
let u = wrap.getElementsByTagName('u')[0];
expect(u.title).toBe('errorrik-errorrik@gmail.com');
store.dispatch('for-connect-1', {
name: 'erik',
email: 'erik@gmail.com'
});
san.nextTick(() => {
let u = wrap.getElementsByTagName('u')[0];
expect(u.title).toBe('erik-erik@gmail.com');
myComponent.dispose();
document.body.removeChild(wrap);
done();
});
});
expect(MyComponent === RawComponent).toBeFalsy();
let wrap = document.createElement('div');
document.body.appendChild(wrap);
let myComponent = new RawComponent();
myComponent.attach(wrap);
let myComponent2 = new MyComponent();
myComponent2.attach(wrap);
expect(myComponent.el.title).toBe('efe-ecomfe@gmail.com');
expect(myComponent2.el.title).toBe('errorrik-errorrik@gmail.com');
store.dispatch('for-connect-9', {
name: 'erik',
email: 'erik@gmail.com'
});
myComponent.data.set('name', 'err');
myComponent.data.set('email', 'errorrik@gmail.com');
san.nextTick(() => {
expect(myComponent.el.title).toBe('err-errorrik@gmail.com');
expect(myComponent2.el.title).toBe('erik-erik@gmail.com');
myComponent.dispose();
myComponent2.dispose();
document.body.removeChild(wrap);
done();
});
return function ({data}) {
if (data.errors) {
store.dispatch(Types.ERRORS_SET, data.errors);
}
else if (typeof fn === 'function'){
fn(data);
}
return data;
};
}