Group parameter display strings by class/method
This commit is contained in:
parent
1a31594b75
commit
60bb08838b
|
|
@ -166,59 +166,137 @@ interface ActionParameterDisplayString {
|
||||||
value: string;
|
value: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const clockDisplayString = (
|
||||||
|
action: ActionTraceEvent,
|
||||||
|
): ActionParameterDisplayString | undefined => {
|
||||||
|
switch (action.method) {
|
||||||
|
case 'clockPauseAt':
|
||||||
|
case 'clockSetFixedTime':
|
||||||
|
case 'clockSetSystemTime': {
|
||||||
|
if (
|
||||||
|
action.params.timeString === undefined &&
|
||||||
|
action.params.timeNumber === undefined
|
||||||
|
)
|
||||||
|
return undefined;
|
||||||
|
return {
|
||||||
|
type: 'generic',
|
||||||
|
value: new Date(
|
||||||
|
action.params.timeString ?? action.params.timeNumber,
|
||||||
|
).toLocaleString(undefined, { timeZone: 'UTC' }),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
case 'clockFastForward':
|
||||||
|
case 'clockRunFor': {
|
||||||
|
if (
|
||||||
|
action.params.ticksNumber === undefined &&
|
||||||
|
action.params.ticksString === undefined
|
||||||
|
)
|
||||||
|
return undefined;
|
||||||
|
return {
|
||||||
|
type: 'generic',
|
||||||
|
value: action.params.ticksString ?? `${action.params.ticksNumber}ms`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
const keyboardDisplayString = (
|
||||||
|
action: ActionTraceEvent,
|
||||||
|
): ActionParameterDisplayString | undefined => {
|
||||||
|
switch (action.method) {
|
||||||
|
case 'press':
|
||||||
|
case 'keyboardPress':
|
||||||
|
case 'keyboardDown':
|
||||||
|
case 'keyboardUp': {
|
||||||
|
if (action.params.key === undefined)
|
||||||
|
return undefined;
|
||||||
|
return { type: 'generic', value: action.params.key };
|
||||||
|
}
|
||||||
|
case 'type':
|
||||||
|
case 'fill':
|
||||||
|
case 'keyboardType':
|
||||||
|
case 'keyboardInsertText': {
|
||||||
|
if (action.params.text === undefined)
|
||||||
|
return undefined;
|
||||||
|
return { type: 'generic', value: `"${action.params.text}"` };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const mouseDisplayString = (
|
||||||
|
action: ActionTraceEvent,
|
||||||
|
): ActionParameterDisplayString | undefined => {
|
||||||
|
switch (action.method) {
|
||||||
|
case 'click':
|
||||||
|
case 'dblclick':
|
||||||
|
case 'mouseClick':
|
||||||
|
case 'mouseMove': {
|
||||||
|
if (action.params.x === undefined || action.params.y === undefined)
|
||||||
|
return undefined;
|
||||||
|
return {
|
||||||
|
type: 'generic',
|
||||||
|
value: `(${action.params.x}, ${action.params.y})`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
case 'mouseWheel': {
|
||||||
|
if (
|
||||||
|
action.params.deltaX === undefined ||
|
||||||
|
action.params.deltaY === undefined
|
||||||
|
)
|
||||||
|
return undefined;
|
||||||
|
return {
|
||||||
|
type: 'generic',
|
||||||
|
value: `(${action.params.deltaX}, ${action.params.deltaY})`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const touchscreenDisplayString = (
|
||||||
|
action: ActionTraceEvent,
|
||||||
|
): ActionParameterDisplayString | undefined => {
|
||||||
|
switch (action.method) {
|
||||||
|
case 'tap': {
|
||||||
|
if (action.params.x === undefined || action.params.y === undefined)
|
||||||
|
return undefined;
|
||||||
|
return {
|
||||||
|
type: 'generic',
|
||||||
|
value: `(${action.params.x}, ${action.params.y})`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const actionParameterDisplayString = (
|
const actionParameterDisplayString = (
|
||||||
action: ActionTraceEvent,
|
action: ActionTraceEvent,
|
||||||
sdkLanguage: Language,
|
sdkLanguage: Language,
|
||||||
): ActionParameterDisplayString | undefined => {
|
): ActionParameterDisplayString | undefined => {
|
||||||
const params = action.params;
|
const params = action.params;
|
||||||
|
|
||||||
let value: string | undefined = undefined;
|
// Locators have many possible classes, so follow existing logic and use `selector` presence
|
||||||
|
if (params.selector !== undefined)
|
||||||
if (params.selector !== undefined) {
|
|
||||||
return { type: 'locator', value: asLocator(sdkLanguage, params.selector) };
|
return { type: 'locator', value: asLocator(sdkLanguage, params.selector) };
|
||||||
} else if (params.ticksNumber !== undefined) {
|
|
||||||
// clock.fastForward/runFor number
|
switch (action.class.toLowerCase()) {
|
||||||
value = `${params.ticksNumber}ms`;
|
case 'browsercontext':
|
||||||
} else if (params.ticksString !== undefined) {
|
return clockDisplayString(action);
|
||||||
// clock.fastForward/runFor string
|
case 'page':
|
||||||
value = params.ticksString;
|
case 'frame':
|
||||||
} else if (
|
case 'elementhandle':
|
||||||
params.timeString !== undefined ||
|
let string = keyboardDisplayString(action);
|
||||||
params.timeNumber !== undefined
|
|
||||||
) {
|
if (string !== undefined)
|
||||||
// clock.pauseAt/setFixedTime/setSystemTime
|
return string;
|
||||||
try {
|
|
||||||
value = new Date(params.timeString ?? params.timeNumber).toLocaleString(
|
string = mouseDisplayString(action);
|
||||||
undefined,
|
|
||||||
{
|
if (string !== undefined)
|
||||||
timeZone: 'UTC',
|
return string;
|
||||||
},
|
|
||||||
);
|
return touchscreenDisplayString(action);
|
||||||
} catch (e) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
} else if (params.key !== undefined) {
|
|
||||||
// keyboard.press/down/up
|
|
||||||
value = params.key;
|
|
||||||
} else if (params.text !== undefined) {
|
|
||||||
// keyboard.type/insertText
|
|
||||||
value = `"${params.text}"`;
|
|
||||||
} else if (params.x !== undefined && params.y !== undefined) {
|
|
||||||
// mouse.click/dblclick/move
|
|
||||||
value = `(${params.x}, ${params.y})`;
|
|
||||||
} else if (params.deltaX !== undefined && params.deltaY !== undefined) {
|
|
||||||
// mouse.wheel
|
|
||||||
value = `(${params.deltaX}, ${params.deltaY})`;
|
|
||||||
} else if (params.x && params.y) {
|
|
||||||
// touchscreen.tap
|
|
||||||
value = `(${params.x}, ${params.y})`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value === undefined)
|
return undefined;
|
||||||
return undefined;
|
|
||||||
|
|
||||||
return {
|
|
||||||
type: 'generic',
|
|
||||||
value,
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue