From 84ad7588296331452c571de81a9dbe219e364ca9 Mon Sep 17 00:00:00 2001 From: Mario Pietsch Date: Fri, 11 Mar 2022 17:33:58 +0100 Subject: [PATCH] Prepare tabs macro tests for future readability improvements (#6504) * prepare tabs macro test for future improvements * update tests for tabs-macro to check all possible parameters --- .../expected-html-tabs-horizontal-all.tid | 33 +++++++ .../expected-html-tabs-horizontal.tid | 43 ++++++++++ .../expected-html-tabs-vertical.tid | 43 ++++++++++ .../tests/test-wikitext-tabs-macro.js | 86 +++++++++++++++++++ 4 files changed, 205 insertions(+) create mode 100644 editions/test/tiddlers/tests/data/tabs-macro/expected-html-tabs-horizontal-all.tid create mode 100644 editions/test/tiddlers/tests/data/tabs-macro/expected-html-tabs-horizontal.tid create mode 100644 editions/test/tiddlers/tests/data/tabs-macro/expected-html-tabs-vertical.tid create mode 100644 editions/test/tiddlers/tests/test-wikitext-tabs-macro.js diff --git a/editions/test/tiddlers/tests/data/tabs-macro/expected-html-tabs-horizontal-all.tid b/editions/test/tiddlers/tests/data/tabs-macro/expected-html-tabs-horizontal-all.tid new file mode 100644 index 000000000..6cd40a30a --- /dev/null +++ b/editions/test/tiddlers/tests/data/tabs-macro/expected-html-tabs-horizontal-all.tid @@ -0,0 +1,33 @@ +title: expected-html-tabs-horizontal-all +type: text/html +description: Horizontal tabs with all parameters active. This is the expected HTML output from a test in test-wikitext-tabs-macro.js + +

+ +

+
+ +
+
+
+

TabTwo

Text tab 2

+
+
+ +

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/tabs-macro/expected-html-tabs-horizontal.tid b/editions/test/tiddlers/tests/data/tabs-macro/expected-html-tabs-horizontal.tid new file mode 100644 index 000000000..b64ce9941 --- /dev/null +++ b/editions/test/tiddlers/tests/data/tabs-macro/expected-html-tabs-horizontal.tid @@ -0,0 +1,43 @@ +title: expected-html-tabs-horizontal +type: text/html +description: Horizontal tabs test - This is the expected HTML output from a test in test-wikitext-tabs-macro.js + +

+ +

+
+ +
+
+
+

Text tab 2

+
+
+ +

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/tabs-macro/expected-html-tabs-vertical.tid b/editions/test/tiddlers/tests/data/tabs-macro/expected-html-tabs-vertical.tid new file mode 100644 index 000000000..e352f4ef0 --- /dev/null +++ b/editions/test/tiddlers/tests/data/tabs-macro/expected-html-tabs-vertical.tid @@ -0,0 +1,43 @@ +title: expected-html-tabs-vertical +type: text/html +description: Vertical tabs test -- This is the expected HTML output from the test in test-wikitext-tabs-macro.js + +

+ +

+
+ +
+
+
+

Text tab 2

+
+
+ +

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/test-wikitext-tabs-macro.js b/editions/test/tiddlers/tests/test-wikitext-tabs-macro.js new file mode 100644 index 000000000..9c015cf17 --- /dev/null +++ b/editions/test/tiddlers/tests/test-wikitext-tabs-macro.js @@ -0,0 +1,86 @@ +/*\ +title: test-wikitext-tabs-macro.js +type: application/javascript +tags: [[$:/tags/test-spec]] + +Tests the core tabs macro by comparing the HTML output with a stored template. +Intended to permit future readability improvements. + +Adding new functionality will probably change the "expected" html structure. + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +describe("Tabs-macro HTML tests", function() { + + var expected = $tw.wiki.getTiddler("expected-html-tabs-horizontal"), + expectedAll = $tw.wiki.getTiddler("expected-html-tabs-horizontal-all"), + expectedVert = $tw.wiki.getTiddler("expected-html-tabs-vertical"), + coreTabsTiddler = $tw.wiki.getTiddler("$:/core/macros/tabs"); + + // Create a wiki + var wiki = new $tw.Wiki(); + + // Add a couple of tiddlers + wiki.addTiddler({title: "TabOne", text: "Text tab 1", caption:"t 1"}); + wiki.addTiddler({title: "TabTwo", text: "Text tab 2", caption:"t 2"}); + // TabThree shows description used in button-template instead of caption + wiki.addTiddler({title: "TabThree", text: "Text tab 3", caption:"t 3", description:"desc"}); + // Tab Four has no caption field, so title will be used + wiki.addTiddler({title: "TabFour", text: "Text tab 4"}); + + // Template tiddlers + wiki.addTiddler({ title: "body-template", + text: '!! <>\n\n<$transclude tiddler=<> mode="block"/>'}); + wiki.addTiddler({ title: "button-template", + text: '<$transclude tiddler=<> field="description"><$transclude tiddler=<> field="caption"><$macrocall $name="currentTab" $type="text/plain" $output="text/plain"/>'}); + // tabs macro cloned, to be used with \\import + wiki.addTiddler({title: "tabs-macro-definition", text: coreTabsTiddler.fields.text}); + + // horizontal tabs test uses `tabsList`, `default` and `state` -- unnamed params + wiki.addTiddler({title: "test-tabs-macro-horizontal", text: '\\import [[tabs-macro-definition]]\n<>'}); + + // horizontal tabs test adds `template`, `buttonTemplate` and `explicitState` as named params + wiki.addTiddler({title: "test-tabs-macro-horizontal-all", text: '\\import [[tabs-macro-definition]]\n<>'}); + + // vertical tabs test. Same params as test 1 + wiki.addTiddler({title: "test-tabs-macro-vertical", text: '\\import [[tabs-macro-definition]]\n<>'}); + + /* ----------------- + / Run the tests + --------------------*/ + // horizontal + it("should render horizontal tabs v5.2.1", function() { + expect(wiki.renderTiddler("text/html","test-tabs-macro-horizontal")).toBe(expected.fields.text); + }); + + it("should render horizontal tabs macro with all parameters modified V5.2.1", function() { + expect(wiki.renderTiddler("text/html","test-tabs-macro-horizontal-all")).toBe(expectedAll.fields.text); + }); + + // vertical + it("should render tabs vertical tabs v5.2.1", function() { + expect(wiki.renderTiddler("text/html","test-tabs-macro-vertical")).toBe(expectedVert.fields.text); + }); + + // Future tests + // horizontal + xit("should render 'horizontal' tabs from v5.2.2 and up with whitespace trim", function() { + expect(wiki.renderTiddler("text/html","test-tabs-macro-horizontal")).toBe(expected.fields.text.replace(/\n/g,"")); + }); + + xit("should render 'horizontal' tabs from v5.2.2 and up with whitespace trim", function() { + expect(wiki.renderTiddler("text/html","test-tabs-macro-horizontal-all")).toBe(expectedAll.fields.text.replace(/\n/g,"")); + }); + + // vertical + xit("should render 'vertical' tabs from v5.2.2 and up with whitespace trim", function() { + expect(wiki.renderTiddler("text/html","test-tabs-macro-vertical")).toBe(expectedVert.fields.text.replace(/\n/g,"")); + }); +}); + +})();