Debian Codegraph @

test/tests/unit/__attributeValue.js

raw symbols SCIP
1 describe('__atributeValue() unit tests', function() {
2
3 it(':append modifier appends to inherited value', function () {
4 const container = createDisconnectedHTML(
5 '<div hx-include:inherited=".parent">' +
6 ' <button hx-include:append=".child">Test</button>' +
7 '</div>'
8 );
9 const button = container.querySelector('button');
10 const result = htmx.__attributeValue(button, 'hx-include');
11 assert.equal(result, '.parent,.child');
12 });
13
14 it(':append modifier works without inherited value', function () {
15 const button = createDisconnectedHTML('<button hx-include:append=".child">Test</button>');
16 const result = htmx.__attributeValue(button, 'hx-include');
17 assert.equal(result, '.child');
18 });
19
20 it(':append modifier works with multiple inheritance levels', function () {
21 const container = createDisconnectedHTML(
22 '<div hx-vals:inherited=\'{"a":1}\'>' +
23 ' <div>' +
24 ' <button hx-vals:append=\'{"b":2}\'>Test</button>' +
25 ' </div>' +
26 '</div>'
27 );
28 const button = container.querySelector('button');
29 const result = htmx.__attributeValue(button, 'hx-vals');
30 assert.equal(result, '"a":1,"b":2');
31 });
32
33 it(':inherited still works normally', function () {
34 const container = createDisconnectedHTML(
35 '<div hx-include:inherited=".parent">' +
36 ' <button>Test</button>' +
37 '</div>'
38 );
39 const button = container.querySelector('button');
40 const result = htmx.__attributeValue(button, 'hx-include');
41 assert.equal(result, '.parent');
42 });
43
44 it('direct attribute takes precedence over :append', function () {
45 const container = createDisconnectedHTML(
46 '<div hx-include:inherited=".parent">' +
47 ' <button hx-include=".direct" hx-include:append=".child">Test</button>' +
48 '</div>'
49 );
50 const button = container.querySelector('button');
51 const result = htmx.__attributeValue(button, 'hx-include');
52 assert.equal(result, '.direct');
53 });
54
55 it(':inherited:append modifier works', function () {
56 const container = createDisconnectedHTML(
57 '<div hx-include:inherited=".grandparent">' +
58 ' <div hx-include:inherited:append=".parent">' +
59 ' <button hx-include:append=".child">Test</button>' +
60 ' </div>' +
61 '</div>'
62 );
63 const button = container.querySelector('button');
64 const result = htmx.__attributeValue(button, 'hx-include');
65 assert.equal(result, '.grandparent,.parent,.child');
66 });
67
68 it(':inherited:append can be inherited by descendants', function () {
69 const container = createDisconnectedHTML(
70 '<div hx-include:inherited:append=".parent">' +
71 ' <button>Test</button>' +
72 '</div>'
73 );
74 const button = container.querySelector('button');
75 const result = htmx.__attributeValue(button, 'hx-include');
76 assert.equal(result, '.parent');
77 });
78
79 });