Skip to content

Commit

Permalink
Merge pull request #4 from rafiramadhana/1-hx-swap-test
Browse files Browse the repository at this point in the history
Add unit test of SwapStrategy
  • Loading branch information
angelofallars authored Nov 25, 2023
2 parents a425ee8 + 8e2d8f8 commit f6fd13c
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions swap_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package htmx

import (
"testing"
"time"
)

func TestSwapStrategy_SwapString(t *testing.T) {
testCases := []struct {
name string
swapStrategy SwapStrategy
result string
}{
{
name: "no modifier",
swapStrategy: SwapInnerHTML,
result: "innerHTML",
},
{
name: "one modifier",
swapStrategy: SwapInnerHTML.Transition(true),
result: "innerHTML transition:true",
},
{
name: "many modifiers",
swapStrategy: SwapInnerHTML.Transition(true).
IgnoreTitle(true).
FocusScroll(true).
After(5*time.Second).
SettleAfter(5*time.Second).
Scroll(Top).
ScrollOn("#another-div", Top).
ScrollWindow(Top).
Show(Top).
ShowOn("#another-div", Top).ShowWindow(Top).
ShowNone(),
result: "innerHTML transition:true ignoreTitle:true focusScroll:true swap:5s settle:5s scroll:window:top show:none",
},
}

for _, tc := range testCases {
if result := tc.swapStrategy.swapString(); result != tc.result {
t.Errorf(`got: "%v", want: "%v"`, result, tc.result)
}
}
}

0 comments on commit f6fd13c

Please sign in to comment.