-
-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathaction-view-helpers.test.ts
More file actions
74 lines (65 loc) · 1.89 KB
/
action-view-helpers.test.ts
File metadata and controls
74 lines (65 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { describe, test, expect, beforeAll } from "vitest"
import { Herb } from "@herb-tools/node-wasm"
import { Formatter } from "../../src"
import dedent from "dedent"
let formatter: Formatter
describe("@herb-tools/formatter - ActionView Helpers", () => {
beforeAll(async () => {
await Herb.load()
formatter = new Formatter(Herb, {
indentWidth: 2,
maxLineLength: 80,
}, {
action_view_helpers: true,
})
})
test("tag.div with multiline data hash preserves original source", () => {
const source = dedent`
<%= tag.div(
data: {
controller: "hello",
action: "click->hello#greet"
}
) do %>
<div>Hello</div>
<% end %>
`
const result = formatter.format(source)
expect(result).toEqual(source)
})
test("tag.div with simple attributes preserves original source", () => {
const source = dedent`
<%= tag.div class: "content" do %>
Content
<% end %>
`
const result = formatter.format(source)
expect(result).toEqual(source)
})
test("tag.div without block preserves original source", () => {
const source = `<%= tag.div class: "content" %>`
const result = formatter.format(source)
expect(result).toEqual(source)
})
test("content_tag with attributes preserves original source", () => {
const source = dedent`
<%= content_tag :div, class: "content" do %>
Content
<% end %>
`
const result = formatter.format(source)
expect(result).toEqual(source)
})
test("tag.div with data and aria splats preserves original source", () => {
const source = dedent`
<%= tag.div(
data: { controller: "hello", **data_attrs },
aria: { label: "greeting", **aria_attrs }
) do %>
<div>Hello</div>
<% end %>
`
const result = formatter.format(source)
expect(result).toEqual(source)
})
})