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

Commit

Permalink
(PC-1501): Change form direction when creating or updating offers
Browse files Browse the repository at this point in the history
  • Loading branch information
Akhilian committed Apr 3, 2019
1 parent 4414426 commit a5e3375
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 166 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 @@ -73,16 +73,15 @@ class RawOffer extends Component {
offer,
selectedOfferType,
} = nextProps
const { eventId, thingId } = offer || {}

const { eventId } = offer || {}

const isEdit = search.indexOf('modifie') > -1
const isNew = offerId === 'nouveau'
const isEventType = get(selectedOfferType, 'type') === 'Event' || eventId
const isReadOnly = !isNew && !isEdit

const apiPath = isEventType
? `events/${eventId || ''}`
: `things/${thingId || ''}`
const apiPath = isNew ? 'offers/' : `offers/${offerId}`

return {
apiPath,
Expand Down
273 changes: 117 additions & 156 deletions src/components/pages/Offer/tests/RawOffer.spec.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import React from 'react'
import { shallow } from 'enzyme'
import configureStore from 'redux-mock-store'

import RawOffer from '../RawOffer'
import MediationsManager from '../MediationsManager/index'
import { requestData } from 'redux-saga-data'

import { offerNormalizer } from 'utils/normalizers'
import { Form } from 'pass-culture-shared'

const dispatchMock = jest.fn()

Expand Down Expand Up @@ -41,6 +38,7 @@ describe('src | components | pages | Offer | RawOffer ', () => {
expect(wrapper).toMatchSnapshot()
})
})

