mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-11 09:41:41 +00:00
test(discord): stabilize model picker timeout assertions
This commit is contained in:
@@ -44,6 +44,21 @@ function createModelsProviderData(entries: Record<string, string[]>): ModelsProv
|
|||||||
return createBaseModelsProviderData(entries, { defaultProviderOrder: "sorted" });
|
return createBaseModelsProviderData(entries, { defaultProviderOrder: "sorted" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function waitForCondition(
|
||||||
|
predicate: () => boolean,
|
||||||
|
opts?: { attempts?: number; delayMs?: number },
|
||||||
|
): Promise<void> {
|
||||||
|
const attempts = opts?.attempts ?? 50;
|
||||||
|
const delayMs = opts?.delayMs ?? 0;
|
||||||
|
for (let index = 0; index < attempts; index += 1) {
|
||||||
|
if (predicate()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
||||||
|
}
|
||||||
|
throw new Error("condition not met");
|
||||||
|
}
|
||||||
|
|
||||||
function createModelPickerContext(): ModelPickerContext {
|
function createModelPickerContext(): ModelPickerContext {
|
||||||
const cfg = {
|
const cfg = {
|
||||||
channels: {
|
channels: {
|
||||||
@@ -317,7 +332,7 @@ describe("Discord model picker interactions", () => {
|
|||||||
await button.run(submitInteraction as unknown as PickerButtonInteraction, submitData);
|
await button.run(submitInteraction as unknown as PickerButtonInteraction, submitData);
|
||||||
|
|
||||||
expect(withTimeoutSpy).toHaveBeenCalledTimes(1);
|
expect(withTimeoutSpy).toHaveBeenCalledTimes(1);
|
||||||
expect(dispatchSpy).toHaveBeenCalledTimes(1);
|
await waitForCondition(() => dispatchSpy.mock.calls.length === 1);
|
||||||
expect(submitInteraction.followUp).toHaveBeenCalledTimes(1);
|
expect(submitInteraction.followUp).toHaveBeenCalledTimes(1);
|
||||||
const followUpPayload = submitInteraction.followUp.mock.calls[0]?.[0] as {
|
const followUpPayload = submitInteraction.followUp.mock.calls[0]?.[0] as {
|
||||||
components?: Array<{ components?: Array<{ content?: string }> }>;
|
components?: Array<{ components?: Array<{ content?: string }> }>;
|
||||||
|
|||||||
Reference in New Issue
Block a user