-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
536343b
commit c328c59
Showing
6 changed files
with
163 additions
and
4 deletions.
There are no files selected for viewing
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,41 @@ | ||
import { EntityDialog } from "@serenity-is/corelib"; | ||
import { waitForAjaxRequests } from "./waitutils"; | ||
|
||
export class EntityDialogTestWrapper<TDialog extends EntityDialog<any, any>> { | ||
constructor(public readonly actual: TDialog) { | ||
} | ||
|
||
clickDeleteButton(): Promise<void> { | ||
var button = this.actual.element.findFirst(".delete-button"); | ||
if (!button.length) | ||
throw "Delete button not found in the dialog!"; | ||
if (button.hasClass("disabled")) | ||
throw "Delete button is disabled!"; | ||
const spy = jest.spyOn(window, "confirm").mockReturnValue(true); | ||
button.click(); | ||
spy.mockRestore(); | ||
return waitForAjaxRequests(); | ||
} | ||
|
||
clickSaveButton(): Promise<void> { | ||
var button = this.actual.element.findFirst(".save-and-close-button"); | ||
if (!button.length) | ||
throw "Save button not found in the dialog!"; | ||
if (button.hasClass("disabled")) | ||
throw "Save button is disabled!"; | ||
button.click(); | ||
return waitForAjaxRequests(); | ||
} | ||
|
||
|
||
setTextInput(name: string, value: any) { | ||
var input = this.actual["byId"](name); | ||
if (!input.length) | ||
throw `Input not found in the dialog: ${name}!`; | ||
input.val(value).trigger("change"); | ||
} | ||
|
||
waitForAjaxRequests(timeout: number = 10000): Promise<void> { | ||
return waitForAjaxRequests(timeout); | ||
} | ||
} |
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 +1,3 @@ | ||
export * from "./mocks"; | ||
export * from "./entitydialogutils"; | ||
export * from "./mocks"; | ||
export * from "./waitutils"; |
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
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,22 @@ | ||
import { getActiveRequests } from "@serenity-is/corelib"; | ||
|
||
export function waitForAjaxRequests(timeout: number = 10000): Promise<void> { | ||
return waitUntil(() => typeof globalThis.jQuery !== 'undefined' ? globalThis.jQuery.active == 0 : (getActiveRequests() <= 0), timeout); | ||
} | ||
|
||
export function waitUntil(predicate: () => boolean, timeout: number = 10000, checkInterval: number = 10): Promise<void> { | ||
var start = Date.now(); | ||
return new Promise((resolve, reject) => { | ||
let interval = setInterval(() => { | ||
if (!predicate()) { | ||
if (Date.now() - start > timeout) { | ||
clearInterval(interval); | ||
reject("Timed out while waiting for condition to be true!"); | ||
} | ||
return; | ||
} | ||
clearInterval(interval); | ||
resolve(void 0); | ||
}, checkInterval) | ||
}) | ||
} |