Skip to content

Commit 06b3bfc

Browse files
committed
[-] Select: CI tests fixed (clippy, doc, PW).
1 parent 7e54aa3 commit 06b3bfc

File tree

7 files changed

+78
-76
lines changed

7 files changed

+78
-76
lines changed

playwright/select.spec.ts

Lines changed: 61 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,62 @@
1-
import { test, expect } from '@playwright/test';
2-
3-
test('test', async ({ page }) => {
4-
await page.goto('http://127.0.0.1:8080/component/?name=select&', { timeout: 20 * 60 * 1000 }); // Increase timeout to 20 minutes
5-
// Find Select a fruit...
6-
let selectTrigger = page.locator(".select-trigger");
7-
await selectTrigger.click();
8-
// Assert the select menu is open
9-
const selectMenu = page.locator('.select-list');
10-
await expect(selectMenu).toHaveAttribute('data-state', 'open');
11-
12-
// Assert the menu is focused
13-
await expect(selectMenu).toBeFocused();
14-
await page.keyboard.press('ArrowDown');
15-
const firstOption = selectMenu.getByRole('option', { name: 'apple' });
16-
await expect(firstOption).toBeFocused();
17-
18-
// Assert moving down with arrow keys moves focus to the next option
19-
await page.keyboard.press('ArrowDown');
20-
const secondOption = selectMenu.getByRole('option', { name: 'banana' });
21-
await expect(secondOption).toBeFocused();
22-
23-
// Assert moving up with arrow keys moves focus back to the previous option
24-
await page.keyboard.press('ArrowUp');
25-
await expect(firstOption).toBeFocused();
26-
27-
// Assert pressing Enter selects the focused option
28-
await page.keyboard.press('Enter');
29-
// Assert the select menu is closed after selection
30-
await expect(selectMenu).toHaveCount(0);
31-
32-
// Assert the selected value is displayed in the button
33-
await expect(selectTrigger).toHaveText('apple');
34-
35-
// Reopen the select menu
36-
await selectTrigger.click();
37-
38-
// Assert typeahead functionality works
39-
await page.keyboard.type('Ban');
40-
// Assert the second option is focused after typing 'Ban'
41-
await expect(secondOption).toBeFocused();
42-
43-
// Assert pressing Escape closes the select menu
44-
await page.keyboard.press('Escape');
45-
// Assert the select menu is closed
46-
await expect(selectMenu).toHaveCount(0);
47-
48-
// Reopen the select menu
49-
await selectTrigger.click();
50-
// Assert the select menu is open again
51-
await expect(selectMenu).toHaveAttribute('data-state', 'open');
52-
53-
// Click the second option to select it
54-
let bananaOption = selectMenu.getByRole('option', { name: 'banana' });
55-
await bananaOption.click();
56-
// Assert the select menu is closed after clicking an option
57-
await expect(selectMenu).toHaveCount(0);
58-
// Assert the selected value is now 'banana'
59-
await expect(selectTrigger).toHaveText('banana');
1+
import { test, expect } from "@playwright/test";
2+
3+
test("test", async ({ page }) => {
4+
await page.goto("http://127.0.0.1:8080/component/?name=select&", {
5+
timeout: 20 * 60 * 1000,
6+
}); // Increase timeout to 20 minutes
7+
// Find Select a fruit...
8+
let selectTrigger = page.locator(".select-trigger");
9+
await selectTrigger.click();
10+
// Assert the select menu is open
11+
const selectMenu = page.locator(".select-list");
12+
await expect(selectMenu).toHaveAttribute("data-state", "open");
13+
14+
// Assert the menu is focused
15+
await expect(selectMenu).toBeFocused();
16+
await page.keyboard.press("ArrowDown");
17+
const firstOption = selectMenu.getByRole("option", { name: "apple" });
18+
await expect(firstOption).toBeFocused();
19+
20+
// Assert moving down with arrow keys moves focus to the next option
21+
await page.keyboard.press("ArrowDown");
22+
const secondOption = selectMenu.getByRole("option", { name: "banana" });
23+
await expect(secondOption).toBeFocused();
24+
25+
// Assert moving up with arrow keys moves focus back to the previous option
26+
await page.keyboard.press("ArrowUp");
27+
await expect(firstOption).toBeFocused();
28+
29+
// Assert pressing Enter selects the focused option
30+
await page.keyboard.press("Enter");
31+
// Assert the select menu is closed after selection
32+
await expect(selectMenu).toHaveCount(0);
33+
34+
// Assert the selected value is displayed in the button
35+
await expect(selectTrigger).toHaveText("Apple");
36+
37+
// Reopen the select menu
38+
await selectTrigger.click();
39+
40+
// Assert typeahead functionality works
41+
await page.keyboard.type("Ban");
42+
// Assert the second option is focused after typing 'Ban'
43+
await expect(secondOption).toBeFocused();
44+
45+
// Assert pressing Escape closes the select menu
46+
await page.keyboard.press("Escape");
47+
// Assert the select menu is closed
48+
await expect(selectMenu).toHaveCount(0);
49+
50+
// Reopen the select menu
51+
await selectTrigger.click();
52+
// Assert the select menu is open again
53+
await expect(selectMenu).toHaveAttribute("data-state", "open");
54+
55+
// Click the second option to select it
56+
let bananaOption = selectMenu.getByRole("option", { name: "banana" });
57+
await bananaOption.click();
58+
// Assert the select menu is closed after clicking an option
59+
await expect(selectMenu).toHaveCount(0);
60+
// Assert the selected value is now 'banana'
61+
await expect(selectTrigger).toHaveText("Banana");
6062
});

primitives/src/select/components/group.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ pub struct SelectGroupProps {
2626

2727
/// # SelectGroup
2828
///
29-
/// The `SelectGroup` component is used to group related options within a [`SelectList`]. It provides a way to organize options into logical sections.
29+
/// The `SelectGroup` component is used to group related options within a [`SelectList`](super::list::SelectList). It provides a way to organize options into logical sections.
3030
///
31-
/// This must be used inside a [`SelectList`] component.
31+
/// This must be used inside a [`SelectList`](super::list::SelectList) component.
3232
#[component]
3333
pub fn SelectGroup<T: Clone + PartialEq + 'static>(props: SelectGroupProps) -> Element {
3434
let ctx = use_context::<SelectContext<T>>();
@@ -68,9 +68,9 @@ pub struct SelectGroupLabelProps {
6868

6969
/// # SelectGroupLabel
7070
///
71-
/// The `SelectGroupLabel` component is used to render a label for a group of options within a [`SelectList`].
71+
/// The `SelectGroupLabel` component is used to render a label for a group of options within a [`SelectList`](super::list::SelectList).
7272
///
73-
/// This must be used inside a [`SelectGroup`] component.
73+
/// This must be used inside a [`SelectGroup`](SelectGroup) component.
7474
#[component]
7575
pub fn SelectGroupLabel(props: SelectGroupLabelProps) -> Element {
7676
let mut ctx: SelectGroupContext = use_context();

primitives/src/select/components/list.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ pub struct SelectListProps {
2222

2323
/// # SelectList
2424
///
25-
/// The dropdown list container for the [`Select`] component that contains the
26-
/// [`SelectOption`]s. The list will only be rendered when the select is open.
25+
/// The dropdown list container for the [`Select`](super::select::Select) component that contains the
26+
/// [`SelectOption`](super::option::SelectOption)s. The list will only be rendered when the select is open.
2727
///
28-
/// This must be used inside a [`Select`] component.
28+
/// This must be used inside a [`Select`](super::select::Select) component.
2929
#[component]
3030
pub fn SelectList<T: Clone + PartialEq + 'static>(props: SelectListProps) -> Element {
3131
let mut ctx = use_context::<SelectContext<T>>();

primitives/src/select/components/option.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub struct SelectOptionProps<T: Clone + PartialEq + 'static> {
4444

4545
/// # SelectOption
4646
///
47-
/// An individual selectable option within a [`SelectList`] component. Each option represents
47+
/// An individual selectable option within a [`SelectList`](super::list::SelectList) component. Each option represents
4848
/// a value that can be selected.
4949
///
5050
/// ## Value vs Display
@@ -54,7 +54,7 @@ pub struct SelectOptionProps<T: Clone + PartialEq + 'static> {
5454
///
5555
/// If `display` is not provided, the `value` will be formatted and used as the display text.
5656
///
57-
/// This must be used inside a [`SelectList`] component.
57+
/// This must be used inside a [`SelectList`](super::list::SelectList) component.
5858
#[component]
5959
pub fn SelectOption<T: PartialEq + Clone + 'static>(props: SelectOptionProps<T>) -> Element {
6060
// Generate a unique ID for this option for accessibility
@@ -136,10 +136,10 @@ pub struct SelectItemIndicatorProps {
136136

137137
/// # SelectItemIndicator
138138
///
139-
/// The `SelectItemIndicator` component is used to render an indicator for a selected item within a [`SelectList`]. The
139+
/// The `SelectItemIndicator` component is used to render an indicator for a selected item within a [`SelectList`](super::list::SelectList). The
140140
/// children will only be rendered if the option is selected.
141141
///
142-
/// This must be used inside a [`SelectOption`] component.
142+
/// This must be used inside a [`SelectOption`](SelectOption) component.
143143
#[component]
144144
pub fn SelectItemIndicator(props: SelectItemIndicatorProps) -> Element {
145145
let ctx: SelectOptionContext = use_context();

primitives/src/select/components/trigger.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ pub struct SelectTriggerProps {
1717

1818
/// # SelectTrigger
1919
///
20-
/// The trigger button for the [`Select`] component which controls if the [`SelectList`] is rendered.
20+
/// The trigger button for the [`Select`](super::select::Select) component which controls if the [`SelectList`](super::list::SelectList) is rendered.
2121
///
22-
/// This must be used inside a [`Select`] component.
22+
/// This must be used inside a [`Select`](super::select::Select) component.
2323
#[component]
2424
pub fn SelectTrigger<T: Clone + PartialEq + 'static>(props: SelectTriggerProps) -> Element {
2525
let mut ctx = use_context::<SelectContext<T>>();

primitives/src/select/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
119119
// Internal modules
120120
mod context;
121-
mod text_search;
121+
pub(crate) mod text_search;
122122

123123
// Public components module
124124
pub mod components;

primitives/src/select/text_search.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ impl AdaptiveKeyboard {
178178
let key_b = self.physical_mappings.iter().find(|(_, &ch)| ch == b)?.0;
179179

180180
let distance = physical_key_distance(key_a, key_b)?;
181-
Some((distance / 10.0).min(1.0).max(0.1))
181+
Some((distance / 10.0).clamp(0.1, 1.0))
182182
}
183183

184184
/// Calculate similarity based on Unicode codepoint proximity
@@ -187,7 +187,7 @@ impl AdaptiveKeyboard {
187187

188188
// Characters close in Unicode are often similar
189189
// Scale: adjacent codepoints get ~0.1 cost, distant ones approach 1.0
190-
(diff / 100.0).min(1.0).max(0.1)
190+
(diff / 100.0).clamp(0.1, 1.0)
191191
}
192192

193193
/// Check phonetic similarity using small lookup groups
@@ -387,7 +387,7 @@ impl KeyboardLayout {
387387
let distance = (dx * dx + dy * dy).sqrt();
388388

389389
// Scale the distance to be between 0.1 and 1.0
390-
(distance / 10.0).min(1.0).max(0.1)
390+
(distance / 10.0).clamp(0.1, 1.0)
391391
}
392392

393393
/// Get the position of a character on the keyboard layout

0 commit comments

Comments
 (0)