Debian Codegraph @

test/tests/unit/__determineMethodAndAction.js

raw symbols SCIP
1 describe('__determineMethodAndAction unit tests', function() {
2
3 beforeEach(function() {
4 setupTest();
5 });
6
7 afterEach(function() {
8 cleanupTest();
9 });
10
11 it('boosted form with lowercase method="get" returns uppercase GET', function() {
12 let form = createProcessedHTML('<form hx-boost="true" action="/test" method="get"></form>')
13 let result = htmx.__determineMethodAndAction(form, new Event('submit'))
14 assert.equal(result.method, 'GET')
15 })
16
17 it('boosted form with lowercase method="post" returns uppercase POST', function() {
18 let form = createProcessedHTML('<form hx-boost="true" action="/test" method="post"></form>')
19 let result = htmx.__determineMethodAndAction(form, new Event('submit'))
20 assert.equal(result.method, 'POST')
21 })
22
23 it('boosted form with no method defaults to GET', function() {
24 let form = createProcessedHTML('<form hx-boost="true" action="/test"></form>')
25 let result = htmx.__determineMethodAndAction(form, new Event('submit'))
26 assert.equal(result.method, 'GET')
27 })
28
29 it('boosted anchor returns GET', function() {
30 let a = createProcessedHTML('<a hx-boost="true" href="/test">Link</a>')
31 let result = htmx.__determineMethodAndAction(a, new Event('click'))
32 assert.equal(result.method, 'GET')
33 assert.equal(result.action, '/test')
34 })
35
36 it('non-boosted element with hx-get returns GET', function() {
37 let div = createProcessedHTML('<div hx-get="/test"></div>')
38 let result = htmx.__determineMethodAndAction(div, new Event('click'))
39 assert.equal(result.method, 'GET')
40 assert.equal(result.action, '/test')
41 })
42
43 it('non-boosted element with hx-post returns POST', function() {
44 let div = createProcessedHTML('<div hx-post="/test"></div>')
45 let result = htmx.__determineMethodAndAction(div, new Event('click'))
46 assert.equal(result.method, 'POST')
47 assert.equal(result.action, '/test')
48 })
49
50 })