2024-02-04 12:14:42 +01:00
|
|
|
import { expect } from 'chai'
|
2023-04-18 18:47:49 -04:00
|
|
|
import { Design } from '../src/index.mjs'
|
|
|
|
|
|
|
|
describe('Pattern Rendering', () => {
|
|
|
|
describe('Pattern.prototype.getRenderProps()', () => {
|
|
|
|
describe('Hidden parts and stacks', () => {
|
|
|
|
const part = {
|
|
|
|
name: 'test',
|
|
|
|
draft: ({ part }) => {
|
|
|
|
part.hide()
|
|
|
|
return part
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
const design = new Design({ parts: [part] })
|
feat(core): Added Pattern.getLogs() and updated Pattern.getRenderProps()
The data returned by `Pattern.getRenderProps()` was not serializable as
we were returning `this` all over the place, thereby including marcors,
log methods, cyclic object references, and so on.
This commit changes that by implementing a `.asRenderProp()` method on
all of the various objects (stack, part, path, point, snippet,
attributes, svg) and only including data that can be serialized.
In addition, we no longer include the logs in the renderProps because
they are not related to rendering the pattern.
Instead, the new method `Pattern.getLogs()` gives you the logs.
2023-06-01 16:45:13 +02:00
|
|
|
const pattern = new design({}).draft()
|
|
|
|
const props = pattern.getRenderProps()
|
|
|
|
const logs = pattern.getLogs()
|
2023-04-18 18:47:49 -04:00
|
|
|
|
|
|
|
it('Should not include hidden stacks', () => {
|
|
|
|
expect(props.stacks).not.to.have.property('test')
|
|
|
|
})
|
|
|
|
it('Should log that it has skipped a hidden stack', () => {
|
feat(core): Added Pattern.getLogs() and updated Pattern.getRenderProps()
The data returned by `Pattern.getRenderProps()` was not serializable as
we were returning `this` all over the place, thereby including marcors,
log methods, cyclic object references, and so on.
This commit changes that by implementing a `.asRenderProp()` method on
all of the various objects (stack, part, path, point, snippet,
attributes, svg) and only including data that can be serialized.
In addition, we no longer include the logs in the renderProps because
they are not related to rendering the pattern.
Instead, the new method `Pattern.getLogs()` gives you the logs.
2023-06-01 16:45:13 +02:00
|
|
|
expect(logs.pattern.info).to.include('Stack test is hidden. Skipping in render props.')
|
2023-04-18 18:47:49 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|