0.0.7 • Published 2 years ago

@hexagramio/simple-libs v0.0.7

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

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);
  });

});
0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago