fix(codegen): trim alt selectors to 80 chars
Fixes https://github.com/microsoft/playwright/issues/31254
This commit is contained in:
parent
a002572dd2
commit
d216f167ff
|
|
@ -528,7 +528,7 @@ function suitableTextAlternatives(text: string) {
|
||||||
const match = text.match(/^([\d.,]+)[^.,\w]/);
|
const match = text.match(/^([\d.,]+)[^.,\w]/);
|
||||||
const leadingNumberLength = match ? match[1].length : 0;
|
const leadingNumberLength = match ? match[1].length : 0;
|
||||||
if (leadingNumberLength) {
|
if (leadingNumberLength) {
|
||||||
const alt = text.substring(leadingNumberLength).trimStart();
|
const alt = trimWordBoundary(text.substring(leadingNumberLength).trimStart(), 80);
|
||||||
result.push({ text: alt, scoreBouns: alt.length <= 30 ? 2 : 1 });
|
result.push({ text: alt, scoreBouns: alt.length <= 30 ? 2 : 1 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -537,7 +537,7 @@ function suitableTextAlternatives(text: string) {
|
||||||
const match = text.match(/[^.,\w]([\d.,]+)$/);
|
const match = text.match(/[^.,\w]([\d.,]+)$/);
|
||||||
const trailingNumberLength = match ? match[1].length : 0;
|
const trailingNumberLength = match ? match[1].length : 0;
|
||||||
if (trailingNumberLength) {
|
if (trailingNumberLength) {
|
||||||
const alt = text.substring(0, text.length - trailingNumberLength).trimEnd();
|
const alt = trimWordBoundary(text.substring(0, text.length - trailingNumberLength).trimEnd(), 80);
|
||||||
result.push({ text: alt, scoreBouns: alt.length <= 30 ? 2 : 1 });
|
result.push({ text: alt, scoreBouns: alt.length <= 30 ? 2 : 1 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -551,7 +551,7 @@ function suitableTextAlternatives(text: string) {
|
||||||
|
|
||||||
result = result.filter(r => r.text);
|
result = result.filter(r => r.text);
|
||||||
if (!result.length)
|
if (!result.length)
|
||||||
result.push({ text: text.substring(0, 80), scoreBouns: 0 });
|
result.push({ text: trimWordBoundary(text, 80), scoreBouns: 0 });
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue