Skip to content

Commit

Permalink
Added test for Action switcher
Browse files Browse the repository at this point in the history
  • Loading branch information
akclace committed Nov 26, 2024
1 parent 90b9727 commit 8f617e7
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/app/action/layout.go.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@

<div class="col-start-1 col-span-1">
{{ if and (.links) (gt (len .links) 1) }}
<div class="dropdown dropdown-bottom">
<div tabindex="0" role="button" class="btn bg-transparent">
<div class="dropdown dropdown-bottom" title="Switch between Actions">
<div tabindex="0" role="button" class="btn btn-outline">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-menu-2">
<path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M4 6l16 0" /><path d="M4 12l16 0" /><path d="M4 18l16 0" /></svg>
Expand Down
42 changes: 42 additions & 0 deletions internal/app/tests/appaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -811,3 +811,45 @@ app = ace.app("testApp",
t.Errorf("Expected full html response, got: %s", body)
}
}

func TestMultipleActions(t *testing.T) {
logger := testutil.TestLogger()
fileData := map[string]string{
"app.star": `
def handler(dry_run, args):
return ace.result(status="done", values=[{"a": 1, "b": "abc"}])
app = ace.app("testApp",
actions=[ace.action("test1Action", "/test1", handler),
ace.action("test2Action", "/test2", handler)])
`,
"params.star": `param("param1", description="param1 description", type=STRING, default="myvalue")`,
}
a, _, err := CreateTestApp(logger, fileData)
if err != nil {
t.Fatalf("Error %s", err)
}

request := httptest.NewRequest("GET", "/test/test1", nil)
response := httptest.NewRecorder()
a.ServeHTTP(response, request)

testutil.AssertEqualsInt(t, "code", 200, response.Code)
body := response.Body.String()
if strings.Contains(body, `<li><a href="/test/test1">test1Action</a></li>`) {
t.Errorf("actions switcher should not have current action, got %s", body)
}
testutil.AssertStringContains(t, body, `<li><a href="/test/test2">test2Action</a></li>`)

request = httptest.NewRequest("GET", "/test/test2", nil)
response = httptest.NewRecorder()
a.ServeHTTP(response, request)

testutil.AssertEqualsInt(t, "code", 200, response.Code)
body = response.Body.String()
if strings.Contains(body, `<li><a href="/test/test2">test2Action</a></li>`) {
t.Errorf("actions switcher should not have current action, got %s", body)
}
testutil.AssertStringContains(t, body, `<li><a href="/test/test1">test1Action</a></li>`)
}

0 comments on commit 8f617e7

Please sign in to comment.