Skip to content

Commit

Permalink
Merge pull request #7 from mamhoff/add-get-sanitized-ingredient
Browse files Browse the repository at this point in the history
Add element.getRichtext(name) method
  • Loading branch information
mamhoff authored Mar 29, 2021
2 parents 90cd735 + 4c3551d commit 5aa5bd0
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/mixins/__tests__/element.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,52 @@ describe("Alchemy element mixin", () => {
})
})

describe("getRichtext", () => {
describe("if essence does not exist", () => {
it("returns undefined", () => {
const comp = shallowMount(AlchemyElementComponent, {
propsData: {
element: {
name: "content_page",
essences: [],
},
},
})
expect(comp.vm.getRichtext("foo")).toBeUndefined()
})
})

describe("if essence with sanitized_body exists", () => {
it("returns the essences ingredient", () => {
const headline = { role: "headline", sanitized_body: "The Headline" }
const comp = shallowMount(AlchemyElementComponent, {
propsData: {
element: {
name: "content_page",
essences: [headline],
},
},
})
expect(comp.vm.getRichtext("headline")).toEqual("The Headline")
})
})

describe("if essence with body and no sanitized body exists", () => {
it("returns the essences ingredient", () => {
const headline = { role: "headline", body: "<h1>The Headline</h1>" }
const comp = shallowMount(AlchemyElementComponent, {
propsData: {
element: {
name: "content_page",
essences: [headline],
},
},
})
expect(comp.vm.getRichtext("headline")).toEqual("<h1>The Headline</h1>")
})
})
})

describe("focusAlchemyElement", () => {
describe("if id matches elements id", () => {
it.skip("scrolls element into view", () => {
Expand Down
3 changes: 3 additions & 0 deletions src/mixins/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export default {
getIngredient(name) {
return this.getEssence(name).ingredient
},
getRichtext(name) {
return this.getEssence(name).sanitized_body || this.getEssence(name).body
},
getEssence(name) {
return this.element.essences.find((e) => e.role === name) || {}
},
Expand Down

0 comments on commit 5aa5bd0

Please sign in to comment.