@hexagramio/simple-libs
v0.0.7
Published
Some Simple Libs
Downloads
31
Readme
Some Useful Libs
Install
npm install @hexagramio/simple_libs
Scheduling States
import {ScheduleEntry, pickSchedule,} from "../src";
describe("daily schedule state", () => {
let schedule: ScheduleEntry[] = [
{time:{h:8,m:0},state:"wake"},
{time:{h:9,m:0},state:"sport"},
{time:{h:10,m:0},state:"work"},
{time:{h:12,m:0},state:"lunch"},
{time:{h:13,m:0},state:"work"},
{time:{h:18,m:0},state:"home"},
{time:{h:19,m:0},state:"dinner"},
{time:{h:20,m:0},state:"entertainment"},
{time:{h:23,m:0},state:"sleep"}
]
let scheduleNightOwl: ScheduleEntry[] = [
{time:{h:8,m:0},state:"wake"},
{time:{h:9,m:0},state:"sport"},
{time:{h:10,m:0},state:"work"},
{time:{h:12,m:0},state:"lunch"},
{time:{h:13,m:0},state:"work"},
{time:{h:18,m:0},state:"home"},
{time:{h:19,m:0},state:"dinner"},
{time:{h:21,m:0},state:"entertainment"},
{time:{h:1,m:0},state: [["party",0.2],["sleep",0.1]] }, //state array
{time:{h:3,m:0},state:"sleep"}
]
test('should return state when current state is null', async () => {
expect(pickSchedule(schedule,{h:12,m:5},"")).toBe("lunch")
});
test('should return state when current state is null', async () => {
expect(pickSchedule(schedule,{h:23,m:30},"")).toBe("sleep")
});
test('should return null when state is already the state', async () => {
expect(pickSchedule(schedule,{h:12,m:5},"lunch")).toBe(null)
});
test('should return the state that matches when the day overflows into the next one ', async () => {
expect(pickSchedule(schedule,{h:2,m:5},"")).toBe("sleep")
});
test('should return the state that matches when the day overflows into the next one ', async () => {
expect(["party","sleep"]).toContain(pickSchedule(scheduleNightOwl,{h:2,m:5},""))
});
test('should return the state that matches when the day overflows into the next one ', async () => {
expect(pickSchedule(scheduleNightOwl,{h:4,m:5},"")).toBe("sleep")
});
test('should return null that matches when the day overflows into the next one and its already at the state', async () => {
expect(pickSchedule(scheduleNightOwl,{h:4,m:5},"sleep")).toBe(null);
});
});