From d89cb5b5f6253e99fde36a27c21ab1929d56bee1 Mon Sep 17 00:00:00 2001 From: Chi Nguyen Date: Mon, 8 Apr 2019 13:35:23 +0300 Subject: [PATCH 1/5] fix deprecated ref prop on react-bootstrap cause null value --- app/shared/comment-form/CommentForm.js | 5 +++-- app/shared/comment-form/CommentForm.spec.js | 2 +- app/shared/modals/reservation-info/ReservationInfoModal.js | 5 +++-- .../modals/reservation-info/ReservationInfoModal.spec.js | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/shared/comment-form/CommentForm.js b/app/shared/comment-form/CommentForm.js index f2c84e1ec..885682dd9 100644 --- a/app/shared/comment-form/CommentForm.js +++ b/app/shared/comment-form/CommentForm.js @@ -17,7 +17,7 @@ class CommentForm extends Component { handleSave(event) { event.preventDefault(); - const comments = this.commentsInput.current.value; + const comments = this.commentsInput.value; this.props.onSave(comments); } @@ -33,8 +33,9 @@ class CommentForm extends Component { this.commentsInput = ref} placeholder={t('CommentForm.placeholder')} - ref={this.commentsInput} rows={5} /> diff --git a/app/shared/comment-form/CommentForm.spec.js b/app/shared/comment-form/CommentForm.spec.js index 9d24849c5..c32cca99a 100644 --- a/app/shared/comment-form/CommentForm.spec.js +++ b/app/shared/comment-form/CommentForm.spec.js @@ -75,7 +75,7 @@ describe('shared/comment-form/CommentForm', () => { beforeAll(() => { const instance = getWrapper().instance(); // override ref value to mock - instance.commentsInput.current = { value: comments }; + instance.commentsInput = { value: comments }; defaultProps.onSave.reset(); instance.handleSave(mockEvent); diff --git a/app/shared/modals/reservation-info/ReservationInfoModal.js b/app/shared/modals/reservation-info/ReservationInfoModal.js index 40f244492..c3e6d6c14 100644 --- a/app/shared/modals/reservation-info/ReservationInfoModal.js +++ b/app/shared/modals/reservation-info/ReservationInfoModal.js @@ -29,7 +29,7 @@ class ReservationInfoModal extends Component { } handleSaveCommentsClick() { - const comments = this.commentsInput.current.value; + const comments = this.commentsInput.value; this.props.onSaveCommentsClick(comments); } @@ -98,8 +98,9 @@ class ReservationInfoModal extends Component { componentClass="textarea" defaultValue={reservation.comments} disabled={disabled} + // eslint-disable-next-line no-return-assign + inputRef={ref => this.commentsInput = ref} placeholder={t('common.commentsPlaceholder')} - ref={this.commentsInput} rows={5} /> diff --git a/app/shared/modals/reservation-info/ReservationInfoModal.spec.js b/app/shared/modals/reservation-info/ReservationInfoModal.spec.js index 28e4e4c42..c4eed510f 100644 --- a/app/shared/modals/reservation-info/ReservationInfoModal.spec.js +++ b/app/shared/modals/reservation-info/ReservationInfoModal.spec.js @@ -363,7 +363,7 @@ describe('shared/modals/reservation-info/ReservationInfoModal', () => { beforeAll(() => { const instance = getWrapper({ onSaveCommentsClick }).instance(); // override ref value to mock - instance.commentsInput.current = { value: comments }; + instance.commentsInput = { value: comments }; instance.handleSaveCommentsClick(); }); From 3a8ffd2172ee87af54da291d7cfefa653c5dc0dd Mon Sep 17 00:00:00 2001 From: Chi Nguyen Date: Mon, 8 Apr 2019 13:53:14 +0300 Subject: [PATCH 2/5] add unit tests --- app/shared/comment-form/CommentForm.spec.js | 1 + app/shared/modals/reservation-info/ReservationInfoModal.spec.js | 1 + 2 files changed, 2 insertions(+) diff --git a/app/shared/comment-form/CommentForm.spec.js b/app/shared/comment-form/CommentForm.spec.js index c32cca99a..2ad15c83c 100644 --- a/app/shared/comment-form/CommentForm.spec.js +++ b/app/shared/comment-form/CommentForm.spec.js @@ -32,6 +32,7 @@ describe('shared/comment-form/CommentForm', () => { expect(formControl.length).toBe(1); expect(formControl.prop('componentClass')).toBe('textarea'); expect(formControl.prop('defaultValue')).toBe(defaultProps.defaultValue); + expect(typeof formControl.prop('inputRef')).toBe('function'); }); }); diff --git a/app/shared/modals/reservation-info/ReservationInfoModal.spec.js b/app/shared/modals/reservation-info/ReservationInfoModal.spec.js index c4eed510f..8052d14f7 100644 --- a/app/shared/modals/reservation-info/ReservationInfoModal.spec.js +++ b/app/shared/modals/reservation-info/ReservationInfoModal.spec.js @@ -125,6 +125,7 @@ describe('shared/modals/reservation-info/ReservationInfoModal', () => { expect(formControl).toHaveLength(1); expect(formControl.prop('componentClass')).toBe('textarea'); expect(formControl.prop('defaultValue')).toBe(reservation.comments); + expect(typeof formControl.prop('inputRef')).toBe('function'); }); test('renders a save button with correct onClick prop', () => { From 8969fa12a4eeb7fe4563e0c87aaf3e6e454e0333 Mon Sep 17 00:00:00 2001 From: Chi Nguyen Date: Mon, 8 Apr 2019 14:27:47 +0300 Subject: [PATCH 3/5] add better test include mocking input change --- app/shared/comment-form/CommentForm.spec.js | 6 +++++- .../modals/reservation-info/ReservationInfoModal.spec.js | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/shared/comment-form/CommentForm.spec.js b/app/shared/comment-form/CommentForm.spec.js index 2ad15c83c..6832eb294 100644 --- a/app/shared/comment-form/CommentForm.spec.js +++ b/app/shared/comment-form/CommentForm.spec.js @@ -27,12 +27,16 @@ describe('shared/comment-form/CommentForm', () => { describe('comments textarea', () => { test('renders a FormControl with correct props', () => { - const formControl = getWrapper().find(FormControl); + const wrapper = getWrapper(); + const formControl = wrapper.find(FormControl); + formControl.prop('inputRef')('foo'); + // change input expect(formControl.length).toBe(1); expect(formControl.prop('componentClass')).toBe('textarea'); expect(formControl.prop('defaultValue')).toBe(defaultProps.defaultValue); expect(typeof formControl.prop('inputRef')).toBe('function'); + expect(wrapper.instance().commentsInput).toEqual('foo'); }); }); diff --git a/app/shared/modals/reservation-info/ReservationInfoModal.spec.js b/app/shared/modals/reservation-info/ReservationInfoModal.spec.js index 8052d14f7..6ddcbb54f 100644 --- a/app/shared/modals/reservation-info/ReservationInfoModal.spec.js +++ b/app/shared/modals/reservation-info/ReservationInfoModal.spec.js @@ -121,11 +121,17 @@ describe('shared/modals/reservation-info/ReservationInfoModal', () => { }); test('renders textarea FormControl for comments with correct props', () => { - const formControl = getCommentsForm(props).find(FormControl); + const wrapper = getWrapper(props); + const formControl = wrapper.find('.comments-form').find(FormControl); + + formControl.prop('inputRef')('foo'); + // change input value + expect(formControl).toHaveLength(1); expect(formControl.prop('componentClass')).toBe('textarea'); expect(formControl.prop('defaultValue')).toBe(reservation.comments); expect(typeof formControl.prop('inputRef')).toBe('function'); + expect(wrapper.instance().commentsInput).toEqual('foo'); }); test('renders a save button with correct onClick prop', () => { From 08b144eaf44dfe882c584b75554b71fc1dc3b3a7 Mon Sep 17 00:00:00 2001 From: Chi Nguyen Date: Mon, 8 Apr 2019 14:38:31 +0300 Subject: [PATCH 4/5] making mock more consistent with real ref --- app/shared/comment-form/CommentForm.spec.js | 6 ++++-- .../modals/reservation-info/ReservationInfoModal.spec.js | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/shared/comment-form/CommentForm.spec.js b/app/shared/comment-form/CommentForm.spec.js index 6832eb294..3eac7a174 100644 --- a/app/shared/comment-form/CommentForm.spec.js +++ b/app/shared/comment-form/CommentForm.spec.js @@ -29,14 +29,16 @@ describe('shared/comment-form/CommentForm', () => { test('renders a FormControl with correct props', () => { const wrapper = getWrapper(); const formControl = wrapper.find(FormControl); - formControl.prop('inputRef')('foo'); + const mockRef = { value: 'foo' }; + + formControl.prop('inputRef')(mockRef); // change input expect(formControl.length).toBe(1); expect(formControl.prop('componentClass')).toBe('textarea'); expect(formControl.prop('defaultValue')).toBe(defaultProps.defaultValue); expect(typeof formControl.prop('inputRef')).toBe('function'); - expect(wrapper.instance().commentsInput).toEqual('foo'); + expect(wrapper.instance().commentsInput).toEqual(mockRef); }); }); diff --git a/app/shared/modals/reservation-info/ReservationInfoModal.spec.js b/app/shared/modals/reservation-info/ReservationInfoModal.spec.js index 6ddcbb54f..e125762c4 100644 --- a/app/shared/modals/reservation-info/ReservationInfoModal.spec.js +++ b/app/shared/modals/reservation-info/ReservationInfoModal.spec.js @@ -123,15 +123,16 @@ describe('shared/modals/reservation-info/ReservationInfoModal', () => { test('renders textarea FormControl for comments with correct props', () => { const wrapper = getWrapper(props); const formControl = wrapper.find('.comments-form').find(FormControl); + const mockRef = { value: 'foo' }; - formControl.prop('inputRef')('foo'); + formControl.prop('inputRef')(mockRef); // change input value expect(formControl).toHaveLength(1); expect(formControl.prop('componentClass')).toBe('textarea'); expect(formControl.prop('defaultValue')).toBe(reservation.comments); expect(typeof formControl.prop('inputRef')).toBe('function'); - expect(wrapper.instance().commentsInput).toEqual('foo'); + expect(wrapper.instance().commentsInput).toEqual(mockRef); }); test('renders a save button with correct onClick prop', () => { From 800550934dbedd5f81491f3c2eac5b813d70fd4a Mon Sep 17 00:00:00 2001 From: Chi Nguyen Date: Tue, 9 Apr 2019 13:53:04 +0300 Subject: [PATCH 5/5] Prepare release 0.1.1 --- CHANGELOG.md | 6 +++++- package.json | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 089f1fa80..a6b7b84ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +* 0.1.1 + ** HOTFIX ** + + - [#913](https://github.com/City-of-Helsinki/varaamo/pull/913) Fix issue staff comment section is not working. Reason: React-bootstrap ref prop which is deprecated and replace with inputProps * 0.1.0 ** MAJOR CHANGES ** @@ -21,7 +25,7 @@ - #875: Expand advanced search panel when filters are applied. - - #876: Free-of-charge filter for resources. + - #876: Free-of-charge filter for resources. - #878: Remove the link for old website from the footer. diff --git a/package.json b/package.json index 16f4fcb15..6bf20b434 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "varaamo", - "version": "0.1.0", + "version": "0.1.1", "repository": { "type": "git", "url": "https://github.com/City-of-Helsinki/varaamo"