Skip to content

Commit 00a593d

Browse files
authored
appium: reset group (#368)
1 parent e8bbc2e commit 00a593d

5 files changed

Lines changed: 82 additions & 1 deletion

File tree

appium/conftest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import os
33
import platform
4+
import shutil
45
import subprocess
56
import time
67
import urllib.request
@@ -33,6 +34,8 @@ def launch_app(driver: WebDriver, session_config_dir: str, test_name: str) -> st
3334
"""Launch the test app."""
3435
config_home = os.path.join(session_config_dir, test_name)
3536
os.makedirs(config_home, exist_ok=True)
37+
profile_src = os.path.join(os.path.dirname(os.path.abspath(__file__)), "profile")
38+
shutil.copy2(profile_src, os.path.join(config_home, "profile"))
3639
app_path = os.path.join(
3740
project_root, "build", platform.machine(), "appium/FcitxTestApp.app"
3841
)

appium/profile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[Groups/0]
2+
# Group Name
3+
Name=Default
4+
# Layout
5+
Default Layout=us
6+
# Default Input Method
7+
DefaultIM=pinyin
8+
9+
[Groups/0/Items/0]
10+
# Name
11+
Name=pinyin
12+
# Layout
13+
Layout=
14+
15+
[GroupOrder]
16+
0=Default
17+

appium/test_group.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from appium.webdriver.webdriver import WebDriver
2+
from util.boolean import get_switch_state
3+
from util.config import read_config
4+
from util.message import (
5+
CHANGE_NOT_SAVED,
6+
CHANGE_WRONGLY_SAVED,
7+
UI_NOT_UPDATED,
8+
UI_WRONGLY_UPDATED,
9+
)
10+
from util.window import find_element_by_id, open_input_method_config, reset_option
11+
12+
SWITCH_IDS = ["VAsQuickphrase", "VE_UE", "NG_GN"]
13+
14+
15+
def test_reset_group(driver: WebDriver, app: str):
16+
open_input_method_config(driver, "pinyin")
17+
18+
def read_config_values() -> list[str]:
19+
cfg = read_config(app, "conf/pinyin.conf")
20+
return [
21+
cfg["Global"][SWITCH_IDS[0]],
22+
cfg["Fuzzy"][SWITCH_IDS[1]],
23+
cfg["Fuzzy"][SWITCH_IDS[2]],
24+
]
25+
26+
page_size = find_element_by_id(driver, "PageSize")
27+
scroll = find_element_by_id(driver, "detailScrollView")
28+
delta_y = page_size.rect["y"] - find_element_by_id(driver, SWITCH_IDS[0]).rect["y"]
29+
driver.execute_script(
30+
"macos: scroll",
31+
{
32+
"elementId": scroll.id,
33+
"deltaX": 0,
34+
"deltaY": delta_y,
35+
},
36+
)
37+
38+
for switch_id in SWITCH_IDS:
39+
find_element_by_id(driver, switch_id).click()
40+
toggled = read_config_values()
41+
toggled_ui = [get_switch_state(find_element_by_id(driver, id)) for id in SWITCH_IDS]
42+
43+
reset_option(driver, "Fuzzy")
44+
for i, switch_id in enumerate(SWITCH_IDS):
45+
ui_state = get_switch_state(find_element_by_id(driver, switch_id))
46+
if i == 0:
47+
assert ui_state == toggled_ui[i], UI_WRONGLY_UPDATED
48+
else:
49+
assert ui_state != toggled_ui[i], UI_NOT_UPDATED
50+
51+
after_reset = read_config_values()
52+
assert after_reset[0] == toggled[0], CHANGE_WRONGLY_SAVED
53+
assert after_reset[1] != toggled[1], CHANGE_NOT_SAVED
54+
assert after_reset[2] != toggled[2], CHANGE_NOT_SAVED

appium/util/window.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ def open_advanced_config(driver: WebDriver):
3232
find_element_by_id(driver, "Advanced").click()
3333

3434

35+
def open_input_method_config(driver: WebDriver, im: str):
36+
"""Open the Input Methods window and select an input method."""
37+
find_element_by_id(driver, "Input Method").click()
38+
find_element_by_id(driver, im).click()
39+
40+
3541
def reset_option(driver: WebDriver, option_id: str):
3642
label = find_element_by_id(driver, f"{option_id}_label")
3743
driver.execute_script(

src/config/InputMethod.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ struct InputMethodConfigView: View {
158158

159159
ForEach($group.inputMethods) { $inputMethod in
160160
HStack {
161-
Text(inputMethod.displayName)
161+
Text(inputMethod.displayName).accessibilityIdentifier(inputMethod.name)
162162
Spacer()
163163
if mouseHoverIMID == inputMethod.id {
164164
if inputMethod.isKeyboard {
@@ -250,6 +250,7 @@ struct InputMethodConfigView: View {
250250
)
251251
.padding()
252252
}.padding([.top], 1) // Cannot be 0 otherwise content overlaps with title bar.
253+
.accessibilityIdentifier("detailScrollView")
253254
FooterView(
254255
manager: manager,
255256
onClose: {

0 commit comments

Comments
 (0)