2022-06-23 12:07:53 +00:00
/* eslint max-len: ["error", { "code": 150 }]*/
2019-06-04 05:57:01 +00:00
import selectors from '../../helpers/selectors.js' ;
2020-01-14 08:24:09 +00:00
import getBrowser from '../../helpers/puppeteer' ;
2019-06-04 05:57:01 +00:00
2022-12-28 12:06:00 +00:00
fdescribe ( 'Worker time control path' , ( ) => {
2020-01-14 08:24:09 +00:00
let browser ;
let page ;
beforeAll ( async ( ) => {
browser = await getBrowser ( ) ;
page = browser . page ;
await page . loginAndModule ( 'salesBoss' , 'worker' ) ;
await page . accessToSearchResult ( 'HankPym' ) ;
await page . accessToSection ( 'worker.card.timeControl' ) ;
} ) ;
2019-06-04 05:57:01 +00:00
2020-01-14 08:24:09 +00:00
afterAll ( async ( ) => {
2020-01-14 08:41:49 +00:00
await browser . close ( ) ;
2019-06-04 05:57:01 +00:00
} ) ;
2022-06-28 10:10:37 +00:00
const eightAm = '08:00' ;
2022-06-23 12:07:53 +00:00
const fourPm = '16:00' ;
const hankPymId = 1107 ;
2019-06-04 05:57:01 +00:00
2022-12-28 12:06:00 +00:00
it ( ` should go to the next month, go to current month, go 1 month in the past, return error when insert 'out' of first entry, then insert 'in' monday, then insert 'out' monday, then check if Hank Pym worked 8:20 hours, remove first entry of monday, be the 'out' the first entry of monday and change week of month ` , async ( ) => {
let date = new Date ( ) ;
2022-06-23 12:07:53 +00:00
date . setMonth ( date . getMonth ( ) + 1 ) ;
2022-12-28 12:06:00 +00:00
let month = date . toLocaleString ( 'default' , { month : 'long' } ) ;
2019-06-04 05:57:01 +00:00
2022-12-28 12:06:00 +00:00
await page . click ( selectors . workerTimeControl . nextMonthButton ) ;
2020-01-14 08:24:09 +00:00
2022-12-28 12:06:00 +00:00
expect ( await page . getProperty ( selectors . workerTimeControl . monthName , 'innerText' ) ) . toContain ( month ) ;
2019-06-04 05:57:01 +00:00
2022-12-28 12:06:00 +00:00
date = new Date ( ) ;
month = date . toLocaleString ( 'default' , { month : 'long' } ) ;
2019-06-04 05:57:01 +00:00
2022-12-28 12:06:00 +00:00
await page . click ( selectors . workerTimeControl . previousMonthButton ) ;
2019-06-04 05:57:01 +00:00
2022-12-28 12:06:00 +00:00
expect ( await page . getProperty ( selectors . workerTimeControl . monthName , 'innerText' ) ) . toContain ( month ) ;
2019-06-04 05:57:01 +00:00
2022-12-28 12:06:00 +00:00
date = new Date ( ) ;
2022-06-23 12:07:53 +00:00
date . setMonth ( date . getMonth ( ) - 1 ) ;
2022-12-28 12:06:00 +00:00
month = date . toLocaleString ( 'default' , { month : 'long' } ) ;
2022-06-23 12:07:53 +00:00
const timestamp = Math . round ( date . getTime ( ) / 1000 ) ;
await page . loginAndModule ( 'salesBoss' , 'worker' ) ;
await page . goto ( ` http://localhost:5000/#!/worker/ ${ hankPymId } /time-control?timestamp= ${ timestamp } ` ) ;
2022-12-28 12:06:00 +00:00
await page . click ( selectors . workerTimeControl . secondWeekDay ) ;
2019-06-04 05:57:01 +00:00
2022-12-28 12:06:00 +00:00
expect ( await page . getProperty ( selectors . workerTimeControl . monthName , 'innerText' ) ) . toContain ( month ) ;
2019-06-04 05:57:01 +00:00
2022-12-28 12:06:00 +00:00
await page . click ( selectors . workerTimeControl . mondayAddTimeButton ) ;
2022-06-28 10:10:37 +00:00
await page . pickTime ( selectors . workerTimeControl . dialogTimeInput , eightAm ) ;
2022-06-23 12:07:53 +00:00
await page . autocompleteSearch ( selectors . workerTimeControl . dialogTimeDirection , 'out' ) ;
await page . respondToDialog ( 'accept' ) ;
2022-12-28 12:06:00 +00:00
let message = await page . waitForSnackbar ( ) ;
2019-06-04 05:57:01 +00:00
2022-06-23 12:07:53 +00:00
expect ( message . text ) . toBeDefined ( ) ;
2019-06-04 05:57:01 +00:00
2022-12-28 12:06:00 +00:00
await page . click ( selectors . workerTimeControl . mondayAddTimeButton ) ;
2022-06-28 10:10:37 +00:00
await page . pickTime ( selectors . workerTimeControl . dialogTimeInput , eightAm ) ;
2022-06-23 12:07:53 +00:00
await page . autocompleteSearch ( selectors . workerTimeControl . dialogTimeDirection , 'in' ) ;
await page . respondToDialog ( 'accept' ) ;
2019-06-04 05:57:01 +00:00
2022-12-28 12:06:00 +00:00
expect ( await page . getProperty ( selectors . workerTimeControl . firstEntryOfMonday , 'innerText' ) ) . toEqual ( eightAm ) ;
2019-06-04 05:57:01 +00:00
2022-12-28 12:06:00 +00:00
await page . click ( selectors . workerTimeControl . mondayAddTimeButton ) ;
2022-06-23 12:07:53 +00:00
await page . pickTime ( selectors . workerTimeControl . dialogTimeInput , fourPm ) ;
await page . autocompleteSearch ( selectors . workerTimeControl . dialogTimeDirection , 'out' ) ;
await page . respondToDialog ( 'accept' ) ;
2019-06-04 05:57:01 +00:00
2022-12-28 12:06:00 +00:00
expect ( await page . getProperty ( selectors . workerTimeControl . secondEntryOfMonday , 'innerText' ) ) . toEqual ( fourPm ) ;
2019-06-04 05:57:01 +00:00
2022-12-28 12:06:00 +00:00
expect ( await page . getProperty ( selectors . workerTimeControl . mondayWorkedHours , 'innerText' ) ) . toBe ( '08:20 h.' ) ;
expect ( await page . getProperty ( selectors . workerTimeControl . weekWorkedHours , 'innerText' ) ) . toBe ( '08:20 h.' ) ;
expect ( await page . getProperty ( selectors . workerTimeControl . firstEntryOfMonday , 'innerText' ) ) . toBe ( eightAm ) ;
expect ( await page . getProperty ( selectors . workerTimeControl . secondEntryOfMonday , 'innerText' ) ) . toBe ( fourPm ) ;
await page . click ( selectors . workerTimeControl . firstEntryOfMondayDelete ) ;
2022-06-23 12:07:53 +00:00
await page . respondToDialog ( 'accept' ) ;
2022-12-28 12:06:00 +00:00
message = await page . waitForSnackbar ( ) ;
2019-06-04 05:57:01 +00:00
2022-06-23 12:07:53 +00:00
expect ( message . text ) . toContain ( 'Entry removed' ) ;
2020-01-16 12:40:51 +00:00
2022-12-28 12:06:00 +00:00
const result = await page . getProperty ( selectors . workerTimeControl . firstEntryOfMonday , 'innerText' ) ;
2019-06-04 05:57:01 +00:00
2022-06-23 12:07:53 +00:00
expect ( result ) . toEqual ( fourPm ) ;
2019-06-04 05:57:01 +00:00
2022-12-28 12:06:00 +00:00
await page . click ( selectors . workerTimeControl . thrirdWeekDay ) ;
expect ( await page . getProperty ( selectors . workerTimeControl . mondayWorkedHours , 'innerText' ) ) . toBe ( '00:00 h.' ) ;
2019-06-04 05:57:01 +00:00
} ) ;
} ) ;