enhancement: introduce theme processing (#9133)
* enhancement: introduce theme processing * enhancement: introduce theme processing * enhancement: add theme processing tests and changelog * Update services/web/pkg/config/config.go Co-authored-by: Michael Barz <michael.barz@zeitgestalten.eu> * fix: ci findings * Apply suggestions from code review Co-authored-by: Martin <github@diemattels.at> * enhancement: use the theme assets from web instead of having them inside the oCis repo (license clash Apache vs. AGPLv3) * fix: golangci tagalign order * fix: rename UnifiedRoleUploader to UnifiedRoleEditorLite * fix: some typos Co-authored-by: Michael Barz <michael.barz@zeitgestalten.eu> * enhancement: export supported theme logo upload filetypes * chore: bump reva * fix: allow init func --------- Co-authored-by: Michael Barz <michael.barz@zeitgestalten.eu> Co-authored-by: Martin <github@diemattels.at>
This commit is contained in:
co-authored by
Michael Barz
Martin
parent
80480cb7fa
commit
eb7c36443f
@@ -0,0 +1,137 @@
|
||||
package theme_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/afero"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/x/io/fsx"
|
||||
"github.com/owncloud/ocis/v2/services/web/pkg/theme"
|
||||
)
|
||||
|
||||
func TestMergeKV(t *testing.T) {
|
||||
left := theme.KV{
|
||||
"left": "left",
|
||||
"both": "left",
|
||||
}
|
||||
right := theme.KV{
|
||||
"right": "right",
|
||||
"both": "right",
|
||||
}
|
||||
|
||||
result, err := theme.MergeKV(left, right)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, result, theme.KV{
|
||||
"left": "left",
|
||||
"right": "right",
|
||||
"both": "right",
|
||||
})
|
||||
}
|
||||
|
||||
func TestPatchKV(t *testing.T) {
|
||||
in := theme.KV{
|
||||
"a": theme.KV{
|
||||
"value": "a",
|
||||
},
|
||||
"b": theme.KV{
|
||||
"value": "b",
|
||||
},
|
||||
}
|
||||
err := theme.PatchKV(&in, theme.KV{
|
||||
"b.value": "b-new",
|
||||
"c.value": "c-new",
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, in, theme.KV{
|
||||
"a": map[string]interface{}{
|
||||
"value": "a",
|
||||
},
|
||||
"b": map[string]interface{}{
|
||||
"value": "b-new",
|
||||
},
|
||||
"c": map[string]interface{}{
|
||||
"value": "c-new",
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestLoadKV(t *testing.T) {
|
||||
in := theme.KV{
|
||||
"a": map[string]interface{}{
|
||||
"value": "a",
|
||||
},
|
||||
"b": map[string]interface{}{
|
||||
"value": "b",
|
||||
},
|
||||
}
|
||||
b, err := json.Marshal(in)
|
||||
assert.Nil(t, err)
|
||||
|
||||
fsys := fsx.NewMemMapFs()
|
||||
assert.Nil(t, afero.WriteFile(fsys, "some.json", b, 0644))
|
||||
|
||||
out, err := theme.LoadKV(fsys, "some.json")
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, in, out)
|
||||
}
|
||||
|
||||
func TestWriteKV(t *testing.T) {
|
||||
in := theme.KV{
|
||||
"a": map[string]interface{}{
|
||||
"value": "a",
|
||||
},
|
||||
"b": map[string]interface{}{
|
||||
"value": "b",
|
||||
},
|
||||
}
|
||||
|
||||
fsys := fsx.NewMemMapFs()
|
||||
assert.Nil(t, theme.WriteKV(fsys, "some.json", in))
|
||||
|
||||
f, err := fsys.Open("some.json")
|
||||
assert.Nil(t, err)
|
||||
|
||||
var out theme.KV
|
||||
assert.Nil(t, json.NewDecoder(f).Decode(&out))
|
||||
assert.Equal(t, in, out)
|
||||
}
|
||||
|
||||
func TestUpdateKV(t *testing.T) {
|
||||
fileKV := theme.KV{
|
||||
"a": map[string]interface{}{
|
||||
"value": "a",
|
||||
},
|
||||
"b": map[string]interface{}{
|
||||
"value": "b",
|
||||
},
|
||||
}
|
||||
|
||||
wb, err := json.Marshal(fileKV)
|
||||
assert.Nil(t, err)
|
||||
|
||||
fsys := fsx.NewMemMapFs()
|
||||
assert.Nil(t, afero.WriteFile(fsys, "some.json", wb, 0644))
|
||||
assert.Nil(t, theme.UpdateKV(fsys, "some.json", theme.KV{
|
||||
"b.value": "b-new",
|
||||
"c.value": "c-new",
|
||||
}))
|
||||
|
||||
f, err := fsys.Open("some.json")
|
||||
assert.Nil(t, err)
|
||||
|
||||
var out theme.KV
|
||||
assert.Nil(t, json.NewDecoder(f).Decode(&out))
|
||||
assert.Equal(t, out, theme.KV{
|
||||
"a": map[string]interface{}{
|
||||
"value": "a",
|
||||
},
|
||||
"b": map[string]interface{}{
|
||||
"value": "b-new",
|
||||
},
|
||||
"c": map[string]interface{}{
|
||||
"value": "c-new",
|
||||
},
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user