Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
Add more l10n tests, and fixed some bug
Browse files Browse the repository at this point in the history
  • Loading branch information
sunfmin committed Jun 5, 2024
1 parent 896e33d commit b8f776e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docsrc/examples/examples_admin/localization.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ func LocalizationExample(b *presets.Builder, db *gorm.DB) http.Handler {
mb.Listing("ID", "Title", "Locale")
// @snippet_end
// @snippet_end
return b
return l10nBuilder.EnsureLocale(b)
}
49 changes: 49 additions & 0 deletions docsrc/examples/examples_admin/localization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ INSERT INTO public.l10n_models (id, created_at, updated_at, deleted_at, title, l
'2024-06-04 23:27:40.442281 +00:00', '2024-06-04 23:27:40.442281 +00:00', null, 'My model title', 'International');
`, []string{"l10n_models"}))

var l10nDataWithChina = gofixtures.Data(gofixtures.Sql(`
INSERT INTO public.l10n_models (id, created_at, updated_at, deleted_at, title, locale_code) VALUES (1,
'2024-06-04 23:27:40.442281 +00:00', '2024-06-04 23:27:40.442281 +00:00', null, 'My model title', 'International');
INSERT INTO public.l10n_models (id, created_at, updated_at, deleted_at, title, locale_code) VALUES (1, '2024-06-04 23:50:28.847833 +00:00', '2024-06-04 23:50:28.844069 +00:00', null, '中文标题', 'China');
`, []string{"l10n_models"}))

func TestLocalization(t *testing.T) {
Expand All @@ -33,6 +41,15 @@ func TestLocalization(t *testing.T) {
},
ExpectPageBodyContainsInOrder: []string{"My model title", "International"},
},
{
Name: "Index Page with locale code",
Debug: true,
ReqFunc: func() *http.Request {
l10nDataWithChina.TruncatePut(SqlDB)
return httptest.NewRequest("GET", "/l10n-models?locale=China", nil)
},
ExpectPageBodyContainsInOrder: []string{"中文标题", `<v-chip color='success' :variant='"flat"' :label='true' :size='"small"'>China</v-chip>`},
},
{
Name: "Localize dialog",
Debug: true,
Expand All @@ -45,6 +62,38 @@ func TestLocalization(t *testing.T) {
},
ExpectPortalUpdate0ContainsInOrder: []string{"China", "Japan"},
},
{
Name: "Show detail",
Debug: true,
ReqFunc: func() *http.Request {
l10nDataWithChina.TruncatePut(SqlDB)
req := multipartestutils.NewMultipartBuilder().
PageURL("/l10n-models?__execute_event__=presets_Edit&id=1_China").
BuildEventFuncRequest()
return req
},
ExpectPortalUpdate0ContainsInOrder: []string{"中文标题"},
},
{
Name: "Update detail",
Debug: true,
ReqFunc: func() *http.Request {
l10nDataWithChina.TruncatePut(SqlDB)
req := multipartestutils.NewMultipartBuilder().
PageURL("/l10n-models?__execute_event__=presets_Update&id=1_China").
AddField("Title", "Updated Title").
AddField("LocaleCode", "China").
BuildEventFuncRequest()
return req
},
EventResponseMatch: func(t *testing.T, er *multipartestutils.TestEventResponse) {
var m L10nModel
TestDB.Find(&m, "id = ? AND locale_code = ?", 1, "China")
if m.Title != "Updated Title" {
t.Errorf("title is wrong %#+v", m)
}
},
},
{
Name: "Localize to China and Japan",
Debug: true,
Expand Down

0 comments on commit b8f776e

Please sign in to comment.