mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-05 19:59:37 -06:00
* 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>
75 lines
2.0 KiB
Go
75 lines
2.0 KiB
Go
package theme_test
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
|
|
"github.com/spf13/afero"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/tidwall/gjson"
|
|
|
|
"github.com/owncloud/ocis/v2/ocis-pkg/x/io/fsx"
|
|
"github.com/owncloud/ocis/v2/services/graph/mocks"
|
|
"github.com/owncloud/ocis/v2/services/graph/pkg/unifiedrole"
|
|
"github.com/owncloud/ocis/v2/services/web/pkg/theme"
|
|
)
|
|
|
|
func TestNewService(t *testing.T) {
|
|
t.Run("fails if the options are invalid", func(t *testing.T) {
|
|
_, err := theme.NewService(theme.ServiceOptions{})
|
|
assert.Error(t, err)
|
|
})
|
|
|
|
t.Run("success if the options are valid", func(t *testing.T) {
|
|
_, err := theme.NewService(
|
|
theme.ServiceOptions{}.
|
|
WithThemeFS(fsx.NewFallbackFS(fsx.NewMemMapFs(), fsx.NewMemMapFs())).
|
|
WithGatewaySelector(mocks.NewSelectable[gateway.GatewayAPIClient](t)),
|
|
)
|
|
assert.NoError(t, err)
|
|
})
|
|
}
|
|
|
|
func TestService_Get(t *testing.T) {
|
|
primaryFS := fsx.NewMemMapFs()
|
|
fallbackFS := fsx.NewFallbackFS(primaryFS, fsx.NewMemMapFs())
|
|
|
|
add := func(filename string, content interface{}) {
|
|
b, err := json.Marshal(content)
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, afero.WriteFile(primaryFS, filename, b, 0644))
|
|
}
|
|
|
|
// baseTheme
|
|
add("base/theme.json", map[string]interface{}{
|
|
"base": "base",
|
|
})
|
|
// brandingTheme
|
|
add("_branding/theme.json", map[string]interface{}{
|
|
"_branding": "_branding",
|
|
})
|
|
|
|
service, _ := theme.NewService(
|
|
theme.ServiceOptions{}.
|
|
WithThemeFS(fallbackFS).
|
|
WithGatewaySelector(mocks.NewSelectable[gateway.GatewayAPIClient](t)),
|
|
)
|
|
r := httptest.NewRequest(http.MethodGet, "/", nil)
|
|
r.SetPathValue("id", "base")
|
|
|
|
w := httptest.NewRecorder()
|
|
service.Get(w, r)
|
|
|
|
jsonData := gjson.Parse(w.Body.String())
|
|
// baseTheme
|
|
assert.Equal(t, jsonData.Get("base").String(), "base")
|
|
// brandingTheme
|
|
assert.Equal(t, jsonData.Get("_branding").String(), "_branding")
|
|
// themeDefaults
|
|
assert.Equal(t, jsonData.Get("common.shareRoles."+unifiedrole.UnifiedRoleViewerID+".name").String(), "UnifiedRoleViewer")
|
|
}
|