/**
* Tests for wrapCellsInModel: the model may send only the mxCell elements of
* a page, like in the web app, and the server adds the wrapper and root cells.
*/
import { beforeAll, describe, expect, it } from "vitest"
import { installDomPolyfill } from "../src/dom.js"
beforeAll(() => {
installDomPolyfill()
})
import { wrapCellsInModel } from "../src/pages.js"
import { validateAndFixXml } from "../src/xml-validation.js"
const A = ``
const B = ``
const ROOTS = ``
describe("wrapCellsInModel", () => {
it("wraps sibling cells so they pass validation", () => {
expect(validateAndFixXml(A + B).valid).toBe(false)
const wrapped = wrapCellsInModel(A + B)
expect(wrapped).toBe(
`${ROOTS}${A}${B}`,
)
expect(validateAndFixXml(wrapped).valid).toBe(true)
})
it("replaces root cells the model wrote itself", () => {
const wrapped = wrapCellsInModel(
`${A}`,
)
expect(wrapped.match(/id="0"/g)).toHaveLength(1)
expect(wrapped.match(/id="1"/g)).toHaveLength(1)
expect(wrapped).toContain(A)
})
it("unwraps a and drops trailing provider tags", () => {
const wrapped = wrapCellsInModel(
`${A}`,
)
expect(wrapped).toBe(
`${ROOTS}${A}`,
)
})
it("leaves and input unchanged", () => {
const model = `${ROOTS}${A}`
const file = `${model}`
expect(wrapCellsInModel(model)).toBe(model)
expect(wrapCellsInModel(file)).toBe(file)
})
it("keeps a UserObject cell at the end", () => {
const wrapped = ``
expect(wrapCellsInModel(A + wrapped)).toContain(wrapped)
expect(wrapCellsInModel(`${wrapped}`)).toBe(
`${ROOTS}${wrapped}`,
)
})
})