Skip to content

Commit

Permalink
test: pattern wrap classes reading from markdown and/or json
Browse files Browse the repository at this point in the history
  • Loading branch information
hadl committed Sep 25, 2022
1 parent 7497bc4 commit 201d15f
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"theme-class": "json-theme-class"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bar
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
theme-class: markdown-theme-class
---
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bar
53 changes: 53 additions & 0 deletions packages/core/test/patternWrapClasses_tests.js
Original file line number Diff line number Diff line change
@@ -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 =
'<div class="pl-pattern-wrapper-element markdown-theme-class"></div>';

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 =
'<div class="pl-pattern-wrapper-element json-theme-class"></div>';

test.equal(patternJson.patternPartialCode, patternPartialJson);
test.end();
});

0 comments on commit 201d15f

Please sign in to comment.