Best JavaScript code snippet using wpt
ReservableAreaHandle.ts
Source:ReservableAreaHandle.ts
1import { ElementHandle, Page } from 'puppeteer';2import { TimeSlotManager, TimeSlot } from '../../utils/TimeSlotManager';3import { ReserveButton } from './ReserveButton';4export class ReservableAreaHandle {5 private element: ElementHandle;6 private day: string;7 private page: Page;8 private SELECTOR: { [key: string]: string } = {9 RESERVABLE_BUTTON: '.btn_style.btn_green.forReservation',10 DOUBLE_BOOKING_BUTTON: '.btn_style.double_booking',11 ALREADY_RSERVED_BUTTON: '.btn_style.reserved.forCancellation',12 };13 constructor(page: Page, reservableAreaElement: ElementHandle) {14 this.element = reservableAreaElement;15 this.day = '';16 this.page = page;17 }18 private async setDay(): Promise<string> {19 this.day = await this.element.$eval('.day', (node) =>20 (node as HTMLElement).innerText.substring(1, 2),21 );22 return this.day;23 }24 private async isConvenientDay(timeSlot: TimeSlot): Promise<boolean> {25 if (!Object.prototype.hasOwnProperty.call(timeSlot, this.day)) {26 console.log(`${this.day} is not convenient day`);27 return false;28 }29 return true;30 }31 private async isDoubleBookingDay(): Promise<boolean> {32 const doubleBookingElement = await this.element.$(33 this.SELECTOR.DOUBLE_BOOKING_BUTTON,34 );35 if (doubleBookingElement) {36 console.log(`${this.day} has double booking`);37 return true;38 }39 return false;40 }41 private async isReservedDay(): Promise<boolean> {42 const alreadyRservedElement = await this.element.$(43 this.SELECTOR.ALREADY_RSERVED_BUTTON,44 );45 if (alreadyRservedElement) {46 console.log(`${this.day} has already reserved`);47 return true;48 }49 return false;50 }51 private async findReservableTimeFromTimeSlot(52 timeSlot: TimeSlot,53 ): Promise<ReserveButton | null> {54 const reserveButtons = await this.element.$$(55 this.SELECTOR.RESERVABLE_BUTTON,56 );57 if (reserveButtons.length === 0) {58 console.log(`Reservable time not found in ${this.day}`);59 return null;60 }61 for (const reserveButton of reserveButtons) {62 try {63 const time = await this.page.evaluate(64 (node) => (node as HTMLElement).innerText,65 reserveButton,66 );67 if (timeSlot[this.day].indexOf(time) === -1) {68 continue;69 }70 return new ReserveButton(this.page, reserveButton, time);71 } catch (e) {72 console.log(e);73 continue;74 }75 }76 console.log(`Convenient time slot not found in ${this.day}`);77 return null;78 }79 async findReservableTime(): Promise<ReserveButton | null> {80 await this.setDay();81 const timeSlot = TimeSlotManager.getConvenientTimeSlot();82 if (83 !(await this.isConvenientDay(timeSlot)) ||84 (await this.isDoubleBookingDay()) ||85 (await this.isReservedDay())86 ) {87 return null;88 }89 return this.findReservableTimeFromTimeSlot(timeSlot);90 }...
TimeSlotManager.ts
Source:TimeSlotManager.ts
1import { TimeSlotManager } from '../TimeSlotManager';2describe('TimeSLotManager', () => {3 beforeAll(() => {4 jest.useFakeTimers('modern');5 });6 test('When it is 21:59 JST, do not remove next day from convenient time slot', () => {7 jest.setSystemTime(new Date('Wed, 26 Aug 2020 21:59:00 +0900'));8 const actual = TimeSlotManager.getConvenientTimeSlot();9 const expectTimeSlot = {10 æ: ['08:00', '08:30', '09:00'],11 æ¨: ['08:00', '08:30', '09:00'],12 æ°´: ['08:00', '08:30', '09:00'],13 ç«: ['08:00', '08:30', '09:00'],14 é: ['08:00', '08:30', '09:00'],15 };16 expect(actual).toEqual(expectTimeSlot);17 });18 test('When it is 22:00 JST, remove next day from convenient time slot', () => {19 jest.setSystemTime(new Date('Wed, 26 Aug 2020 22:00:00 +0900'));20 const actual = TimeSlotManager.getConvenientTimeSlot();21 const expectTimeSlot = {22 æ: ['08:00', '08:30', '09:00'],23 æ°´: ['08:00', '08:30', '09:00'],24 ç«: ['08:00', '08:30', '09:00'],25 é: ['08:00', '08:30', '09:00'],26 };27 expect(actual).toEqual(expectTimeSlot);28 });29 test('When it is 0:00 JST, remove today from convenient time slot', () => {30 jest.setSystemTime(new Date('Thu, 27 Aug 2020 00:00:00 +0900'));31 const actual = TimeSlotManager.getConvenientTimeSlot();32 const expectTimeSlot = {33 æ: ['08:00', '08:30', '09:00'],34 æ°´: ['08:00', '08:30', '09:00'],35 ç«: ['08:00', '08:30', '09:00'],36 é: ['08:00', '08:30', '09:00'],37 };38 expect(actual).toEqual(expectTimeSlot);39 });40 test('When it is 9:00 JST, remove today from convenient time slot', () => {41 jest.setSystemTime(new Date('Thu, 27 Aug 2020 09:00:00 +0900'));42 const actual = TimeSlotManager.getConvenientTimeSlot();43 const expectTimeSlot = {44 æ: ['08:00', '08:30', '09:00'],45 æ°´: ['08:00', '08:30', '09:00'],46 ç«: ['08:00', '08:30', '09:00'],47 é: ['08:00', '08:30', '09:00'],48 };49 expect(actual).toEqual(expectTimeSlot);50 });51 test('When it is 10:00 JST, remove today from convenient time slot', () => {52 jest.setSystemTime(new Date('Thu, 27 Aug 2020 10:00:00 +0900'));53 const actual = TimeSlotManager.getConvenientTimeSlot();54 const expectTimeSlot = {55 æ: ['08:00', '08:30', '09:00'],56 æ¨: ['08:00', '08:30', '09:00'],57 æ°´: ['08:00', '08:30', '09:00'],58 ç«: ['08:00', '08:30', '09:00'],59 é: ['08:00', '08:30', '09:00'],60 };61 expect(actual).toEqual(expectTimeSlot);62 });...
importModule.js
Source:importModule.js
1const LanguageManager = require('./src/managers/LanguageManager')2const dao = require('./src/managers/dao')3const SkillsManager = require('./src/managers/SkillsManager')4const MeetingManager = require('./src/managers/MeetingManager')5const ProvinceManager = require('./src/managers/ProvinceManager')6const CriteriaManager = require('./src/managers/CriteriaManager')7const CareerDayManager = require('./src/managers/CareerDayManager')8const UserManager = require('./src/managers/UserManager')9const EnterpriseManager = require('./src/managers/EntrepriseManager')10const EmployeeManager = require('./src/managers/EmplyeeManager')11const StudentManager = require('./src/managers/StudentManager')12const RoleManager = require('./src/managers/RoleManager')13const TimeSlotManager = require('./src/managers/TimeSlotManager')14const AttendanceManager = require('./src/managers/AttendanceManager')15const ProgramManager = require('./src/managers/ProgramManager')16const NotificationManager = require('./src/managers/NotificationManager')17const awsRoute = require('./src/rest-module/awsRoute')18module.exports = {19 LanguageManager,20 dao,21 SkillsManager,22 CriteriaManager,23 CareerDayManager,24 ProvinceManager,25 MeetingManager,26 UserManager,27 EnterpriseManager,28 EmployeeManager,29 StudentManager,30 RoleManager,31 TimeSlotManager,32 AttendanceManager,33 ProgramManager,34 NotificationManager,35 awsRoute...
Using AI Code Generation
1const TimeSlotManager = require('./wpt-api').TimeSlotManager;2const TimeSlot = require('./wpt-api').TimeSlot;3let timeSlotManager = new TimeSlotManager();4let timeSlot = new TimeSlot('2017-01-01T00:00:00Z','2017-01-01T00:30:00Z');5timeSlotManager.addTimeSlot(timeSlot);6timeSlot = new TimeSlot('2017-01-01T00:30:00Z','2017-01-01T01:00:00Z');7timeSlotManager.addTimeSlot(timeSlot);8timeSlot = new TimeSlot('2017-01-01T01:00:00Z','2017-01-01T01:30:00Z');9timeSlotManager.addTimeSlot(timeSlot);10timeSlot = new TimeSlot('2017-01-01T01:30:00Z','2017-01-01T02:00:00Z');11timeSlotManager.addTimeSlot(timeSlot);12timeSlot = new TimeSlot('2017-01-01T02:00:00Z','2017-01-01T02:30:00Z');13timeSlotManager.addTimeSlot(timeSlot);14timeSlot = new TimeSlot('2017-01-01T02:30:00Z','2017-01-01T03:00:00Z');15timeSlotManager.addTimeSlot(timeSlot);16timeSlot = new TimeSlot('2017-01-01T03:00:00Z','2017-01-01T03:30:00Z');17timeSlotManager.addTimeSlot(timeSlot);
Using AI Code Generation
1const TimeSlotManager = require('../wpt-api').TimeSlotManager;2let tsm = new TimeSlotManager();3let timeslots = tsm.getTimeslotsForDate('2018-02-14');4console.log(timeslots);5let timeslots2 = tsm.getTimeslotsForDateTime('2018-02-14', '15:00');6console.log(timeslots2);7let timeslots3 = tsm.getTimeslotsForDateTime('2018-02-14', '15:00', '2018-02-14');8console.log(timeslots3);9let timeslots4 = tsm.getTimeslotsForDateTime('2018-02-14', '15:00', '2018-02-14', '16:00');10console.log(timeslots4);11let timeslots5 = tsm.getTimeslotsForDateTime('2018-02-14', '15:00', '2018-02-14', '16:00', 3);12console.log(timeslots5);13let timeslots6 = tsm.getTimeslotsForDateTime('2018-02-14', '15:00', '2018-02-14', '16:00', 3, 30);14console.log(timeslots6);15let timeslots7 = tsm.getTimeslotsForDateTime('2018-02-14', '15:00', '2018-02-14', '16:00', 3, 30, 2);16console.log(timeslots7);17let timeslots8 = tsm.getTimeslotsForDateTime('2018-02-14
Using AI Code Generation
1var TimeSlotManager = require('./TimeSlotManager.js');2var tsManager = new TimeSlotManager();3tsManager.init();4tsManager.addTimeSlot('2016-10-10', '10:00', '11:00');5tsManager.addTimeSlot('2016-10-10', '11:00', '12:00');6tsManager.addTimeSlot('2016-10-10', '12:00', '13:00');7tsManager.addTimeSlot('2016-10-10', '13:00', '14:00');8tsManager.addTimeSlot('2016-10-10', '14:00', '15:00');9tsManager.addTimeSlot('2016-10-10', '15:00', '16:00');10tsManager.addTimeSlot('2016-10-10', '16:00', '17:00');11tsManager.addTimeSlot('2016-10-10', '17:00', '18:00');12tsManager.addTimeSlot('2016-10-10', '18:00', '19:00');13tsManager.addTimeSlot('2016-10-10', '19:00', '20:00');14tsManager.addTimeSlot('2016-10-10', '20:00', '21:00');15tsManager.addTimeSlot('2016-10-10', '21:00', '22:00');16tsManager.addTimeSlot('2016-10-10', '22:00', '23:00');17tsManager.addTimeSlot('2016-10-10', '23:00', '24:00');18var availSlots = tsManager.getAvailableTimeSlots('2016-10-10', '10:00', '12:00');19console.log(availSlots);
Using AI Code Generation
1var tsm = require('./tsm.js');2var tsmObj = new tsm.TimeSlotManager();3var test = function() {4 var tsmObj = new tsm.TimeSlotManager();5 var timeSlot = {6 };7 var timeSlot2 = {8 };9 var timeSlot3 = {10 };11 var timeSlot4 = {12 };13 var timeSlot5 = {14 };15 var timeSlot6 = {16 };17 var timeSlot7 = {18 };19 var timeSlot8 = {20 };21 var timeSlot9 = {
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!