Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
petaki committed Mar 7, 2023
2 parents ba5e7bb + b35251c commit 787e939
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 5 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ inertiaManager.EnableSsr("http://ssr-host:13714")

This is a simplified example using Vue 3 and Laravel Mix.

For more information, please read the official documentation.

```js
// resources/js/ssr.js

Expand Down Expand Up @@ -136,7 +134,7 @@ mix.options({ manifest: false })
});
```

You can find the example for the SSR based root template below.
You can find the example for the SSR based root template below. For more information, please read the official Server-side Rendering documentation on [inertiajs.com](https://inertiajs.com).

## Examples

Expand Down Expand Up @@ -165,7 +163,7 @@ func authenticate(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// ...

ctx := inertiaManager.WithProp(r.Context(), "authUserId", user.Id)
ctx := inertiaManager.WithProp(r.Context(), "authUserID", user.ID)
next.ServeHTTP(w, r.WithContext(ctx))
})
}
Expand Down
73 changes: 72 additions & 1 deletion inertia_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package inertia

import "testing"
import (
"context"
"testing"
)

func TestEnableSsr(t *testing.T) {
i := New("", "", "")
Expand Down Expand Up @@ -55,3 +58,71 @@ func TestDisableSsr(t *testing.T) {
t.Error("expected: nil, got: *http.Client")
}
}

func TestShare(t *testing.T) {
i := New("", "", "")
i.Share("title", "Inertia.js Go")

title, ok := i.sharedProps["title"].(string)
if !ok {
t.Error("expected: title, got: empty value")
}

if title != "Inertia.js Go" {
t.Errorf("expected: Inertia.js Go, got: %s", title)
}
}

func TestShareFunc(t *testing.T) {
i := New("", "", "")
i.ShareFunc("asset", func(path string) (string, error) {
return "/" + path, nil
})

_, ok := i.sharedFuncMap["asset"].(func(string) (string, error))
if !ok {
t.Error("expected: asset func, got: empty value")
}
}

func TestWithProp(t *testing.T) {
ctx := context.TODO()

i := New("", "", "")
ctx = i.WithProp(ctx, "user", "test-user")

contextProps, ok := ctx.Value(ContextKeyProps).(map[string]interface{})
if !ok {
t.Error("expected: context props, got: empty value")
}

user, ok := contextProps["user"].(string)
if !ok {
t.Error("expected: user, got: empty value")
}

if user != "test-user" {
t.Errorf("expected: test-user, got: %s", user)
}
}

func TestWithViewData(t *testing.T) {
ctx := context.TODO()

i := New("", "", "")
ctx = i.WithViewData(ctx, "meta", "test-meta")

contextViewData, ok := ctx.Value(ContextKeyViewData).(map[string]interface{})
if !ok {
t.Error("expected: context view data, got: empty value")
}

meta, ok := contextViewData["meta"].(string)
if !ok {
t.Error("expected: meta, got: empty value")
}

if meta != "test-meta" {
t.Errorf("expected: test-meta, got: %s", meta)
}
}

0 comments on commit 787e939

Please sign in to comment.