Add unit test for PostBody's measurePost (#2833)
This commit is contained in:
parent
f444b70f4f
commit
b1bdd2b07c
1 changed files with 56 additions and 0 deletions
|
|
@ -67,4 +67,60 @@ describe('PostBody', () => {
|
|||
|
||||
expect(wrapper.find(PostBodyAdditionalContent).exists()).toBeFalsy();
|
||||
});
|
||||
|
||||
test('measurePost should update isLongPost when showLongPost is false', () => {
|
||||
const event = {
|
||||
nativeEvent: {
|
||||
layout: {
|
||||
height: null,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const props = {...baseProps, showLongPost: false};
|
||||
const wrapper = shallowWithIntl(<PostBody {...props}/>);
|
||||
const instance = wrapper.instance();
|
||||
|
||||
expect(wrapper.state('isLongPost')).toEqual(false);
|
||||
|
||||
event.nativeEvent.layout.height = wrapper.state('maxHeight');
|
||||
instance.measurePost(event);
|
||||
expect(wrapper.state('isLongPost')).toEqual(true);
|
||||
|
||||
event.nativeEvent.layout.height = wrapper.state('maxHeight') - 1;
|
||||
instance.measurePost(event);
|
||||
expect(wrapper.state('isLongPost')).toEqual(false);
|
||||
|
||||
event.nativeEvent.layout.height = wrapper.state('maxHeight') + 1;
|
||||
instance.measurePost(event);
|
||||
expect(wrapper.state('isLongPost')).toEqual(true);
|
||||
});
|
||||
|
||||
test('measurePost should not update isLongPost when showLongPost is true', () => {
|
||||
const event = {
|
||||
nativeEvent: {
|
||||
layout: {
|
||||
height: null,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const props = {...baseProps, showLongPost: true};
|
||||
const wrapper = shallowWithIntl(<PostBody {...props}/>);
|
||||
const instance = wrapper.instance();
|
||||
|
||||
expect(wrapper.state('isLongPost')).toEqual(false);
|
||||
|
||||
event.nativeEvent.layout.height = wrapper.state('maxHeight');
|
||||
instance.measurePost(event);
|
||||
expect(wrapper.state('isLongPost')).toEqual(false);
|
||||
|
||||
event.nativeEvent.layout.height = wrapper.state('maxHeight') - 1;
|
||||
instance.measurePost(event);
|
||||
expect(wrapper.state('isLongPost')).toEqual(false);
|
||||
|
||||
event.nativeEvent.layout.height = wrapper.state('maxHeight') + 1;
|
||||
instance.measurePost(event);
|
||||
expect(wrapper.state('isLongPost')).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue