mirror of
https://github.com/enso-org/enso.git
synced 2024-11-23 16:18:23 +03:00
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:
parent
655ae46b8f
commit
45221d9167
@ -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> {
|
||||
|
@ -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
|
||||
}
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user