-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into TASK-163
- Loading branch information
Showing
10 changed files
with
205 additions
and
8 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
cypress/integration/unit/logic/schedule-parser/schedule.parser.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* eslint-disable @typescript-eslint/camelcase */ | ||
/// <reference types="cypress" /> | ||
import { ScheduleParser } from "../../../../../src/logic/schedule-parser/schedule.parser"; | ||
import { ScheduleDataModel } from "../../../../../src/common-models/schedule-data.model"; | ||
import { ShiftCode, ShiftInfoModel } from "../../../../../src/common-models/shift-info.model"; | ||
import { WorkersInfoModel, WorkerType } from "../../../../../src/common-models/worker-info.model"; | ||
|
||
function fillWorkerInfo( | ||
shifts: ShiftInfoModel, | ||
employeeInfo: WorkersInfoModel, | ||
section: string[][], | ||
sectionType: WorkerType | ||
): void { | ||
section.forEach((element) => { | ||
shifts[element[0]] = element.slice(1).map((x) => ShiftCode[x] ?? ShiftCode.W); | ||
employeeInfo.type[element[0]] = sectionType; | ||
employeeInfo.time[element[0]] = 1; | ||
}); | ||
} | ||
|
||
//#region data declaration | ||
const emptyRow = [""]; | ||
const dates = [28, 29, 30, 31, 1, 2, 3, 4, 5, 6]; | ||
const nurseSection = [ | ||
["pielęgniarka 1", "DN", " ", " ", " ", "U", "U", "U", "U", "U", "D"], | ||
["pielęgniarka 2", "DN", "DN", "U", "W", "U", "U", "U", "U", "U", "D"], | ||
["pielęgniarka 3", "N", " ", "L4", "D", "U", "U", "U", "U", "U", "D"], | ||
["pielęgniarka 4", "U", "U", "U", "U", "D", "D", "DN", "L4", "DN", "U"], | ||
["pielęgniarka 5", "DN", "L4", "L4", "W", "L4", "L4", "L4", "L4", "L4", "L4"], | ||
]; | ||
|
||
const babysitterSection = [ | ||
["opiekunka 1", "L4", "L4", "L4", "L4", "L4", "D", "N", "L4", "L4", "L4"], | ||
["opiekunka 2", "L4", "L4", "L4", "L4", "L4", "L4", "L4", "L4", "L4", "D"], | ||
]; | ||
|
||
const exampleData = [ | ||
["Grafik ", "miesiąc listopad", "rok 2020", "ilość godz 0"], | ||
["Dni miesiąca", ...dates.map((x) => x.toString())], | ||
emptyRow, | ||
["Dzieci", ...dates.map((x) => "1")], | ||
emptyRow, | ||
...nurseSection, | ||
emptyRow, | ||
...babysitterSection, | ||
]; | ||
|
||
const shifts: ShiftInfoModel = {}; | ||
const employee_info: WorkersInfoModel = { type: {}, time: {} }; | ||
|
||
fillWorkerInfo(shifts, employee_info, nurseSection, WorkerType.NURSE); | ||
fillWorkerInfo(shifts, employee_info, babysitterSection, WorkerType.OTHER); | ||
|
||
const expectedSchedule: ScheduleDataModel = { | ||
schedule_info: { month_number: 10, year: 2020, daysFromPreviousMonthExists: true }, | ||
shifts: shifts, | ||
month_info: { | ||
frozen_shifts: [], | ||
children_number: dates.map((x) => 1), | ||
dates: dates, | ||
}, | ||
employee_info: employee_info, | ||
}; | ||
|
||
//#endregion | ||
|
||
describe("Schedule parser", () => { | ||
const scheduleParser = new ScheduleParser(exampleData); | ||
const result = scheduleParser.schedule.getDataModel(); | ||
it("check if workerType was parsed correctly ", () => { | ||
for (const [key, value] of Object.entries(result.employee_info.type)) { | ||
expect(expectedSchedule.employee_info.type[key]).to.equal(value); | ||
} | ||
}); | ||
it("length of days must be equal to length of shifts", () => { | ||
for (const [, value] of Object.entries(result.shifts)) { | ||
expect(value).to.have.lengthOf(result.month_info.dates.length); | ||
} | ||
}); | ||
|
||
it("should check if input and output shifts are equal", () => { | ||
for (const [key, value] of Object.entries(result.shifts)) { | ||
expect(value).to.eql(expectedSchedule.shifts[key]); | ||
} | ||
}); | ||
it("all babysitter and nurses are in employee_info ", () => { | ||
expect(result.employee_info).to.have.keys(Object.keys(expectedSchedule.employee_info)); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.worker-info > p { | ||
margin-bottom: 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
import React from "react"; | ||
import { NameTableSection } from "./nametable-section.component"; | ||
import { BaseSectionOptions } from "../schedule-page/table/schedule/sections/base-section/base-section.component"; | ||
import { WorkerType } from "../../common-models/worker-info.model"; | ||
|
||
export function NameTableComponent(options: Partial<BaseSectionOptions>): JSX.Element { | ||
const { data = [] } = options; | ||
interface NameSectionOptions extends Partial<BaseSectionOptions> { | ||
workerType?: WorkerType; | ||
} | ||
|
||
export function NameTableComponent(options: NameSectionOptions): JSX.Element { | ||
const { data = [], workerType } = options; | ||
|
||
return ( | ||
<div> | ||
<NameTableSection dataRow={data} /> | ||
<NameTableSection dataRow={data} workerType={workerType} /> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from "react"; | ||
import { | ||
WorkerInfoModel, | ||
WorkerType, | ||
WorkerTypeHelper, | ||
} from "../../common-models/worker-info.model"; | ||
import { StringHelper } from "../../helpers/string.helper"; | ||
import classNames from "classnames/bind"; | ||
import { Button } from "../common-components"; | ||
|
||
export function WorkerInfoComponent(info: WorkerInfoModel): JSX.Element { | ||
return ( | ||
<> | ||
<div className={"span-errors"}> | ||
<div className={"workers-table"}> | ||
<span | ||
className={classNames("worker-label", `${info.type?.toString().toLowerCase()}-label`)} | ||
> | ||
{StringHelper.capitalize(WorkerTypeHelper.translate(info.type ?? WorkerType.OTHER))} | ||
</span> | ||
</div> | ||
<br /> | ||
<div className={"worker-info"}> | ||
<p>Typ umowy:</p> | ||
<p>Ilość godzin: {info.requiredHours}</p> | ||
<p>Ilość nadgodzin: {info.overtime}</p> | ||
<p>Suma godzin: {info.time}</p> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 17 additions & 2 deletions
19
src/components/workers-page/workers-tab/worker-drawer.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,39 @@ | ||
import React from "react"; | ||
import Drawer, { DrawerOptions } from "../../common-components/drawer/drawer.component"; | ||
import { WorkerInfoModel } from "../../../common-models/worker-info.model"; | ||
import { WorkerInfoComponent } from "../../namestable/worker-info.component"; | ||
|
||
export enum WorkerDrawerMode { | ||
EDIT, | ||
ADD_NEW, | ||
INFO, | ||
} | ||
|
||
interface WorkerDrawerOptions extends Omit<DrawerOptions, "title"> { | ||
mode: WorkerDrawerMode; | ||
worker?: WorkerInfoModel; | ||
} | ||
|
||
function getTitle(mode: WorkerDrawerMode): string { | ||
switch (mode) { | ||
case WorkerDrawerMode.EDIT: | ||
return "Edycja pracownika"; | ||
case WorkerDrawerMode.ADD_NEW: | ||
return "Dodaj pracownika"; | ||
case WorkerDrawerMode.INFO: | ||
return "Pracownik"; | ||
} | ||
} | ||
|
||
export default function WorkerDrawerComponent(options: WorkerDrawerOptions): JSX.Element { | ||
const { mode, worker, setOpen, ...otherOptions } = options; | ||
const title = mode === WorkerDrawerMode.ADD_NEW ? "Dodaj pracownika" : "Edycja pracownika"; | ||
|
||
const title = getTitle(mode); | ||
const isInfo = mode === WorkerDrawerMode.INFO; | ||
return ( | ||
<Drawer setOpen={setOpen} title={title} {...otherOptions}> | ||
{worker && <h1>{worker.name}</h1>} | ||
|
||
{isInfo && WorkerInfoComponent(worker ?? { name: "", time: 0 })} | ||
</Drawer> | ||
); | ||
} |