diff --git a/packages/core/test/files/_patterns/test/pattern-wrap-class-json.json b/packages/core/test/files/_patterns/test/pattern-wrap-class-json.json new file mode 100644 index 000000000..1cb2a1d93 --- /dev/null +++ b/packages/core/test/files/_patterns/test/pattern-wrap-class-json.json @@ -0,0 +1,3 @@ +{ + "theme-class": "json-theme-class" +} diff --git a/packages/core/test/files/_patterns/test/pattern-wrap-class-json.mustache b/packages/core/test/files/_patterns/test/pattern-wrap-class-json.mustache new file mode 100644 index 000000000..5716ca598 --- /dev/null +++ b/packages/core/test/files/_patterns/test/pattern-wrap-class-json.mustache @@ -0,0 +1 @@ +bar diff --git a/packages/core/test/files/_patterns/test/pattern-wrap-class-markdown.md b/packages/core/test/files/_patterns/test/pattern-wrap-class-markdown.md new file mode 100644 index 000000000..358c8a525 --- /dev/null +++ b/packages/core/test/files/_patterns/test/pattern-wrap-class-markdown.md @@ -0,0 +1,3 @@ +--- +theme-class: markdown-theme-class +--- diff --git a/packages/core/test/files/_patterns/test/pattern-wrap-class-markdown.mustache b/packages/core/test/files/_patterns/test/pattern-wrap-class-markdown.mustache new file mode 100644 index 000000000..5716ca598 --- /dev/null +++ b/packages/core/test/files/_patterns/test/pattern-wrap-class-markdown.mustache @@ -0,0 +1 @@ +bar diff --git a/packages/core/test/patternWrapClasses_tests.js b/packages/core/test/patternWrapClasses_tests.js new file mode 100644 index 000000000..a00d06dd1 --- /dev/null +++ b/packages/core/test/patternWrapClasses_tests.js @@ -0,0 +1,53 @@ +'use strict'; + +const path = require('path'); +const tap = require('tap'); + +const loadPattern = require('../src/lib/loadPattern'); +const patternWrapClassesChangePatternTemplate = require('../src/lib/patternWrapClasses'); +const util = require('./util/test_utils.js'); +const patternEngines = require('../src/lib/pattern_engines'); +const config = require('./util/patternlab-config.json'); + +patternEngines.loadAllEngines(config); + +const patterns_dir = `${__dirname}/files/_patterns`; + +tap.test('reading pattern wrap class from markdown', function (test) { + const patternlab = util.fakePatternLab(patterns_dir); + patternlab.config = { + ...patternlab.config, + patternWrapClassesEnable: true, + patternWrapClassesKey: ['theme-class'], + }; + + const patternPathMarkdown = path.join( + 'test', + 'pattern-wrap-class-markdown.mustache' + ); + const patternMarkdown = loadPattern(patternPathMarkdown, patternlab); + patternWrapClassesChangePatternTemplate(patternlab, patternMarkdown); + const patternPartialMarkdown = + '
'; + + test.equal(patternMarkdown.patternPartialCode, patternPartialMarkdown); + test.end(); +}); + +tap.test('reading pattern wrap class from json', function (test) { + const patternlab = util.fakePatternLab(patterns_dir); + patternlab.config = { + ...patternlab.config, + patternWrapClassesEnable: true, + patternWrapClassesKey: ['theme-class'], + }; + + const patternPathJson = path.join('test', 'pattern-wrap-class-json.mustache'); + const patternJson = loadPattern(patternPathJson, patternlab); + patternWrapClassesChangePatternTemplate(patternlab, patternJson); + const patternPartialJson = + ''; + + test.equal(patternJson.patternPartialCode, patternPartialJson); + test.end(); +});