2023-06-19 23:42:47 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2019-01-01 21:53:52 +01:00
|
|
|
package form // import "miniflux.app/ui/form"
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestValid(t *testing.T) {
|
|
|
|
settings := &SettingsForm{
|
2021-08-30 16:53:05 +02:00
|
|
|
Username: "user",
|
|
|
|
Password: "hunter2",
|
|
|
|
Confirmation: "hunter2",
|
|
|
|
Theme: "default",
|
|
|
|
Language: "en_US",
|
|
|
|
Timezone: "UTC",
|
|
|
|
EntryDirection: "asc",
|
|
|
|
EntriesPerPage: 50,
|
|
|
|
DisplayMode: "standalone",
|
2022-09-30 07:37:57 +02:00
|
|
|
GestureNav: "tap",
|
2021-08-30 16:53:05 +02:00
|
|
|
DefaultReadingSpeed: 35,
|
|
|
|
CJKReadingSpeed: 25,
|
2022-07-20 22:07:55 +02:00
|
|
|
DefaultHomePage: "unread",
|
2019-01-01 21:53:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
err := settings.Validate()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfirmationEmpty(t *testing.T) {
|
|
|
|
settings := &SettingsForm{
|
2021-08-30 16:53:05 +02:00
|
|
|
Username: "user",
|
|
|
|
Password: "hunter2",
|
|
|
|
Confirmation: "",
|
|
|
|
Theme: "default",
|
|
|
|
Language: "en_US",
|
|
|
|
Timezone: "UTC",
|
|
|
|
EntryDirection: "asc",
|
|
|
|
EntriesPerPage: 50,
|
|
|
|
DisplayMode: "standalone",
|
2022-09-30 07:37:57 +02:00
|
|
|
GestureNav: "tap",
|
2021-08-30 16:53:05 +02:00
|
|
|
DefaultReadingSpeed: 35,
|
|
|
|
CJKReadingSpeed: 25,
|
2022-07-20 22:07:55 +02:00
|
|
|
DefaultHomePage: "unread",
|
2019-01-01 21:53:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
err := settings.Validate()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if settings.Password != "" {
|
|
|
|
t.Error("Password should have been cleared")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfirmationIncorrect(t *testing.T) {
|
|
|
|
settings := &SettingsForm{
|
2021-08-30 16:53:05 +02:00
|
|
|
Username: "user",
|
|
|
|
Password: "hunter2",
|
|
|
|
Confirmation: "unter2",
|
|
|
|
Theme: "default",
|
|
|
|
Language: "en_US",
|
|
|
|
Timezone: "UTC",
|
|
|
|
EntryDirection: "asc",
|
|
|
|
EntriesPerPage: 50,
|
|
|
|
DisplayMode: "standalone",
|
2022-09-30 07:37:57 +02:00
|
|
|
GestureNav: "tap",
|
2021-08-30 16:53:05 +02:00
|
|
|
DefaultReadingSpeed: 35,
|
|
|
|
CJKReadingSpeed: 25,
|
2022-07-20 22:07:55 +02:00
|
|
|
DefaultHomePage: "unread",
|
2020-07-09 01:24:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
err := settings.Validate()
|
|
|
|
if err == nil {
|
|
|
|
t.Error("Validate should return an error")
|
|
|
|
}
|
|
|
|
}
|