describe('render', () => {
describe('MediationsManager', () => {
it("should be displayed when it's not a new offer", () => {
Expand Down Expand Up @@ -84,170 +82,133 @@ describe('src | components | pages | Offer | RawOffer ', () => {
expect(mediationsManagerComponent).toHaveLength(1)
})
})
})

describe('functions', () => {
describe('handleDataRequest', () => {
describe('When OfferId is not nouveau and venue is given', () => {
it('should first dispatch requestData when Main component is rendered', () => {
// given
const initialProps = {
location: {
search: '?lieu=AQ',
},
match: {
params: {
offerId: 'N9',
},
},
currentUser: {
isAdmin: false,
},
history: {
action: 'POP',
location: {
pathname: '/offres/N9',
search: '?lieu=AQ',
hash: '',
state: undefined,
key: 'c5cg3o',
},
},
query: {
parse: () => ({ lieu: 'AQ' }),
},
dispatch: dispatchMock,
offerers: [],
venues: [],
providers: [],
types: [],
}

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

const handleSuccess = jest.fn(() => {})

console.log('GET STATE in test', wrapper.state())
console.log('props in test', wrapper.props())

wrapper.props().handleDataRequest(handleSuccess)
const expectedRequestedGetTypes = {
keepComponentMounted: undefined,
type: 'CLOSE_MODAL',
}

const toto3 = {
config: {
apiPath: '/offers/N9',
method: 'GET',
normalizer: offerNormalizer,
stateKey: 'offers',
},
type: 'REQUEST_DATA_GET_OFFERS',
}

const toto4 = {
config: {
apiPath: '/offerers',
method: 'GET',
normalizer: {
managedVenues: 'venues',
},
describe('when creating a new offer', () => {
it('should create a new Thing when no offer type', () => {
// given
const initialProps = {
location: {
search: '?lieu=AQ',
},
match: {
params: {
offerId: 'nouveau',
},
type: 'REQUEST_DATA_GET_/OFFERERS',
}
},
currentUser: {
isAdmin: false,
},
query: {
parse: () => ({ lieu: 'AQ' }),
},
dispatch: dispatchMock,
venues: [],
}

const toto5 = {
config: {
apiPath: '/providers',
method: 'GET',
},
type: 'REQUEST_DATA_GET_/PROVIDERS',
}
// when
const wrapper = shallow(<RawOffer {...initialProps} />)

const toto6 = {
config: {
apiPath: '/types',
method: 'GET',
},
type: 'REQUEST_DATA_GET_/TYPES',
}

// then
expect(dispatchMock).toHaveBeenCalled()
expect(dispatchMock.mock.calls.length).toEqual(7)
expect(dispatchMock.mock.calls[0][0]).toEqual(
expectedRequestedGetTypes
)
expect(dispatchMock.mock.calls[1][0]).toEqual(
expectedRequestedGetTypes
)
expect(dispatchMock.mock.calls[2][0]).toEqual(
expectedRequestedGetTypes
)
expect(dispatchMock.mock.calls[3][0]).toEqual(toto3)
expect(dispatchMock.mock.calls[4][0]).toEqual(toto4)
expect(dispatchMock.mock.calls[5][0]).toEqual(toto5)
expect(dispatchMock.mock.calls[6][0]).toEqual(toto6)
})
})
describe.skip('When venueId', () => {
it('????', () => {
// query parse {lieu: "DY"}
// RawOffer.js:118 QQQQQQQQQQQ Venue Id DY
// RawOffer.js:119 QQQQQQQQQQQ OffererID undefined
// je créé un lieu et je peux ajouter une offre http://localhost:3001/offres/nouveau?lieu=DY
})
// then
expect(wrapper.find(Form).prop('action')).toEqual('offers/')
})
describe.skip('When OfferId is nouveau', () => {
// /offres/nouveau?structure=BU

// venueId est undefined // offererId = BU

it('should ', () => {
// given
const initialProps = {
location: {
search: '?structure=BU',
it('should create a new Event when event type given', () => {
// given
const initialProps = {
location: {
search: '?lieu=AQ',
},
match: {
params: {
offerId: 'nouveau',
},
}
},
currentUser: {
isAdmin: false,
},
query: {
parse: () => ({ lieu: 'AQ' }),
},
dispatch: dispatchMock,
venues: [],

// when
selectedOfferType: {
type: 'Event',
},
}

// then
})
})
describe('When no venue at all and new offer', () => {
it('should display modal', () => {
// query parse {}
// RawOffer.js:118 QQQQQQQQQQQ Venue Id undefined
// RawOffer.js:119 QQQQQQQQQQQ OffererID undefined
})
// when
const wrapper = shallow(<RawOffer {...initialProps} />)

// then
expect(wrapper.find(Form).prop('action')).toEqual('offers/')
})
describe('When one venue and new offer', () => {
it('???', () => {
// url : http://localhost:3001/offres/nouveau
// Venue Id undefined
// OffererID undefined

// given

const initialProps = {
history: {},
dispatch: dispatchMock,
match: {
params: { offerId: 'nouveau' },
})

describe('when updating the offer', () => {
it('should update a thing when no offer type', () => {
// given
const initialProps = {
location: {
search: '?lieu=AQ',
},
match: {
params: {
offerId: 'VAG',
},
offerers: [],
venues: [],
providers: [],
query: {
parse: () => ({}),
},
currentUser: {
isAdmin: false,
},
query: {
parse: () => ({ lieu: 'AQ' }),
},
dispatch: dispatchMock,
venues: [],
offer: {
thingId: 'V24',
},
}

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

// then
expect(wrapper.find(Form).prop('action')).toEqual('offers/VAG')
})

it('should create a new Event when event type given', () => {
// given
const initialProps = {
location: {
search: '?lieu=AQ',
},
match: {
params: {
offerId: 'VAG',
},
types: [],
}
})
},
currentUser: {
isAdmin: false,
},
query: {
parse: () => ({ lieu: 'AQ' }),
},
dispatch: dispatchMock,
venues: [],
selectedOfferType: {
type: 'Event',
},
offer: {
eventId: '6GD',
},
}

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

// then
expect(wrapper.find(Form).prop('action')).toEqual('offers/VAG')
})
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ ShallowWrapper {
<withRouter(Connect(_Form))
BlockComponent={null}
Tag="form"
action="things/"
action="offers/N9"
className={null}
errorsPatch={Object {}}
failNotification="Formulaire non validé"
Expand Down Expand Up @@ -251,7 +251,7 @@ ShallowWrapper {
<withRouter(Connect(_Form))
BlockComponent={null}
Tag="form"
action="things/"
action="offers/N9"
className={null}
errorsPatch={Object {}}
failNotification="Formulaire non validé"
Expand Down Expand Up @@ -451,7 +451,7 @@ ShallowWrapper {
"props": Object {
"BlockComponent": null,
"Tag": "form",
"action": "things/",
"action": "offers/N9",
"children": Array [
<div
className="field-group"
Expand Down Expand Up @@ -1172,7 +1172,7 @@ ShallowWrapper {
<withRouter(Connect(_Form))
BlockComponent={null}
Tag="form"
action="things/"
action="offers/N9"
className={null}
errorsPatch={Object {}}
failNotification="Formulaire non validé"
Expand Down Expand Up @@ -1359,7 +1359,7 @@ ShallowWrapper {
<withRouter(Connect(_Form))
BlockComponent={null}
Tag="form"
action="things/"
action="offers/N9"
className={null}
errorsPatch={Object {}}
failNotification="Formulaire non validé"
Expand Down Expand Up @@ -1559,7 +1559,7 @@ ShallowWrapper {
"props": Object {
"BlockComponent": null,
"Tag": "form",
"action": "things/",
"action": "offers/N9",
"children": Array [
<div
className="field-group"
Expand Down

0 comments on commit a5e3375

Please sign in to comment.