Load projects and initialize form with last project and task

This commit is contained in:
Manuel Bouza
2019-02-06 18:55:10 +01:00
parent 49aa36bf54
commit 7ad7cab5c0
16 changed files with 783 additions and 125 deletions

108
test/data.js Normal file
View File

@@ -0,0 +1,108 @@
export const projects = [
{
id: 944868981,
name: "Browser Extension",
customer_name: "Simplificator",
intern: false,
identifier: "137",
tasks: [
{
id: 2733682,
name: "Bugfixing",
billable: true
},
{
id: 2733681,
name: "Development",
billable: true
}
]
},
{
id: 944724773,
name: "Development",
customer_name: "MOCO APP",
intern: false,
identifier: "116",
tasks: [
{
id: 1621304,
name: "Roadmap Features",
billable: true
},
{
id: 1621310,
name: "Bugfixing",
billable: true
},
{
id: 1621305,
name: "Quickwins",
billable: true
},
{
id: 1621323,
name: "Refactorings",
billable: true
}
]
},
{
id: 944837106,
name: "Support",
customer_name: "MOCO APP",
intern: false,
identifier: "130",
tasks: [
{
id: 2500080,
name: "Intercom & Mails",
billable: false
},
{
id: 2500081,
name: "Demos",
billable: false
},
{
id: 2506050,
name: "Calls",
billable: false
},
{
id: 2500084,
name: "Importe",
billable: false
}
]
},
{
id: 944621413,
name: "Tech Consulting",
customer_name: "sharoo",
intern: false,
identifier: "97",
tasks: [
{
id: 874014,
name: "Entwicklung",
billable: true
},
{
id: 874015,
name: "Grafik",
billable: true
},
{
id: 874016,
name: "Konzept",
billable: true
},
{
id: 874017,
name: "Projektleitung",
billable: true
}
]
}
]

65
test/utils.test.js Normal file
View File

@@ -0,0 +1,65 @@
import { projects } from "./data"
import {
findLastProject,
findLastTask,
groupedProjectOptions
} from "../src/js/utils"
import { map } from "lodash/fp"
describe("utils", () => {
describe("findLastProject", () => {
it("finds an existing project", () => {
const options = groupedProjectOptions(projects)
const project = findLastProject(944837106)(options)
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 options = groupedProjectOptions(projects)
const project = findLastProject(123)(options)
expect(project).toBe(undefined)
})
it("returns undefined for undefined id", () => {
const options = groupedProjectOptions(projects)
const project = findLastProject(undefined)(options)
expect(project).toBe(undefined)
})
})
describe("findLastTask", () => {
it("find an existing task", () => {
const options = groupedProjectOptions(projects)
const project = findLastProject(944837106)(options)
const task = findLastTask(2506050)(project)
expect(task.value).toEqual(2506050)
expect(task.label).toEqual("Calls")
})
it("returns undefined if task is not found", () => {
const options = groupedProjectOptions(projects)
const project = findLastProject(944837106)(options)
const task = findLastTask(123)(project)
expect(task).toBe(undefined)
})
it("returns undefined for undefined project", () => {
const task = findLastTask(2506050)(undefined)
expect(task).toBe(undefined)
})
})
describe("groupedProjectOptions", () => {
it("transforms projects into grouped options by company", () => {
const result = groupedProjectOptions(projects)
expect(map("label", result)).toEqual([
"Simplificator",
"MOCO APP",
"sharoo"
])
})
})
})