Skip to content

Commit

Permalink
CSCFAIRMETA-1076 refactor and clean up (#861)
Browse files Browse the repository at this point in the history
* - translationsRoot moved to mobx stores
- cleaned up some excessive Stores passing between components (FieldList, FieldListAdd, ModalContent, etc.)
- '@' alias added to webpack so that paths now can be written "@/stores"
- @ refers to ./js
* retry for pr
* fix for imports of locations tests
* regression test fix
* locations rename fix
updated ipdb to 0.13.9
* existing Locations in provenance missing translations fixed.
* cleanup
Co-authored-by: Jori Niemi <3295718+tahme@users.noreply.github.com>
  • Loading branch information
ismotee authored Sep 21, 2021
1 parent 2c687fe commit 0cc7cb3
Show file tree
Hide file tree
Showing 42 changed files with 258 additions and 308 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('Given modified provenance with added used entity', () => {
mockStores.Qvain.Provenances.clearInEdit()
})

test('Provenance should not have Used enitities', () => {
test('Provenance should not have Used entities', () => {
mockStores.Qvain.Provenances.storage.length.should.eql(1)
mockStores.Qvain.Provenances.storage[0].uiid.should.eql(uiid)
mockStores.Qvain.Provenances.storage[0].usedEntities.storage.length.should.eql(0)
Expand All @@ -39,14 +39,14 @@ describe('Given modified provenance with added location', () => {
mockStores.Qvain.Provenances.clearInEdit()
// then edit the provenance to add a new location
mockStores.Qvain.Provenances.edit(uiid)
mockStores.Qvain.Provenances.inEdit.spatials.create()
mockStores.Qvain.Provenances.inEdit.locations.create()
// cancel provennace
mockStores.Qvain.Provenances.clearInEdit()
})

test('Provenance should not have Locations', () => {
mockStores.Qvain.Provenances.storage.length.should.eql(1)
mockStores.Qvain.Provenances.storage[0].uiid.should.eql(uiid)
mockStores.Qvain.Provenances.storage[0].spatials.storage.length.should.eql(0)
mockStores.Qvain.Provenances.storage[0].locations.storage.length.should.eql(0)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ let Field = {
startDate: '1.1.2000',
endDate: '2.2.2020',
},
translationsRoot: 'translationsRoot',
changeAttribute: jest.fn(),
}

let translationsRoot = 'translationsRoot'
let datum = 'datum'
let id = 'id'

const expectedLabelContent = 'translationsRoot.modal.datumInput.label'

describe('DurationPicker', () => {
let wrapper
let props = { Field, translationsRoot, datum, id }
let props = { Field, datum, id }
const Stores = {
Qvain: {
readonly: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
import React from 'react'
import { shallow } from 'enzyme'
import 'chai/register-expect'
import { useStores } from '@/stores/stores'

import ModalContent from '../../../js/components/qvain/general/modal/modalContent'
import ModalContent from '@/components/qvain/general/modal/modalContent'
import ModalButtons from '../../../js/components/qvain/general/modal/modalButtons'
import { ConfirmClose } from '../../../js/components/qvain/general/modal/confirmClose'

jest.mock('@/stores/stores', () => {
return {
useStores: jest.fn(),
}
})
describe('ModalContent', () => {
let wrapper

const mockStores = {
Qvain: {
readonly: false,
},
}

const Form = () => <div id="form" />

const props = {
Store: { readonly: false },
Field: {},
Field: {
translationsRoot: 'translationsRoot',
},
Form,
formProps: { someProp: 'someProp' },
handleSave: jest.fn(),
translationsRoot: 'translationsRoot',
language: 'language',
onConfirmCancel: jest.fn(),
onConfirm: jest.fn(),
Expand All @@ -37,6 +49,7 @@ describe('ModalContent', () => {
})

const render = extraProps => {
useStores.mockReturnValue(mockStores)
const parsedProps = { ...props, ...extraProps }
wrapper = shallow(<ModalContent {...parsedProps} />)
}
Expand Down Expand Up @@ -88,10 +101,7 @@ describe('ModalContent', () => {

test('should have expectedProps', () => {
const expectedProps = {
Store: props.Store,
Field,
translationsRoot: props.translationsRoot,
language: props.language,
someProp: props.formProps.someProp,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Label } from '../../../js/components/qvain/general/modal/form'
describe('ModalInput', () => {
let wrapper

const Field = { changeAttribute: jest.fn(), inEdit: {} }
const Field = { changeAttribute: jest.fn(), inEdit: {}, translationsRoot: 'translationsRoot' }

const props = {
Field,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ const Field = {
inEdit: {
datum: {},
},
translationsRoot: 'translationsRoot',
}

const props = {
Field,
translationsRoot: 'translationsRoot',
datum: 'datum',
model: jest.fn(),
metaxIdentifier: 'metaxIdentifier',
Expand All @@ -26,8 +26,8 @@ describe('ModalRefenceInput', function () {
let wrapper

const getTranslations = props => ({
label: `${props.translationsRoot}.modal.${props.datum}Input.label`,
placeholder: `${props.translationsRoot}.modal.${props.datum}Input.placeholder`,
label: `${Field.translationsRoot}.modal.${props.datum}Input.label`,
placeholder: `${Field.translationsRoot}.modal.${props.datum}Input.placeholder`,
})

const render = extraProps => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ describe('TranslationsTabInputModal', () => {
Stores = buildStores()
Field = new FieldClass(Stores.Qvain, template, model)
Field.create()
Field.translationsRoot = 'translationsRoot'

props = {
Field,
datum: 'datum',
translationsRoot: 'translationsRoot',
language: 'en',
handleBlur: jest.fn(),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ describe('Provenance', () => {
schema: {
validate: jest.fn(),
},
translationsRoot: 'provenance translationsRoot',
associationsTranslationsRoot: 'qvain.history.provenance.modal.actorsInput',
},
},
Locale: {
Expand Down Expand Up @@ -105,12 +107,10 @@ describe('Provenance', () => {
FieldList: {
Field: mockStores.Qvain.Provenances,
lang: 'en',
translationsRoot: 'qvain.history.provenance',
},
FieldListAdd: {
Store: mockStores.Qvain,
Field: mockStores.Qvain.Provenances,
translationsRoot: 'qvain.history.provenance',
Form,
},
}
Expand Down Expand Up @@ -185,11 +185,13 @@ describe('given required props and mockStores', () => {
outcomeDescription: {
fi: 'fi-outcome',
},
spatials: {
locations: {
storage: [],
translationsRoot: 'locations translationsRoot',
},
usedEntities: {
storage: [],
translationsRoot: 'usedEntities translationsRoot',
},
associations: {
actorOptions: [],
Expand All @@ -209,9 +211,7 @@ describe('given required props and mockStores', () => {
}

const props = {
Store: mockStores.Qvain,
Field: mockStores.Qvain.Provenances,
translationsRoot: 'translationsRoot',
}

const harness = new Harness(Form, props)
Expand Down Expand Up @@ -316,26 +316,20 @@ describe('given required props and mockStores', () => {
{ label: 'LocationFieldListAdd', findArgs: FieldListAdd },
]

const translationsRoot = 'qvain.history.provenance.modal.locationInput'
const translationsRoot = 'locations translationsRoot'

const props = {
LocationLabel: {
content: `${translationsRoot}.label`,
htmlFor: 'location-input',
},
LocationFieldList: {
Store: mockStores.Qvain.Provenances,
Field: mockStores.Qvain.Provenances.inEdit.spatials,
fieldIdentifier: 'spatials',
lang: 'en',
translationsRoot,
Field: mockStores.Qvain.Provenances.inEdit.locations,
disableNoItemsText: true,
},
LocationFieldListAdd: {
Store: mockStores.Qvain.Provenances,
Field: mockStores.Qvain.Provenances.inEdit.spatials,
Field: mockStores.Qvain.Provenances.inEdit.locations,
Form: SpatialsForm,
translationsRoot,
position: 'left',
hideButton: false,
},
Expand All @@ -345,7 +339,7 @@ describe('given required props and mockStores', () => {
})
})

describe('LocationInput', () => {
describe('UsedEntityInput', () => {
beforeEach(() => {
harness.restoreWrapper('UsedEntityInput')
harness.dive()
Expand All @@ -358,26 +352,20 @@ describe('given required props and mockStores', () => {
{ label: 'UsedEntityFieldListAdd', findArgs: FieldListAdd },
]

const translationsRoot = 'qvain.history.provenance.modal.usedEntityInput'
const translationsRoot = 'usedEntities translationsRoot'

const props = {
UsedEntityLabel: {
content: `${translationsRoot}.label`,
htmlFor: 'used-entity-input',
},
UsedEntityFieldList: {
Store: mockStores.Qvain.Provenances,
Field: mockStores.Qvain.Provenances.inEdit.usedEntities,
fieldIdentifier: 'usedEntities',
lang: 'en',
translationsRoot: translationsRoot,
disableNoItemsText: true,
},
LocationFieldListAdd: {
Store: mockStores.Qvain.Provenances,
Field: mockStores.Qvain.Provenances.inEdit.usedEntities,
Form: UsedEntitiesForm,
translationsRoot: translationsRoot,
formProps: { hideRelationType: true },
position: 'left',
hideButton: false,
Expand All @@ -403,13 +391,11 @@ describe('given required props and mockStores', () => {
{ label: 'ActorsSelect', findType: 'prop', findArgs: ['component', ReactSelect] },
]

const { inEdit } = mockStores.Qvain.Provenances

const translationsRoot = 'qvain.history.provenance.modal.actorsInput'
const { inEdit, associationsTranslationsRoot } = mockStores.Qvain.Provenances

const expectedProps = {
ActorsLabel: {
content: `${translationsRoot}.label`,
content: `${associationsTranslationsRoot}.label`,
htmlFor: 'actors-input',
},
ActorsList: {
Expand All @@ -419,7 +405,7 @@ describe('given required props and mockStores', () => {
},
ActorsSelect: {
inputId: 'actors-select',
attributes: { placeholder: `${translationsRoot}.placeholder` },
attributes: { placeholder: `${associationsTranslationsRoot}.placeholder` },
options: [
{
label: createButtonTranslation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,8 @@ describe('given mockStores', () => {
const props = {
FieldList: {
Field: mockStores.Qvain.RelatedResources,
lang: 'en',
translationsRoot: mockStores.Qvain.RelatedResources.translationsRoot,
},
FieldListAdd: {
translationsRoot: mockStores.Qvain.RelatedResources.translationsRoot,
Store: mockStores.Qvain,
Field: mockStores.Qvain.RelatedResources,
Form,
handleSave,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ describe('given mockStore in useStores', () => {
const harness = new Harness(SpatialFieldContent)
const mockStores = {
Qvain: {
Spatials: {},
Spatials: {
translationsRoot: 'translationsRoot',
},
},
Locale: {
lang: 'en',
},
}
const translationsRoot = 'qvain.temporalAndSpatial.spatial'

describe('SpatialFieldContent', () => {
beforeEach(() => {
Expand All @@ -76,12 +77,9 @@ describe('given mockStore in useStores', () => {
const props = {
FieldList: {
Field: mockStores.Qvain.Spatials,
lang: mockStores.Locale.lang,
translationsRoot,
disableNoItemsText: false,
},
FieldListAdd: {
Store: mockStores.Qvain,
Field: mockStores.Qvain.Spatials,
Form: Form,
},
Expand All @@ -96,8 +94,8 @@ describe('given mockStore in useStores', () => {
harness.props.handleSave()
})

test('should call handleSave with Qvain.Spatials & translationsRoot', () => {
expect(handleSave).to.have.beenCalledWith(mockStores.Qvain.Spatials, translationsRoot)
test('should call handleSave with Qvain.Spatials', () => {
expect(handleSave).to.have.beenCalledWith(mockStores.Qvain.Spatials)
})
})
})
Expand Down
Loading

0 comments on commit 0cc7cb3

Please sign in to comment.