1
0
Fork 0

wip(core): Work on part unit tests

This commit is contained in:
joostdecock 2022-09-10 16:00:43 +02:00
parent 904e0044c5
commit cf0c70f4c6
4 changed files with 165 additions and 320 deletions

View file

@ -6,24 +6,25 @@ import { Snippet } from './snippet.mjs'
import { Hooks } from './hooks.mjs'
export function Part() {
// Non-enumerable properties
utils.addNonEnumProp(this, 'freeId', 0)
utils.addNonEnumProp(this, 'topLeft', false)
utils.addNonEnumProp(this, 'bottomRight', false)
utils.addNonEnumProp(this, 'width', false)
utils.addNonEnumProp(this, 'height', false)
utils.addNonEnumProp(this, 'utils', utils)
utils.addNonEnumProp(this, 'layout', { move: { x: 0, y: 0 } })
utils.addNonEnumProp(this, 'Point', Point)
utils.addNonEnumProp(this, 'Path', Path)
utils.addNonEnumProp(this, 'Snippet', Snippet)
utils.addNonEnumProp(this, 'hooks', new Hooks())
// Enumerable properties
this.render = true // FIXME: Replace render with hide
this.attributes = new Attributes()
this.points = {}
this.paths = {}
this.snippets = {}
this.freeId = 0
this.topLeft = false
this.bottomRight = false
this.width = false
this.height = false
this.render = true
this.utils = utils
this.layout = { move: { x: 0, y: 0 } }
this.cut = { grain: 90, materials: {} }
this.Point = Point
this.Path = Path
this.Snippet = Snippet
this.hooks = new Hooks() // Hooks container
return this
}
@ -59,8 +60,8 @@ Part.prototype.getId = function (prefix = '') {
Part.prototype.unitsClosure = function (value) {
const self = this
const method = function (value) {
if (self.context.settings.debug && typeof value !== 'number')
self.context.raise.debug(
if (typeof value !== 'number')
self.context.store.log.warning(
`Calling \`units(value)\` but \`value\` is not a number (\`${typeof value}\`)`
)
return utils.units(value, self.context.settings.units)
@ -85,8 +86,8 @@ Part.prototype.boundary = function () {
if (path.bottomRight.y > bottomRight.y) bottomRight.y = path.bottomRight.y
}
} catch (err) {
this.context.raise.error(`Could not calculate boundary of \`paths.${key}\``)
this.context.raise.debug(
this.context.store.log.error(`Could not calculate boundary of \`paths.${key}\``)
this.context.store.log.debug(
`Since \`paths.${key}\` has no boundary, neither does \`parts.${this.name}\`. Ejecting part`
)
return false
@ -180,12 +181,12 @@ Part.prototype.units = function (input) {
/** Returns an object with shorthand access for pattern design */
Part.prototype.shorthand = function () {
const complete = this.context.settings.complete ? true : false
const paperless = this.context.settings.paperless === true ? true : false
const sa = this.context.settings.complete ? this.context.settings.sa || 0 : 0
const complete = this.context.settings?.complete ? true : false
const paperless = this.context.settings?.paperless === true ? true : false
const sa = this.context.settings?.complete ? this.context.settings?.sa || 0 : 0
const shorthand = {
sa,
scale: this.context.settings.scale,
scale: this.context.settings?.scale,
store: this.context.store,
macro: this.macroClosure(),
units: this.unitsClosure(),
@ -193,7 +194,7 @@ Part.prototype.shorthand = function () {
complete,
paperless,
events: this.context.events,
raise: this.context.raise,
log: this.context.store.log,
addCut: this.addCut,
removeCut: this.removeCut,
}
@ -209,23 +210,23 @@ Part.prototype.shorthand = function () {
// We'll need this
let self = this
// Wrap the Point constructor so objects can raise events
// Wrap the Point constructor so objects can log
shorthand.Point = function (x, y) {
Point.apply(this, [x, y, true])
Object.defineProperty(this, 'raise', { value: self.context.raise })
Object.defineProperty(this, 'log', { value: self.context.store.log })
}
shorthand.Point.prototype = Object.create(Point.prototype)
// Wrap the Path constructor so objects can raise events
// Wrap the Path constructor so objects can log
shorthand.Path = function () {
Path.apply(this, [true])
Object.defineProperty(this, 'raise', { value: self.context.raise })
Object.defineProperty(this, 'log', { value: self.context.store.log })
}
shorthand.Path.prototype = Object.create(Path.prototype)
// Wrap the Snippet constructor so objects can raise events
// Wrap the Snippet constructor so objects can log
shorthand.Snippet = function (def, anchor) {
Snippet.apply(this, [def, anchor, true])
Snippet.apply(this, arguments)
Object.defineProperty(this, 'raise', { value: self.context.raise })
Object.defineProperty(this, 'log', { value: self.context.store.log })
}
shorthand.Snippet.prototype = Object.create(Snippet.prototype)
@ -237,21 +238,21 @@ Part.prototype.shorthand = function () {
set: (points, name, value) => {
// Constructor checks
if (value instanceof Point !== true)
self.context.raise.warning(
self.context.store.log.warning(
`\`points.${name}\` was set with a value that is not a \`Point\` object`
)
if (value.x == null || !utils.isCoord(value.x))
self.context.raise.warning(
self.context.store.log.warning(
`\`points.${name}\` was set with a \`x\` parameter that is not a \`number\``
)
if (value.y == null || !utils.isCoord(value.y))
self.context.raise.warning(
self.context.store.log.warning(
`\`points.${name}\` was set with a \`y\` parameter that is not a \`number\``
)
try {
value.name = name
} catch (err) {
self.context.raise.warning(`Could not set \`name\` property on \`points.${name}\``)
self.context.store.log.warning(`Could not set \`name\` property on \`points.${name}\``)
}
return (self.points[name] = value)
},
@ -265,13 +266,13 @@ Part.prototype.shorthand = function () {
set: (paths, name, value) => {
// Constructor checks
if (value instanceof Path !== true)
self.context.raise.warning(
self.context.store.log.warning(
`\`paths.${name}\` was set with a value that is not a \`Path\` object`
)
try {
value.name = name
} catch (err) {
self.context.raise.warning(`Could not set \`name\` property on \`paths.${name}\``)
self.context.store.log.warning(`Could not set \`name\` property on \`paths.${name}\``)
}
return (self.paths[name] = value)
},
@ -285,21 +286,21 @@ Part.prototype.shorthand = function () {
set: (snippets, name, value) => {
// Constructor checks
if (value instanceof Snippet !== true)
self.context.raise.warning(
self.context.store.log.warning(
`\`snippets.${name}\` was set with a value that is not a \`Snippet\` object`
)
if (typeof value.def !== 'string')
self.context.raise.warning(
self.context.store.log.warning(
`\`snippets.${name}\` was set with a \`def\` parameter that is not a \`string\``
)
if (value.anchor instanceof Point !== true)
self.context.raise.warning(
self.context.store.log.warning(
`\`snippets.${name}\` was set with an \`anchor\` parameter that is not a \`Point\``
)
try {
value.name = name
} catch (err) {
self.context.raise.warning(`Could not set \`name\` property on \`snippets.${name}\``)
self.context.store.log.warning(`Could not set \`name\` property on \`snippets.${name}\``)
}
return (self.snippets[name] = value)
},
@ -309,7 +310,7 @@ Part.prototype.shorthand = function () {
const measurementsProxy = {
get: function (measurements, name) {
if (typeof measurements[name] === 'undefined')
self.context.raise.warning(
self.context.store.log.warning(
`Tried to access \`measurements.${name}\` but it is \`undefined\``
)
return Reflect.get(...arguments)
@ -321,7 +322,7 @@ Part.prototype.shorthand = function () {
const optionsProxy = {
get: function (options, name) {
if (typeof options[name] === 'undefined')
self.context.raise.warning(`Tried to access \`options.${name}\` but it is \`undefined\``)
self.context.store.log.warning(`Tried to access \`options.${name}\` but it is \`undefined\``)
return Reflect.get(...arguments)
},
set: (options, name, value) => (self.context.settings.options[name] = value),
@ -331,7 +332,7 @@ Part.prototype.shorthand = function () {
const absoluteOptionsProxy = {
get: function (absoluteOptions, name) {
if (typeof absoluteOptions[name] === 'undefined')
self.context.raise.warning(
self.context.store.log.warning(
`Tried to access \`absoluteOptions.${name}\` but it is \`undefined\``
)
return Reflect.get(...arguments)

View file

@ -1,145 +0,0 @@
import chai from 'chai'
import { Design } from '../src/index.mjs'
import { pluginBundle } from '@freesewing/plugin-bundle'
const expect = chai.expect
const fabricLines = {
name: 'legend.fabricLines',
plugins: pluginBundle,
draft: legendFabricLines,
}
const lineStrokes = {
name: 'legend.lineStrokes',
plugins: pluginBundle,
//after: fabricLines,
draft: legendLineStrokes,
}
const lineWidths = {
name: 'legend.lineWidths',
plugins: pluginBundle,
//from: lineStrokes,
draft: legendLineWidths,
options: {
waistEase: { pct: 12, min: 0, max: 100 },
},
}
const saLines = {
name: 'legend.saLines',
plugins: pluginBundle,
draft: legendSaLines,
}
const otherLines = {
name: 'legend.otherLines',
plugins: pluginBundle,
draft: legendOtherLines,
}
const parts = [otherLines, saLines, fabricLines, lineStrokes, lineWidths]
describe('Design', () => {
it('FIXME', () => {
const Pattern = new Design({
data: { foo: 'bar' },
parts,
})
const pattern = new Pattern({
paperless: true,
})
pattern.init()
//console.log('plugins:', pattern.config.plugins)
})
})
const allFabricTypes = ['fabric', 'lining', 'canvas', 'interfacing', 'various']
const allLineTypes = ['note', 'mark', 'contrast', 'help']
const allLineStrokes = ['dotted', 'dashed', 'lashed']
const allLineWidths = ['stroke-xs', 'stroke-sm', 'default', 'stroke-lg', 'stroke-xl', 'stroke-xxl']
function legendFabricLines(part) {
let y = 10
for (const t of allFabricTypes) {
drawLine(part, y, t)
y += 15
}
return box(part, 120, 65)
}
function legendLineStrokes(part) {
let y = 10
for (const t of allLineStrokes) {
drawLine(part, y, t)
y += 15
}
return box(part, 120, 50)
}
function legendLineWidths(part) {
let y = 10
for (const t of allLineWidths) {
drawLine(part, y, t)
y += 15
}
return box(part, 120, 95)
}
function legendSaLines(part) {
let y = 10
for (const t of allFabricTypes) {
drawLine(part, y, t + ' sa')
y += 15
}
return box(part, 120, 65)
}
function legendOtherLines(part) {
const { points, Point, paths, Path } = part.shorthand()
const drawLine = (y, t) => {
points[`${t}From`] = new Point(10, y)
points[`${t}To`] = new Point(w, y)
paths[t] = new Path()
.move(points[`${t}From`])
.line(points[`${t}To`])
.attr('class', t)
.attr('data-text', t)
.attr('data-text-class', 'center')
}
let y = 10
let w = 110
for (const t of allLineTypes) {
drawLine(y, t)
y += 15
}
return box(part, 120, 65)
}
function box(part, w = 100, h = 50) {
part.paths.box = new part.Path()
.move(new part.Point(0, 0))
.line(new part.Point(w, h))
.attr('class', 'hidden')
return part
}
function drawLine(part, y, t) {
let { points, Point, paths, Path } = part.shorthand()
points[`${t}From`] = new Point(10, y)
points[`${t}To`] = new Point(110, y)
paths[t] = new Path()
.move(points[`${t}From`])
.line(points[`${t}To`])
.attr('class', t)
.attr('data-text', t)
.attr('data-text-class', 'center')
return part
}

View file

@ -1,38 +1,26 @@
import chai from 'chai'
import { Pattern, Path } from '../src/index.mjs'
import { Design, Pattern, Path } from '../src/index.mjs'
const expect = chai.expect
describe('Part', () => {
it('Svg constructor should initialize object', () => {
let pattern = new Pattern()
let part = new pattern.Part()
expect(part.paths).to.eql({})
expect(part.snippets).to.eql({})
expect(part.freeId).to.equal(0)
expect(part.topLeft).to.equal(false)
expect(part.bottomRight).to.equal(false)
expect(part.width).to.equal(false)
expect(part.height).to.equal(false)
expect(part.render).to.equal(true)
})
it('Should return a function from macroClosure', () => {
let pattern = new Pattern()
let part = new pattern.Part()
const pattern = new Pattern()
const part = pattern.__createPartWithContext()
expect(typeof part.macroClosure()).to.equal('function')
})
it('Should not run an unknown macro', () => {
let pattern = new Pattern()
let part = new pattern.Part()
let macro = part.macroClosure()
const pattern = new Pattern()
const part = pattern.__createPartWithContext()
const macro = part.macroClosure()
expect(macro('unknown')).to.equal(undefined)
})
it('Should register and run a macro', () => {
let pattern = new Pattern()
let plugin = {
const pattern = new Pattern()
const plugin = {
name: 'test',
version: '0.1-test',
macros: {
@ -43,37 +31,38 @@ describe('Part', () => {
},
}
pattern.use(plugin)
let part = new pattern.Part()
let macro = part.macroClosure()
const part = pattern.__createPartWithContext()
const macro = part.macroClosure()
macro('test', { x: 123, y: 456 })
expect(part.points.macro.x).to.equal(123)
expect(part.points.macro.y).to.equal(456)
})
it('Should return a free ID', () => {
let pattern = new Pattern()
let part = new pattern.Part()
let free = part.getId()
const pattern = new Pattern()
const part = pattern.__createPartWithContext()
const free = part.getId()
expect(part.getId()).to.equal('' + (parseInt(free) + 1))
})
it('Should return a function from unitsClosure', () => {
let pattern = new Pattern()
let part = new pattern.Part()
const pattern = new Pattern()
const part = pattern.__createPartWithContext()
expect(typeof part.unitsClosure()).to.equal('function')
})
it('Should convert units', () => {
let pattern = new Pattern()
let part = new pattern.Part()
let units = part.unitsClosure()
const design = new Design()
const pattern = new design()
const part = pattern.__createPartWithContext()
const units = part.unitsClosure()
expect(units(123.456)).to.equal('12.35cm')
expect(part.units(123.456)).to.equal('12.35cm')
})
it('Should set part attributes', () => {
let pattern = new Pattern()
let part = new pattern.Part()
const pattern = new Pattern()
const part = pattern.__createPartWithContext()
part.attr('foo', 'bar')
expect(part.attributes.get('foo')).to.equal('bar')
part.attr('foo', 'baz')
@ -82,83 +71,50 @@ describe('Part', () => {
expect(part.attributes.get('foo')).to.equal('schmoo')
})
it('Should inject a part', () => {
let pattern = new Pattern()
let part = new pattern.Part()
part.points.a = new part.Point(12, 23)
part.points.b = new part.Point(10, 10)
part.points.c = new part.Point(20, 20)
part.paths.bar = new Path()
.move(part.points.a)
.line(part.points.b)
.curve(part.points.c, part.points.b, part.points.a)
const { Snippet, snippets } = part.shorthand()
snippets.d = new Snippet('notch', part.points.a)
let test = new pattern.Part()
test.inject(part)
expect(test.points.a.x).to.equal(12)
expect(test.points.a.y).to.equal(23)
expect(test.paths.bar.ops.length).to.equal(3)
for (let i = 0; i < 3; i++) {
expect(test.paths.bar.ops[i].type).to.equal(part.paths.bar.ops[i].type)
expect(test.paths.bar.ops[i].to.x).to.equal(part.paths.bar.ops[i].to.x)
expect(test.paths.bar.ops[i].to.y).to.equal(part.paths.bar.ops[i].to.y)
}
expect(test.snippets.d.anchor.x).to.equal(part.points.a.x)
expect(test.snippets.d.anchor.y).to.equal(part.points.a.y)
})
it('Should return shorthand', () => {
let pattern = new Pattern()
pattern.settings.mode = 'draft'
pattern.settings.paperless = true
let part = new pattern.Part()
let short = part.shorthand()
expect(short.complete).to.equal(true)
expect(short.paperless).to.equal(true)
})
it('Should raise a warning when setting a non-Point value in points', () => {
const pattern = new Pattern()
pattern.settings.mode = 'draft'
const part = new pattern.Part()
const design = new Design()
const pattern = new design()
const part = pattern.__createPartWithContext()
pattern.init()
const { points } = part.shorthand()
points.a = 'banana'
expect(pattern.events.warning.length).to.equal(4)
expect(pattern.events.warning[0]).to.equal(
expect(pattern.store.logs.warning.length).to.equal(4)
expect(pattern.store.logs.warning[0]).to.equal(
'`points.a` was set with a value that is not a `Point` object'
)
expect(pattern.events.warning[1]).to.equal(
expect(pattern.store.logs.warning[1]).to.equal(
'`points.a` was set with a `x` parameter that is not a `number`'
)
expect(pattern.events.warning[2]).to.equal(
expect(pattern.store.logs.warning[2]).to.equal(
'`points.a` was set with a `y` parameter that is not a `number`'
)
})
it('Should raise a warning when setting a non-Snippet value in snippets', () => {
const pattern = new Pattern()
pattern.settings.mode = 'draft'
const part = new pattern.Part()
const design = new Design()
const pattern = new design()
const part = pattern.__createPartWithContext()
pattern.init()
const { snippets } = part.shorthand()
snippets.a = 'banana'
expect(pattern.events.warning.length).to.equal(4)
expect(pattern.events.warning[0]).to.equal(
expect(pattern.store.logs.warning.length).to.equal(4)
expect(pattern.store.logs.warning[0]).to.equal(
'`snippets.a` was set with a value that is not a `Snippet` object'
)
expect(pattern.events.warning[1]).to.equal(
expect(pattern.store.logs.warning[1]).to.equal(
'`snippets.a` was set with a `def` parameter that is not a `string`'
)
expect(pattern.events.warning[2]).to.equal(
expect(pattern.store.logs.warning[2]).to.equal(
'`snippets.a` was set with an `anchor` parameter that is not a `Point`'
)
})
it('Should calculate the part boundary with default margin', () => {
let pattern = new Pattern()
pattern.settings.mode = 'draft'
let part = new pattern.Part()
let short = part.shorthand()
const design = new Design()
const pattern = new design()
const part = pattern.__createPartWithContext()
pattern.init()
const short = part.shorthand()
part.points.from = new short.Point(123, 456)
part.points.to = new short.Point(19, 76)
part.paths.test = new short.Path().move(part.points.from).line(part.points.to)
@ -173,11 +129,11 @@ describe('Part', () => {
})
it('Should calculate the part boundary with custom margin', () => {
let pattern = new Pattern()
pattern.settings.mode = 'draft'
pattern.settings.margin = 5
let part = new pattern.Part()
let short = part.shorthand()
const design = new Design()
const pattern = new design({ margin: 5 })
const part = pattern.__createPartWithContext()
pattern.init()
const short = part.shorthand()
part.points.from = new short.Point(123, 456)
part.points.to = new short.Point(19, 76)
part.paths.test = new short.Path().move(part.points.from).line(part.points.to)
@ -192,12 +148,11 @@ describe('Part', () => {
})
it('Should calculate the part boundary for paperless', () => {
let pattern = new Pattern()
pattern.settings.mode = 'draft'
pattern.settings.margin = 5
pattern.settings.paperless = true
let part = new pattern.Part()
let short = part.shorthand()
const design = new Design()
const pattern = new design({ paperless: true })
const part = pattern.__createPartWithContext()
pattern.init()
const short = part.shorthand()
part.points.from = new short.Point(123, 456)
part.points.to = new short.Point(19, 76)
part.paths.test = new short.Path().move(part.points.from).line(part.points.to)
@ -210,16 +165,23 @@ describe('Part', () => {
expect(boundary.width).to.equal(124)
expect(boundary.height).to.equal(400)
})
/*
it('Should stack a part', () => {
let pattern = new Pattern()
pattern.settings.mode = 'draft'
let part = new pattern.Part()
let short = part.shorthand()
part.points.from = new short.Point(123, 456)
part.points.to = new short.Point(19, 76)
part.paths.test = new short.Path().move(part.points.from).line(part.points.to)
part.stack()
const part = {
name: 'test',
draft: (part) => {
const { points, Point, paths, Path } = part.shorthand()
points.from = new Point(123, 456)
points.to = new Point(19, 76)
paths.test = new Path().move(points.from).line(points.to)
return aprt
}
}
const design = new Design({ parts: [ part ]})
const pattern = new design({ paperless: true })
pattern.draft()
pattern.parts.test.stack()
console.log(pattern.parts.test.attributes)
expect(part.attributes.get('transform')).to.equal('translate(-17, -74)')
})
@ -236,11 +198,12 @@ describe('Part', () => {
part.stack()
expect(part.attributes.get('transform')).to.equal(false)
})
*/
it('Should run hooks', () => {
let count = 0
const pattern = new Pattern()
const part = new pattern.Part()
const design = new Design()
const pattern = new design({ paperless: true })
const part = pattern.__createPartWithContext()
part.hooks.preDraft = [
{
method: function (p) {
@ -253,22 +216,23 @@ describe('Part', () => {
})
it('Should get the units closure to raise a debug when passing a non-number', () => {
const pattern = new Pattern()
pattern.settings.mode = 'draft'
pattern.settings.debug = true
const part = new pattern.Part()
const design = new Design()
const pattern = new design({ margin: 5 })
const part = pattern.__createPartWithContext()
pattern.init()
const short = part.shorthand()
short.units('a')
expect(pattern.events.debug.length).to.equal(1)
expect(pattern.events.debug[0]).to.equal(
expect(pattern.store.logs.warning.length).to.equal(1)
expect(pattern.store.logs.warning[0]).to.equal(
'Calling `units(value)` but `value` is not a number (`string`)'
)
})
it('Should generate the part transforms', () => {
let pattern = new Pattern()
pattern.settings.mode = 'draft'
let part = new pattern.Part()
const design = new Design()
const pattern = new design({ margin: 5 })
const part = pattern.__createPartWithContext()
pattern.init()
let short = part.shorthand()
part.points.from = new short.Point(2, 2)
part.points.to = new short.Point(19, 76)
@ -283,33 +247,36 @@ describe('Part', () => {
expect(part.attributes.list.transform.length).to.equal(1)
expect(part.attributes.list.transform[0]).to.equal('translate(10 20)')
})
describe('isEmpty', () => {
it('Should return true if the part has no paths or snippets', () => {
let pattern = new Pattern()
let part = new pattern.Part()
const design = new Design()
const pattern = new design()
const part = pattern.__createPartWithContext()
expect(part.isEmpty()).to.be.true
})
it('Should return true if the part has paths but they have no length', () => {
let pattern = new Pattern()
let part = new pattern.Part()
const design = new Design()
const pattern = new design()
const part = pattern.__createPartWithContext()
const { Path, paths, Point } = part.shorthand()
paths.seam = new Path()
expect(part.isEmpty()).to.be.true
})
it("Should return true if the part has paths but they don't render", () => {
let pattern = new Pattern()
let part = new pattern.Part()
const design = new Design()
const pattern = new design()
const part = pattern.__createPartWithContext()
const { Path, paths, Point } = part.shorthand()
paths.seam = new Path().move(new Point(0, 0)).line(new Point(2, 3)).setRender(false)
expect(part.isEmpty()).to.be.true
})
it('Should return false if the part has a path with length', () => {
let pattern = new Pattern()
let part = new pattern.Part()
const design = new Design()
const pattern = new design()
const part = pattern.__createPartWithContext()
const { Path, paths, Point } = part.shorthand()
paths.seam = new Path().move(new Point(0, 0)).line(new Point(2, 3))
@ -317,8 +284,9 @@ describe('Part', () => {
})
it('Should return false if the part has a snippet', () => {
let pattern = new Pattern()
let part = new pattern.Part()
const design = new Design()
const pattern = new design()
const part = pattern.__createPartWithContext()
const { Point, snippets, Snippet } = part.shorthand()
snippets.test = new Snippet('test', new Point(0, 0))
@ -326,8 +294,9 @@ describe('Part', () => {
})
it('Should return false if the part has a point that has text', () => {
let pattern = new Pattern()
let part = new pattern.Part()
const design = new Design()
const pattern = new design()
const part = pattern.__createPartWithContext()
const { Point, points } = part.shorthand()
points.test = new Point(0, 0)
points.test.attributes.set('data-text', 'text')
@ -335,8 +304,9 @@ describe('Part', () => {
})
it('Should return false if the part has a point that has a circle', () => {
let pattern = new Pattern()
let part = new pattern.Part()
const design = new Design()
const pattern = new design()
const part = pattern.__createPartWithContext()
const { Point, points } = part.shorthand()
points.test = new Point(0, 0)
points.test.attributes.set('data-circle', 10)

View file

@ -646,7 +646,26 @@ describe('Pattern', () => {
const pattern = new Pattern()
const part = pattern.__createPartWithContext('test')
expect(typeof part.context).to.equal('object')
expect(typeof part.context.parts).to.equal('object')
expect(typeof part.context.config).to.equal('object')
expect(typeof part.context.config.options).to.equal('object')
expect(typeof part.context.config.data).to.equal('object')
expect(Array.isArray(part.context.config.measurements)).to.equal(true)
expect(Array.isArray(part.context.config.optionalMeasurements)).to.equal(true)
expect(Array.isArray(part.context.config.parts)).to.equal(true)
expect(Array.isArray(part.context.config.plugins)).to.equal(true)
expect(part.context.settings).to.equal(pattern.settings)
expect(typeof part.context.store).to.equal('object')
expect(typeof part.context.store.log).to.equal('object')
expect(typeof part.context.store.log.debug).to.equal('function')
expect(typeof part.context.store.log.info).to.equal('function')
expect(typeof part.context.store.log.warning).to.equal('function')
expect(typeof part.context.store.log.error).to.equal('function')
expect(typeof part.context.store.logs).to.equal('object')
expect(Array.isArray(part.context.store.logs.debug)).to.equal(true)
expect(Array.isArray(part.context.store.logs.info)).to.equal(true)
expect(Array.isArray(part.context.store.logs.warning)).to.equal(true)
expect(Array.isArray(part.context.store.logs.error)).to.equal(true)
})
})