From f12890facba502805f03a64c76f386c4531abbcc Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 12 Jun 2023 14:51:08 -0300 Subject: html: new Stationery class for instantiating Templates --- test/unit/util/html.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'test/unit') diff --git a/test/unit/util/html.js b/test/unit/util/html.js index 82f96b48..01a510ec 100644 --- a/test/unit/util/html.js +++ b/test/unit/util/html.js @@ -904,3 +904,31 @@ t.test(`Template - slot value errors`, t => { `arrayOfHTML length: 0`, ]).toString()); }); + +t.test(`Stationery`, t => { + t.plan(3); + + // 1-3: basic behavior + + const stationery1 = new html.Stationery({ + slots: { + slot1: {type: 'string', default: 'apricot'}, + slot2: {type: 'string', default: 'disaster'}, + }, + + content: ({slot1, slot2}) => html.tag('span', `${slot1} ${slot2}`), + }); + + const template1 = stationery1.template(); + const template2 = stationery1.template(); + + template2.setSlots({slot1: 'aquaduct', slot2: 'dichotomy'}); + + const template3 = stationery1.template(); + + template3.setSlots({slot2: 'vinaigrette'}); + + t.equal(template1.toString(), `apricot disaster`); + t.equal(template2.toString(), `aquaduct dichotomy`); + t.equal(template3.toString(), `apricot vinaigrette`); +}); -- cgit 1.3.0-6-gf8a5