Skip to content

Commit

Permalink
Better handling for classpecs reverted to source. Fixes #90
Browse files Browse the repository at this point in the history
  • Loading branch information
raffazizzi committed Mar 2, 2020
1 parent d9f61d6 commit 773a52c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/reducers/classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,10 @@ export function oddClasses(state, action) {
if (m.ident === action.name) {
const lCl = localsource.classes[action.classType].filter(cl => cl.ident === action.name)[0]
if (lCl) {
acc.push(clone(lCl))
const clonedLCl = clone(lCl)
clonedLCl._changed = ['all']
clonedLCl._revert = true
acc.push(clonedLCl)
}
} else {
acc.push(m)
Expand Down
5 changes: 5 additions & 0 deletions src/reducers/odd/processClassMemberships.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ export function processClassMemberships(specElement, specData, localData, change
classesEl.appendChild(mOf)
}
}
} else if (specData._revert && Boolean(specData._changed)) {
// remove customization element to return to source.
if (specElement.parentNode) {
specElement.parentNode.removeChild(specElement)
}
}
return odd
}
Expand Down
3 changes: 0 additions & 3 deletions test/reducers/classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,6 @@ describe('ODD class operations reducers', () => {
expect(firstState.odd.customization.json.classes.attributes.filter(
x => (x.ident === 'att.divLike')
)[0]._changed).toExist()
expect(state.odd.customization.json.classes.attributes.filter(
x => (x.ident === 'att.divLike')
)[0]._changed).toNotExist()
expect(state.odd.customization.json.classes.attributes.filter(
x => (x.ident === 'att.divLike')
)[0].attributes.filter(a => a.ident === 'org')[0]).toExist()
Expand Down
22 changes: 22 additions & 0 deletions test/reducers/updateOdd_classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,26 @@ describe('Update Customization classes (handles UPDATE_CUSTOMIZATION_ODD)', () =
xml = global.usejsdom(xml)
expect(xml.querySelector('classSpec[ident="att.global.linking"]')).toNotExist()
})

it('should revert a class to source (ie remove customization spec)', () => {
customJson = JSON.parse(customization)
localJson = JSON.parse(localsource)
const firstState = romajsApp({
odd: {
customization: { isFetching: false, json: customJson, xml: customizationXMLString },
localsource: { isFetching: false, json: localJson }
},
selectedOdd: ''
}, {
type: 'REVERT_CLASS_TO_SOURCE',
name: 'att.global',
classType: 'attributes'
})
const state = romajsApp(firstState, {
type: 'UPDATE_CUSTOMIZATION_ODD'
})
let xml = parser.parseFromString(state.odd.customization.updatedXml)
xml = global.usejsdom(xml)
expect(xml.querySelector('classRef[key="att.global"]')).toNotExist()
})
})

0 comments on commit 773a52c

Please sign in to comment.