File tree Expand file tree Collapse file tree 2 files changed +33
-2
lines changed
tests/unit/amo/components Expand file tree Collapse file tree 2 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -90,12 +90,17 @@ export class AddonBase extends React.Component {
9090 }
9191 }
9292
93- componentWillReceiveProps ( { addon : newAddon } ) {
94- const { addon : oldAddon , dispatch } = this . props ;
93+ componentWillReceiveProps ( { addon : newAddon , params : newParams } ) {
94+ const { addon : oldAddon , dispatch, errorHandler, params } = this . props ;
95+
9596 const oldAddonType = oldAddon ? oldAddon . type : null ;
9697 if ( newAddon && newAddon . type !== oldAddonType ) {
9798 dispatch ( setViewContext ( newAddon . type ) ) ;
9899 }
100+
101+ if ( params . slug !== newParams . slug ) {
102+ dispatch ( fetchAddon ( { slug : newParams . slug , errorHandler } ) ) ;
103+ }
99104 }
100105
101106 componentWillUnmount ( ) {
Original file line number Diff line number Diff line change @@ -200,6 +200,32 @@ describe('Addon', () => {
200200 expect ( root . find ( AddonMeta ) . prop ( 'addon' ) ) . toEqual ( null ) ;
201201 } ) ;
202202
203+ it ( 'does not dispatch fetchAddon action when slug is the same' , ( ) => {
204+ const fakeDispatch = sinon . stub ( ) ;
205+ const errorHandler = createStubErrorHandler ( ) ;
206+ const addon = fakeAddon ;
207+ const root = shallowRender ( { addon, errorHandler, dispatch : fakeDispatch } ) ;
208+
209+ fakeDispatch . reset ( ) ;
210+ // Update with the same slug.
211+ root . setProps ( { params : { slug : addon . slug } } ) ;
212+
213+ sinon . assert . notCalled ( fakeDispatch ) ;
214+ } ) ;
215+
216+ it ( 'dispatches fetchAddon action when updating with a new slug' , ( ) => {
217+ const fakeDispatch = sinon . stub ( ) ;
218+ const errorHandler = createStubErrorHandler ( ) ;
219+ const root = shallowRender ( { errorHandler, dispatch : fakeDispatch } ) ;
220+ const slug = 'some-new-slug' ;
221+
222+ fakeDispatch . reset ( ) ;
223+ // Update with a new slug.
224+ root . setProps ( { params : { slug } } ) ;
225+
226+ sinon . assert . calledWith ( fakeDispatch , fetchAddonAction ( { errorHandler, slug } ) ) ;
227+ } ) ;
228+
203229 it ( 'renders an error if there is one' , ( ) => {
204230 const errorHandler = createStubErrorHandler ( new Error ( 'some error' ) ) ;
205231
You can’t perform that action at this time.
0 commit comments