Skip to content
This repository has been archived by the owner on Mar 10, 2022. It is now read-only.

Commit

Permalink
(PC-1501): Fix redirection to next step
Browse files Browse the repository at this point in the history
  • Loading branch information
Akhilian committed Apr 8, 2019
1 parent a5e3375 commit e6de1b1
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/components/pages/Offer/RawOffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,16 @@ class RawOffer extends Component {
config: { method },
payload,
} = action
const { history, offer, venue } = this.props
const eventOrThing = payload.datum

const { history } = this.props
const offer = payload.datum

if (method === 'PATCH') {
history.push(`/offres/${offer.id}`)
return
}

if (method === 'POST') {
const { offers } = eventOrThing || {}
const offer = offers && offers.find(o => o.venueId === get(venue, 'id'))
if (!offer) {
console.warn(
'Something wrong with returned data, we should retrieve the created offer here'
Expand Down
74 changes: 74 additions & 0 deletions src/components/pages/Offer/tests/RawOffer.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,80 @@ describe('src | components | pages | Offer | RawOffer ', () => {
})
})

describe('handleSuccess', () => {
describe('when the offer is successfully modified', () => {
it('should redirect to offer page', () => {
// given
const historyPush = jest.fn()
const initialProps = {
location: {
search: '?lieu=AQ',
},
match: {
params: {},
},
currentUser: {
isAdmin: false,
},
query: {
parse: () => ({ lieu: 'AQ' }),
},
dispatch: dispatchMock,
history: {
push: historyPush,
},
}

const wrapper = shallow(<RawOffer {...initialProps} />)

// when
let offre = { id: 'SN' }
let action = { config: { method: 'PATCH' }, payload: { datum: offre } }
wrapper.instance().handleSuccess({}, action)

// then
expect(historyPush).toHaveBeenCalledWith('/offres/SN')
})
})

describe('when the offer is successfully modified', () => {
it('should redirect to gestion page', () => {
// given
const historyPush = jest.fn()
const initialProps = {
location: {
search: '?lieu=AQ',
},
match: {
params: {
offerId: 'nouveau',
},
},
currentUser: {
isAdmin: false,
},
query: {
parse: () => ({ lieu: 'AQ' }),
},
dispatch: dispatchMock,
history: {
push: historyPush,
},
}

const wrapper = shallow(<RawOffer {...initialProps} />)

// when
let offre = { id: 'SN' }
let action = { config: { method: 'POST' }, payload: { datum: offre } }
wrapper.instance().handleSuccess({}, action)

// then
expect(historyPush).toHaveBeenCalledWith('/offres/SN?gestion')
})
})
})

describe('render', () => {
describe('MediationsManager', () => {
it("should be displayed when it's not a new offer", () => {
Expand Down

0 comments on commit e6de1b1

Please sign in to comment.