From b1bdd2b07c3171ed5cec2b56272d38eb21446492 Mon Sep 17 00:00:00 2001 From: Miguel Alatzar Date: Sat, 25 May 2019 08:58:49 -0700 Subject: [PATCH] Add unit test for PostBody's measurePost (#2833) --- app/components/post_body/post_body.test.js | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/app/components/post_body/post_body.test.js b/app/components/post_body/post_body.test.js index c040209cb..aa78520cb 100644 --- a/app/components/post_body/post_body.test.js +++ b/app/components/post_body/post_body.test.js @@ -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(); + 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(); + 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); + }); });