[MM-57418] Implement support for defining plugin settings sections (#27654)

* Implement support for defining plugin settings sections

* Implement custom plugin configuration sections

* Tests

* Update test

* Improvements
Этот коммит содержится в:
Claudio Costa
2024-07-17 18:24:33 +02:00
коммит произвёл GitHub
родитель c0a7a19294
Коммит be94c47607
17 изменённых файлов: 545 добавлений и 25 удалений

Просмотреть файл

@@ -65,6 +65,37 @@ func TestIsValid(t *testing.T) {
Default: "thedefault",
},
},
Sections: []*PluginSettingsSection{
{
Key: "section1",
Title: "section title",
Subtitle: "section subtitle",
Settings: []*PluginSetting{
{
Key: "section1setting1",
DisplayName: "thedisplayname",
Type: "custom",
},
{
Key: "section1setting2",
DisplayName: "thedisplayname",
Type: "custom",
},
},
Header: "section header",
Footer: "section footer",
},
{
Key: "section2",
Settings: []*PluginSetting{
{
Key: "section2setting1",
DisplayName: "thedisplayname",
Type: "custom",
},
},
},
},
},
}, false},
}
@@ -103,6 +134,62 @@ func TestIsValidSettingsSchema(t *testing.T) {
}
}
func TestPluginSettingsSectionIsValid(t *testing.T) {
for name, test := range map[string]struct {
Section PluginSettingsSection
ExpectedError string
}{
"missing key": {
Section: PluginSettingsSection{
Settings: []*PluginSetting{
{
Type: "custom",
Placeholder: "some Text",
},
},
},
ExpectedError: "invalid empty Key",
},
"invalid setting": {
Section: PluginSettingsSection{
Key: "sectionKey",
Settings: []*PluginSetting{
{
Type: "invalid",
},
},
},
ExpectedError: "invalid setting type: invalid",
},
"valid empty": {
Section: PluginSettingsSection{
Key: "sectionKey",
Settings: []*PluginSetting{},
},
},
"valid": {
Section: PluginSettingsSection{
Key: "sectionKey",
Settings: []*PluginSetting{
{
Type: "custom",
Placeholder: "some Text",
},
},
},
},
} {
t.Run(name, func(t *testing.T) {
err := test.Section.IsValid()
if test.ExpectedError != "" {
assert.EqualError(t, err, test.ExpectedError)
} else {
assert.NoError(t, err)
}
})
}
}
func TestSettingIsValid(t *testing.T) {
for name, test := range map[string]struct {
Setting PluginSetting