From db0e59c024406b5ea98f78c26fdeede9dc02db17 Mon Sep 17 00:00:00 2001 From: Kestutis Kasiulynas Date: Sat, 25 Jul 2020 21:09:53 +0100 Subject: [PATCH] fix: Add default onAction prop (#382) * fix: Add default onAction prop PropTypes define onAction property as optional, however in class its used unconditionally. * fix: Add console error spy check Co-authored-by: Hrusikesh Panda --- __snapshots__/src/index.test.js.md | 2 ++ __snapshots__/src/index.test.js.snap | Bin 4667 -> 4706 bytes src/index.js | 1 + src/index.test.js | 9 +++++++++ 4 files changed, 12 insertions(+) diff --git a/__snapshots__/src/index.test.js.md b/__snapshots__/src/index.test.js.md index 3c7d255b..182f516c 100644 --- a/__snapshots__/src/index.test.js.md +++ b/__snapshots__/src/index.test.js.md @@ -459,6 +459,7 @@ Generated by [AVA](https://ava.li). id="rdts" inlineSearchInput={false} mode="radioSelect" + onAction={Function onAction {}} onBlur={Function onBlur {}} onChange={Function onChange {}} onFocus={Function onFocus {}} @@ -609,6 +610,7 @@ Generated by [AVA](https://ava.li). } id="rdts" inlineSearchInput={false} + onAction={Function onAction {}} onBlur={Function onBlur {}} onChange={Function onChange {}} onFocus={Function onFocus {}} diff --git a/__snapshots__/src/index.test.js.snap b/__snapshots__/src/index.test.js.snap index 3a8268af07a32b8a0ab23049d8bd6b84e4b7e0f2..e5b6eb5d2c3a959272df06e19415a2a15760c76f 100644 GIT binary patch literal 4706 zcmV-o5}oZqRzV=*p8?H`K>00000000B+ zoeP)~<+;bd$^E)X_697V%iUYhU5ghG#e-5&akoIJdq9`jY}gHElQhXL7q!Le!5iMn zgY{Br1#An}V$~LG6>EK<_CT=(m7_kQM@y~RR&)iSVCjEmGLxAvGs#TY<#2R-{AuQ! z_q$)`|4y>22q6x#f5ONsE$4QfzwbMXpRAho-cW{c|6Ec-Nb{DhZ%*8F+V^@|->^P? z{pLjsA3E(+LMHZX`RVv|uN>}OUc2n@rrYjj_)zvDLYDtA6RSPttls$CTbHjMH|lDJ z5AD8+kcYafXIEVNS?{j9M$}#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Rzc_MHp-WyD7t>*A9-r;5ex6LCCNkO5;=LGLD16HIz|b+Sg~}p8L@{ zMA-xUD#qVn7?nM>@b!isvbWHb2`LUiR8orbg?1_GG)qyJk7!rVwN5A3{0b-Bv#HJs zp?b=Miyk)|t5EmVU>i8tgL*)yDtbVm=WiFjy=3`BET4$DZCO4M%O_&_L@b|(3Y@`)(Zv3w$yPsH+xNLQ9mL_;94d?J=l#PW$)K9P=08OtYP`9v(Ah~*Qpd?J=l z#PW%JLwzD2A?_#O2sjS<+X%S`G=W*>eIm}g5oalQ0IUY<^!y@TjlTGxBYu&7C*&9T zzN%kjth!%B=zvMm@9C_vo9F;_7m4!_(l`ogaBv}FhH~3;tIaV@-TkZZok}e;wQt|LdEeDQwB#9J z1Q-jNKn~mv?gOjAb6_iY9~}5<`mWqEr;o!+NLb;}8H=k%MaT+VtyP5l6<3E9Awzvw zh!qZ<9IkFrggl3|rw{E4nS)z5 zgXQ^OSou9T7!ZB{m*onvTp^Y# zL}%#8T_L~zMz}(DTdokx6>_p&Apy%3V!1+2zAK~-!|og~wv;PmIt-+GoK-5*>Nw5*@1YdAvun{s0TxrVxAuCg})-m^npqTEkscGQvssC*T&xZ*A2pj}Q0QbihhJzo1wDdOuy5cJv zvPN8BH|qo{-H1EwI(`D;P-~;!4%IgD_C@$$Fa{*R?O+Ai1h#|EB>&Ax{XT*T?Z0$$ xd7N4vj&q&r9uCD{SCD%+Zg=W>IOKm7f%0&?tMUz)f0uXQ{~wB_0|)>B diff --git a/src/index.js b/src/index.js index 29537e84..726e1c64 100644 --- a/src/index.js +++ b/src/index.js @@ -50,6 +50,7 @@ class DropdownTreeSelect extends Component { } static defaultProps = { + onAction: () => {}, onFocus: () => {}, onBlur: () => {}, onChange: () => {}, diff --git a/src/index.test.js b/src/index.test.js index b6700764..4ce73387 100644 --- a/src/index.test.js +++ b/src/index.test.js @@ -107,6 +107,15 @@ test('notifies on action', t => { t.true(handler.calledWithExactly(node0, action)) }) +test('notifies on action without onAction handler', t => { + const handler = spy(console, 'error') + const { tree } = t.context + const wrapper = mount() + wrapper.find('i.fa-ban').simulate('click') + t.true(handler.notCalled) + handler.restore() +}) + test('notifies on node toggle', t => { const handler = spy() const { tree } = t.context