forked from uadmin/uadmin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate_translation_test.go
96 lines (82 loc) · 2.93 KB
/
generate_translation_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package uadmin
import (
"testing"
)
// TestSyncCustomTranslation is a unit testing function for syncCustomTranslation() function
func TestSyncCustomTranslation(t *testing.T) {
// Activate a second language
ar := Language{}
Get(&ar, "code = ?", "ar")
ar.Active = true
ar.Save()
results := syncCustomTranslation("uadmin/system", "")
if len(results) != len(activeLangs) {
t.Errorf("syncCustomTranslation didn't return status for all active languages. Got %d, expected %d", len(results), len(activeLangs))
}
results = syncCustomTranslation("uadmin/system/tags", "")
if len(results) != 0 {
t.Errorf("syncCustomTranslation didn't return 0 status invalid path. Got %d, expected %d", len(results), 0)
}
zh := Language{}
Get(&zh, "code = ?", "zh")
zh.Active = true
zh.Save()
results = syncCustomTranslation("uadmin/system", "")
if len(results) != len(activeLangs) {
t.Errorf("syncCustomTranslation didn't return status for all active languages. Got %d, expected %d", len(results), len(activeLangs))
}
// Clean up
ar.Active = false
ar.Save()
zh.Active = false
zh.Save()
}
// TestSyncModelTranslation is a unit testing function for syncModelTranslation() function
func TestSyncModelTranslation(t *testing.T) {
// Activate a second language
ar := Language{}
Get(&ar, "code = ?", "ar")
ar.Active = true
ar.Save()
results := syncModelTranslation(Schema["testmodelb"], "")
if len(results) != len(activeLangs) {
t.Errorf("syncModelTranslation didn't return status for all active languages. Got %d, expected %d", len(results), len(activeLangs))
}
zh := Language{}
Get(&zh, "code = ?", "zh")
zh.Active = true
zh.Save()
results = syncModelTranslation(Schema["testmodelb"], "")
if len(results) != len(activeLangs) {
t.Errorf("syncCustomTranslation didn't return status for all active languages. Got %d, expected %d", len(results), len(activeLangs))
}
s := Schema["testmodelb"]
s.Fields = append(s.Fields, F{
Name: "TestField",
DisplayName: "Test Field",
Help: "Help for test field",
PatternMsg: "test message",
Choices: []Choice{},
ErrMsg: "",
})
Schema["testmodelb"] = s
results = syncModelTranslation(Schema["testmodelb"], "")
if len(results) != len(activeLangs) {
t.Errorf("syncCustomTranslation didn't return status for all active languages. Got %d, expected %d", len(results), len(activeLangs))
}
s.FieldByName("TestField").DisplayName = "`Updated Test Field"
s.FieldByName("TestField").Help = "Updated Help for test field"
s.FieldByName("TestField").PatternMsg = "Updated test message"
Schema["testmodelb"] = s
results = syncModelTranslation(Schema["testmodelb"], "")
if len(results) != len(activeLangs) {
t.Errorf("syncCustomTranslation didn't return status for all active languages. Got %d, expected %d", len(results), len(activeLangs))
}
// Clean up
ar.Active = false
ar.Save()
zh.Active = false
zh.Save()
delete(Schema, "testmodelb")
Schema["testmodelb"], _ = getSchema(TestModelB{})
}