A quick fix for incorrectly working dropdowns. (#8933)

Partial fix for #8932 

https://github.com/enso-org/enso/assets/6566674/75a878fb-891b-44fc-bdfd-c3cbb90c9f35

This is not a correct fix, as comparing strings is not what we really want, but it should fix most of use cases.
This commit is contained in:
Ilya Bogdanov 2024-02-02 18:55:22 +04:00 committed by GitHub
parent 655ae46b8f
commit 45221d9167
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 10 deletions

View File

@ -14,12 +14,12 @@ class DropDownLocator {
async expectVisibleWithOptions(page: Page, options: string[]): Promise<void> {
await expect(this.dropDown).toBeVisible()
await expect(this.items).toHaveCount(options.length)
for (const option of options) {
await expect(
this.items.filter({ has: page.getByText(option, { exact: true }) }),
).toBeVisible()
}
await expect(this.items).toHaveCount(options.length)
}
async clickOption(page: Page, option: string): Promise<void> {

View File

@ -79,21 +79,22 @@ const dynamicTags = computed<Tag[]>(() => {
const tags = computed(() => (dynamicTags.value.length > 0 ? dynamicTags.value : staticTags.value))
const tagLabels = computed(() => tags.value.map((tag) => tag.label ?? tag.expression))
const removeSurroundingParens = (expr?: string) => expr?.trim().replaceAll(/(^[(])|([)]$)/g, '')
const selectedIndex = ref<number>()
const selectedTag = computed(() => {
if (selectedIndex.value != null) {
return tags.value[selectedIndex.value]
} else {
const currentExpression = WidgetInput.valueRepr(props.input)?.trim()
const currentExpression = removeSurroundingParens(WidgetInput.valueRepr(props.input))
if (!currentExpression) return undefined
return tags.value.find((tag) => {
const tagExpression = tag.expression.trim()
return (
tagExpression === currentExpression ||
tagExpression === `(${currentExpression})` ||
`(${tagExpression})` === currentExpression
)
})
// We need to find the tag that matches the (beginning of) current expression.
// To prevent partial prefix matches, we arrange tags in reverse lexicographical order.
const sortedTags = tags.value
.map((tag, index) => [removeSurroundingParens(tag.expression), index] as [string, number])
.sort(([a], [b]) => (a < b ? 1 : a > b ? -1 : 0))
const [_, index] = sortedTags.find(([expr]) => currentExpression.startsWith(expr)) ?? []
return index != null ? tags.value[index] : undefined
}
})