Skip to content

Commit

Permalink
fix _toConsumableArray scheduling error when builded
Browse files Browse the repository at this point in the history
  • Loading branch information
leovergaramarq committed May 22, 2024
1 parent ecbc54f commit 15e7a2a
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions src/services/schedule.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export async function schedule(

await page.goto(URL_SCHEDULE, {
timeout: 5000,
waitUntil: ["domcontentloaded", "networkidle0"]
waitUntil: ["domcontentloaded", "networkidle0"] // TODO: check if this is necessary
});

let newLogin;
Expand Down Expand Up @@ -438,11 +438,7 @@ async function scheduleByAdding(page, hours, cells) {
}

console.log("looking for scheduled hours...");
const scheduled = await page.evaluate(() =>
[...document.querySelectorAll(".ui-selecting-finished-FILLED")].map(
(el) => el.id
)
);
const scheduled = await getScheduledHours(page);
console.log("scheduled", scheduled);
scheduled.forEach(
(id) => cells.includes(+id.split("cell")[1]) && count++
Expand All @@ -461,11 +457,6 @@ async function scheduleByArea(page, hours, hoursDate, cells, hoursAvailable) {

// await page.waitForSelector("#cell0");

const getScheduledHours = () =>
[...document.querySelectorAll(".ui-selecting-finished-FILLED")].map(
(el) => el.id
);

try {
// schedule the whole week simulating drag and drop
const { mouse } = page;
Expand All @@ -486,7 +477,7 @@ async function scheduleByArea(page, hours, hoursDate, cells, hoursAvailable) {
}

// find hours already scheduled
const previouslyScheduled = await page.evaluate(getScheduledHours);
const previouslyScheduled = await getScheduledHours(page);
console.log("previouslyScheduled", previouslyScheduled);

const scheduleArea = async (cellFrom, cellTo) => {
Expand Down Expand Up @@ -544,7 +535,7 @@ async function scheduleByArea(page, hours, hoursDate, cells, hoursAvailable) {
}

// unschedule the unwanted hours
const scheduled = await page.evaluate(getScheduledHours); // get the hours scheduled after step 1
const scheduled = await getScheduledHours(page); // get the hours scheduled after step 1
console.log("scheduled so far", scheduled);

const toUnschedule = scheduled.filter((id) => {
Expand Down Expand Up @@ -637,13 +628,21 @@ async function waitForScheduleButton(page, timeout = 30000) {
}
}

function getHoursAvailable(page) {
async function getHoursAvailable(page) {
return (
page.evaluate(
(await page.evaluate(
() =>
+document.querySelector("#lblAvailableHours")?.textContent -
+document.querySelector("#lblScheduledHours")?.textContent
) || 0
)) || 0
);
}

async function getScheduledHours(page) {
return await page.evaluate(() =>
Array.from(
document.querySelectorAll(".ui-selecting-finished-FILLED")
).map((el) => el.id)
);
}

Expand Down

0 comments on commit 15e7a2a

Please sign in to comment.