Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
georgegevoian committed Oct 10, 2023
1 parent c18426f commit 114d115
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 43 deletions.
5 changes: 2 additions & 3 deletions calendar/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,6 @@ class CalendarHandler {
const isEventInRange = (
(event.start >= dateRangeStart && event.start <= dateRangeEnd) ||
(event.end >= dateRangeStart && event.end <= dateRangeEnd) ||
(event.start >= dateRangeStart && event.start <= dateRangeEnd) ||
(event.start < dateRangeStart && event.end > dateRangeEnd)
);
if (!isEventInRange) { continue; }
Expand Down Expand Up @@ -688,7 +687,7 @@ function testGetCalendarEvent(eventId) {
endDate: event.end,
isAllDay: event.isAllday,
};
return JSON.stringify(eventData);
return eventData;
}

function testGetVisibleCalendarEvent(eventId) {
Expand All @@ -702,7 +701,7 @@ function testGetVisibleCalendarEvent(eventId) {
isAllDay: event?.isAllday ?? false,
selected: event?.borderColor === calendarHandler._selectedColor,
};
return JSON.stringify(eventData);
return eventData;
}

function testGetCalendarViewName(){
Expand Down
33 changes: 15 additions & 18 deletions test/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,28 @@ describe('calendar', function () {
});
}

// Not a pretty way to get events from currently used calendar control. but it's working.
function buildGetVisibleCalendarEvent(eventId: number) {
return `return testGetVisibleCalendarEvent(${eventId});`
}

async function getVisibleCalendarEvent(eventId: number): Promise<any> {
const event = await grist.executeScriptOnCustomWidget(buildGetVisibleCalendarEvent(eventId));
return JSON.parse(event as any);
}

function buildGetCalendarEvent(eventId: number) {
return `return testGetCalendarEvent(${eventId});`
return grist.inCustomWidget(() => {
return (window as any).testGetVisibleCalendarEvent(eventId);
});
}

async function getCalendarEvent(eventId: number): Promise<any> {
const event = await grist.executeScriptOnCustomWidget(buildGetCalendarEvent(eventId));
return JSON.parse(event as any);
return grist.inCustomWidget(() => {
return (window as any).testGetCalendarEvent(eventId);
});
}

async function getCalendarViewName(): Promise<string> {
return await grist.executeScriptOnCustomWidget('return testGetCalendarViewName()');
return grist.inCustomWidget(() => {
return (window as any).testGetCalendarViewName();
});
}

async function getDateVersion(): Promise<Date> {
return await grist.executeScriptOnCustomWidget('return testGetDataVersion()');
return grist.inCustomWidget(() => {
return (window as any).testGetDataVersion();
});
}

before(async function () {
Expand Down Expand Up @@ -140,9 +137,9 @@ describe('calendar', function () {
it('should navigate to appropriate time periods when button is pressed', async function () {
const today = new Date();
const validateDate = async (daysToAdd: number) => {
const newDate = await grist.executeScriptOnCustomWidget(
'return calendarHandler.calendar.getDate().d.toDate().toDateString()'
);
const newDate = await grist.inCustomWidget(() => {
return (window as any).calendarHandler.calendar.getDate().d.toDate().toDateString();
});

const expectedDate = new Date(today);
expectedDate.setDate(today.getDate() + daysToAdd);
Expand Down
27 changes: 5 additions & 22 deletions test/getGrist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,28 +263,6 @@ export class GristUtils extends GristWebDriverUtils {
await clickOption(value);
}

// Crude, assumes a single iframe. Should elaborate.
public async getCustomWidgetBody(selector: string = 'html'): Promise<string> {
const iframe = this.driver.find('iframe');
try {
await this.driver.switchTo().frame(iframe);
return await this.driver.find(selector).getText();
} finally {
await this.driver.switchTo().defaultContent();
}
}

public async executeScriptOnCustomWidget<T>(script: string | Function): Promise<T> {
const iframe = this.driver.find('iframe');
try {
await this.driver.switchTo().frame(iframe);
const jsValue = await this.driver.executeScript(script);
return jsValue as T;
} finally {
await this.driver.switchTo().defaultContent();
}
}

public async inCustomWidget<T>(op: () => Promise<T>): Promise<T> {
const iframe = driver.find('iframe');
try {
Expand All @@ -294,4 +272,9 @@ export class GristUtils extends GristWebDriverUtils {
await driver.switchTo().defaultContent();
}
}

// Crude, assumes a single iframe. Should elaborate.
public async getCustomWidgetBody(selector: string = 'html'): Promise<string> {
return this.inCustomWidget(() => this.driver.find(selector).getText());
}
}

0 comments on commit 114d115

Please sign in to comment.