import { describe, it, expect, beforeAll } from "vitest" import { Herb } from "@herb-tools/node-wasm" import { Formatter } from "../../src/formatter" import dedent from "dedent" describe("conditional attributes", () => { let formatter: Formatter beforeAll(async () => { await Herb.load() formatter = new Formatter(Herb) }) it("should preserve conditional ERB in class attributes with string interpolation", () => { const source = dedent` <%= form.label "file_#{id}", class: "btn #{"disabled" if disabled} flex-grow", style: "font-size: 0.875rem;" do %> Upload <% end %> ` const expected = dedent` <%= form.label "file_#{id}", class: "btn #{"disabled" if disabled} flex-grow", style: "font-size: 0.875rem;" do %> Upload <% end %> ` expect(formatter.format(source)).toBe(expected) }) it("should preserve conditional ERB in class attributes", () => { const source = dedent` ` const expected = dedent` ` expect(formatter.format(source)).toBe(expected) }) it("should preserve conditional ERB with local_assigns", () => { const source = dedent` <%= link_to path, class: "btn #{"disabled" if local_assigns[:disabled]} bg-primary", data: { behavior: "modal" } do %> Select <% end %> ` const expected = dedent` <%= link_to path, class: "btn #{"disabled" if local_assigns[:disabled]} bg-primary", data: { behavior: "modal" } do %> Select <% end %> ` expect(formatter.format(source)).toBe(expected) }) it("should preserve inline conditional ERB in div class", () => { const source = dedent`