Skip to content

Commit efc43b1

Browse files
committed
Linter: Add more tests for erb-no-duplicate-branch-elements autofix
1 parent ee69f66 commit efc43b1

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

javascript/packages/linter/test/autofix/erb-no-duplicate-branch-elements.autofix.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,40 @@ describe("erb-no-duplicate-branch-elements autofix", () => {
375375
expect(result.fixed).toHaveLength(1)
376376
})
377377

378+
test("two elements both with different bodies: no autofix", () => {
379+
const input = dedent`
380+
<% if @event.meetup? %>
381+
<div class="text-3xl font-bold text-primary mb-1"><%= @event.talks.where(meta_talk: true).count %></div>
382+
<div class="text-sm font-medium text-gray-600">Events</div>
383+
<% else %>
384+
<div class="text-3xl font-bold text-primary mb-1"><%= @event.sponsors.count %></div>
385+
<div class="text-sm font-medium text-gray-600">Sponsors</div>
386+
<% end %>
387+
`
388+
389+
const result = autofix(input)
390+
391+
expect(result.source).toBe(input)
392+
expect(result.fixed).toHaveLength(0)
393+
})
394+
395+
test("shared tag with different content when branches have different lengths: no autofix", () => {
396+
const input = dedent`
397+
<% if Current.user.verified? %>
398+
<h1>Change your email</h1>
399+
<% else %>
400+
<h1>Verify your email</h1>
401+
<p>We sent a verification email to the address below. Check that email and follow those instructions to confirm it's your email address.</p>
402+
<p><%= button_to "Re-send verification email", identity_email_verification_path %></p>
403+
<% end %>
404+
`
405+
406+
const result = autofix(input)
407+
408+
expect(result.source).toBe(input)
409+
expect(result.fixed).toHaveLength(0)
410+
})
411+
378412
test("identical middle element with different surrounding elements: no autofix", () => {
379413
const input = dedent`
380414
<% if condition? %>

0 commit comments

Comments
 (0)