mocoapp-browser-extension/test/utils/index.test.js
Manuel Bouza 72626a6c42
qw/timer (#23)
* Rename logo and add 32x32 version

* Set timer icon if a timer is running

* Do not query activities on initialization

* Show timer in bubble if timed activity exists

* Pass timed activity to App

* Code cleanup

* Show timer view and stop timer

* Make hours optional

* Use booked seconds instead of hours

* Add type submit to form button

* Define colors as sass variables⎄

* Style timer view

* Show start timer submit label

* Update view layouts and content

* Update version and changelog

* Dyanically set iframe height

* Reduce h1 font size

* Add svg webpack loader

* Parse empty string (TimeInputParser)

* Forward ref in Popup component

* Start time on current day only, format buttons

* Improve styling

* Set standard height as iframe default height, validate form

* Upgrade packages to supress react warning

* Show activity form in popup after timer was stoped

* Use stop-watch icon in timer view

* Fix empty description

* Close TimerView if timer stopped for current service

* Style timerview

* Improve timer view styling

* qw/setting-time-tracking-hh-mm (#24)

* Format duration depending on settingTimeTrackingHHMM

* Fix formatDuation without second argument

* Fix time format after updating bubble

* Add tests for formatDuration
2019-10-10 14:57:01 +02:00

164 lines
4.8 KiB
JavaScript

import { projects } from "../data"
import {
findProjectByValue,
findProjectByIdentifier,
findTask,
defaultTask,
groupedProjectOptions,
extractAndSetTag,
formatDuration,
} from "../../src/js/utils"
import { map, compose } from "lodash/fp"
const getProjectBy = finder => key =>
compose(
finder(key),
groupedProjectOptions,
)(projects)
const getProjectByValue = getProjectBy(findProjectByValue)
const getProjectByIdentifier = getProjectBy(findProjectByIdentifier)
describe("utils", () => {
describe("findProjectByValue", () => {
it("finds an existing project", () => {
const project = getProjectByValue(944837106)
expect(project.value).toEqual(944837106)
expect(project.label).toEqual("Support")
expect(project.customerName).toEqual("MOCO APP")
expect(project.tasks).toHaveLength(4)
})
it("returns undefined if project is not found", () => {
const project = getProjectByValue(123)
expect(project).toBe(undefined)
})
it("returns undefined for undefined id", () => {
const project = getProjectByValue(undefined)
expect(project).toBe(undefined)
})
})
describe("findProjectByIdentifier", () => {
it("finds an existing project", () => {
const options = groupedProjectOptions(projects)
const project = findProjectByIdentifier("130")(options)
expect(project.identifier).toEqual("130")
expect(project.label).toEqual("Support")
expect(project.customerName).toEqual("MOCO APP")
expect(project.tasks).toHaveLength(4)
})
it("returns undefined if project is not found", () => {
const options = groupedProjectOptions(projects)
const project = findProjectByIdentifier("non-existing")(options)
expect(project).toBe(undefined)
})
it("returns undefined for undefined id", () => {
const options = groupedProjectOptions(projects)
const project = findProjectByIdentifier(undefined)(options)
expect(project).toBe(undefined)
})
})
describe("findTask", () => {
it("find an existing task", () => {
const project = getProjectByValue(944837106)
const task = findTask(2506050)(project)
expect(task.value).toEqual(2506050)
expect(task.label).toEqual("(Calls)")
})
it("returns undefined if task is not found", () => {
const project = getProjectByValue(944837106)
const task = findTask(123)(project)
expect(task).toBe(undefined)
})
it("returns undefined for undefined project", () => {
const task = findTask(2506050)(undefined)
expect(task).toBe(undefined)
})
})
describe("defaultTask", () => {
it("find a default task", () => {
const project = getProjectByValue(944837106)
const task = defaultTask(project.tasks)
expect(task.label).toBe("(Demos)")
})
it("returns first task if no default is defined", () => {
const project = getProjectByValue(944621413)
const task = defaultTask(project.tasks)
expect(task.label).toBe("Entwicklung")
})
it("return undefined if no tasks given", () => {
let task = defaultTask(null)
expect(task).toBeUndefined()
task = defaultTask([])
expect(task).toBeUndefined()
})
})
describe("groupedProjectOptions", () => {
it("transforms projects into grouped options by company", () => {
const result = groupedProjectOptions(projects)
expect(map("label", result)).toEqual(["Simplificator", "MOCO APP", "sharoo"])
})
})
describe("extractAndSetTag", () => {
it("sets the correct tag and updates description", () => {
const changeset = {
description: "#meeting Lorem ipsum",
tag: "",
}
expect(extractAndSetTag(changeset)).toEqual({
description: "Lorem ipsum",
tag: "meeting",
})
})
it("only matches tag at the beginning", () => {
const changeset = {
description: "Lorem #meeting ipsum",
tag: "",
}
expect(extractAndSetTag(changeset)).toEqual(changeset)
})
it("returns the changeset if not tag is set", () => {
const changeset = {
description: "Without tag",
tag: "",
}
expect(extractAndSetTag(changeset)).toEqual(changeset)
})
})
describe("formatDuration", () => {
it("format with defaults", () => {
expect(formatDuration(3600)).toBe("1:00:00")
expect(formatDuration(3661)).toBe("1:01:01")
})
it("format without seconds", () => {
expect(formatDuration(3600, { showSeconds: false })).toBe("1:00")
expect(formatDuration(3661, { showSeconds: false })).toBe("1:01")
})
it("format in decimals", () => {
expect(formatDuration(3600, { settingTimeTrackingHHMM: false })).toBe("1.00")
expect(formatDuration(3661, { settingTimeTrackingHHMM: false })).toBe("1.02")
})
})
})