pominal/pominal_cases_test.go
Dan Anglin 19eb9b20be
feat: support configuring Pominal with config file
This commit adds a feature to load Pominal
configuration from a JSON configuration file.

A new data type called PominalConfig was created for
the purpose of configuring Pominal.
A new factory function called newPominalConfig was
created which takes the path to the JSON configuration
file and the flag overrides and generates the new
PominalConfig value.

Here, the JSON config is parsed to create the initial
configuration and any flag overrides can override
the corresponding fields in the PominalConfig object.
Currently only the sessions times and the maximum work
sessions per Pominal cycle have flag overrides.

Additionally users can now configure custom notification
messages for each session type from the configuration file.
There are currently no flag overrides for these.

This commit resolves dananglin/Pominal#1
2020-02-13 12:42:55 +00:00

237 lines
6.7 KiB
Go

/*
Pominal
Copyright (C) 2020 Daniel Anglin
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package main
var newPominalTestCases = []struct {
name string
description string
config PominalConfig
expectedPominal Pominal
}{
{
name: "Test case 1",
description: "When creating a Pominal value with all valid parameters.",
config: PominalConfig{
MaxWorkSessions: 5,
Sessions: Sessions{
Work: SessionConfig{
Duration: "20m",
NotificationMessage: "work time!",
},
ShortBreak: SessionConfig{
Duration: "5m",
NotificationMessage: "break time!",
},
LongBreak: SessionConfig{
Duration: "10m",
NotificationMessage: "long break time!",
},
},
},
expectedPominal: Pominal{
workSession: 1,
maxWorkSessions: 5,
cycle: 1,
countdown: 0,
work: 1200,
shortBreak: 300,
longBreak: 600,
workNotificationMsg: "work time!",
shortBreakNotificationMsg: "break time!",
longBreakNotificationMsg: "long break time!",
currentNotificationMsg: "",
label: "",
stopChan: nil,
},
},
{
name: "Test case 2",
description: "When creating a Pominal value where the work session is set below the minimum allowed time.",
config: PominalConfig{
MaxWorkSessions: 4,
Sessions: Sessions{
Work: SessionConfig{
Duration: "59s999ms",
},
ShortBreak: SessionConfig{
Duration: "25m36s",
},
LongBreak: SessionConfig{
Duration: "30m",
},
},
},
expectedPominal: Pominal{
workSession: 1,
maxWorkSessions: 4,
cycle: 1,
countdown: 0,
work: 60,
shortBreak: 1536,
longBreak: 1800,
workNotificationMsg: "",
shortBreakNotificationMsg: "",
longBreakNotificationMsg: "",
currentNotificationMsg: "",
label: "",
stopChan: nil,
},
},
{
name: "Test case 3",
description: "When creating a Pominal value where both short break and long break sessions are set below the minimum allowed time.",
config: PominalConfig{
MaxWorkSessions: 1,
Sessions: Sessions{
Work: SessionConfig{
Duration: "16m40s",
},
ShortBreak: SessionConfig{
Duration: "1s23ms",
},
LongBreak: SessionConfig{
Duration: "45s674ms",
},
},
},
expectedPominal: Pominal{
workSession: 1,
maxWorkSessions: 1,
cycle: 1,
countdown: 0,
work: 1000,
shortBreak: 60,
longBreak: 60,
workNotificationMsg: "",
shortBreakNotificationMsg: "",
longBreakNotificationMsg: "",
currentNotificationMsg: "",
label: "",
stopChan: nil,
},
},
{
name: "Test case 4",
description: "When creatng a Pominal where the maximum work sessions set below 1 (this covers unconfigured).",
config: PominalConfig{
MaxWorkSessions: -1,
Sessions: Sessions{
Work: SessionConfig{
Duration: "25m",
},
ShortBreak: SessionConfig{
Duration: "5m",
},
LongBreak: SessionConfig{
Duration: "20m",
},
},
},
expectedPominal: Pominal{
workSession: 1,
maxWorkSessions: defaultMaxWorkSessions,
cycle: 1,
countdown: 0,
work: 1500,
shortBreak: 300,
longBreak: 1200,
workNotificationMsg: "",
shortBreakNotificationMsg: "",
longBreakNotificationMsg: "",
currentNotificationMsg: "",
label: "",
stopChan: nil,
},
},
{
name: "Test case 5",
description: "When creatng a Pominal where the work session time is unconfigured.",
config: PominalConfig{
MaxWorkSessions: 4,
Sessions: Sessions{
Work: SessionConfig{},
ShortBreak: SessionConfig{
Duration: "10m",
},
LongBreak: SessionConfig{
Duration: "30m",
},
},
},
expectedPominal: Pominal{
workSession: 1,
maxWorkSessions: 4,
cycle: 1,
countdown: 0,
work: 1500,
shortBreak: 600,
longBreak: 1800,
workNotificationMsg: "",
shortBreakNotificationMsg: "",
longBreakNotificationMsg: "",
currentNotificationMsg: "",
label: "",
stopChan: nil,
},
},
}
var sessionsTestCases = []struct {
name string
description string
expectedWorkSession int
expectedCycle int
expectedLabel string
}{
{
name: "Test session 1",
description: "When the first work session has started.",
expectedWorkSession: 1,
expectedCycle: 1,
expectedLabel: workTimerLabel,
},
{
name: "Test session 2",
description: "When the first work session has finished and the short break session has started.",
expectedWorkSession: 1,
expectedCycle: 1,
expectedLabel: shortBreakTimerLabel,
},
{
name: "Test session 3",
description: "When the short break session has finished and the second work session has started.",
expectedWorkSession: 2,
expectedCycle: 1,
expectedLabel: workTimerLabel,
},
{
name: "Test session 4",
description: "When the second work session has finished and the long break has started.",
expectedWorkSession: 2,
expectedCycle: 1,
expectedLabel: longBreakTimerLabel,
},
{
name: "Test session 5",
description: "When the long break session has finished and the new work session has started for the next Pominal cycle.",
expectedWorkSession: 1,
expectedCycle: 2,
expectedLabel: workTimerLabel,
},
}