Repository navigation
Allow customisation of hs.chooser font sizes. Closes #226 #246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -233,6 +233,27 @@ struct HSChooserTests { | |
| harness.eval("var c = hs.chooser.create()") | ||
| harness.expectTrue("c.selectionColor == null") | ||
| } | ||
|
|
||
| @Test("textSize defaults to 14") | ||
| func testTextSizeDefault() { | ||
| let harness = makeHarness() | ||
| harness.eval("var c = hs.chooser.create()") | ||
| harness.expectTrue("Math.abs(c.textSize - 14) < 0.01") | ||
| } | ||
|
|
||
| @Test("subTextSize defaults to 12") | ||
| func testSubTextSizeDefault() { | ||
| let harness = makeHarness() | ||
| harness.eval("var c = hs.chooser.create()") | ||
| harness.expectTrue("Math.abs(c.subTextSize - 12) < 0.01") | ||
| } | ||
|
|
||
| @Test("querySize defaults to 20") | ||
| func testQuerySizeDefault() { | ||
| let harness = makeHarness() | ||
| harness.eval("var c = hs.chooser.create()") | ||
| harness.expectTrue("Math.abs(c.querySize - 20) < 0.01") | ||
| } | ||
| } | ||
|
|
||
| // MARK: - Behaviour | ||
|
|
@@ -441,6 +462,98 @@ struct HSChooserTests { | |
| #expect(!harness.hasException) | ||
| } | ||
|
|
||
| @Test("textSize setter updates value") | ||
| func testTextSizeSetter() { | ||
| let harness = makeHarness() | ||
| harness.eval(""" | ||
| var c = hs.chooser.create() | ||
| c.textSize = 18 | ||
| """) | ||
| harness.expectTrue("Math.abs(c.textSize - 18) < 0.01") | ||
| #expect(!harness.hasException) | ||
| } | ||
|
|
||
| @Test("textSize setter rejects non-finite and non-positive values") | ||
| func testTextSizeSetterRejectsInvalid() { | ||
| let harness = makeHarness() | ||
| harness.eval(""" | ||
| var c = hs.chooser.create() | ||
| c.textSize = 18 | ||
| c.textSize = NaN | ||
| c.textSize = Infinity | ||
| c.textSize = 0 | ||
| c.textSize = -5 | ||
| """) | ||
| harness.expectTrue("Math.abs(c.textSize - 18) < 0.01") | ||
| #expect(!harness.hasException) | ||
|
Comment on lines
+487
to
+488
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Prompt To Fix With AIThis is a comment left during a code review.
Path: Hammerspoon 2Tests/IntegrationTests/HSChooserIntegrationTests.swift
Line: 487-488
Comment:
**Assignment exceptions go undetected**
`expectTrue` starts a new JavaScript evaluation, which clears the exception recorded by the assignment block before `hasException` checks it. If an invalid assignment throws but leaves the size unchanged, this test still passes, so it does not verify that invalid values are ignored without an exception. Check `hasException` immediately after the assignment block. The subtext and query tests have the same pattern.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly. |
||
| } | ||
|
|
||
| @Test("subTextSize setter updates value") | ||
| func testSubTextSizeSetter() { | ||
| let harness = makeHarness() | ||
| harness.eval(""" | ||
| var c = hs.chooser.create() | ||
| c.subTextSize = 16 | ||
| """) | ||
| harness.expectTrue("Math.abs(c.subTextSize - 16) < 0.01") | ||
| #expect(!harness.hasException) | ||
| } | ||
|
|
||
| @Test("subTextSize setter rejects non-finite and non-positive values") | ||
| func testSubTextSizeSetterRejectsInvalid() { | ||
| let harness = makeHarness() | ||
| harness.eval(""" | ||
| var c = hs.chooser.create() | ||
| c.subTextSize = 16 | ||
| c.subTextSize = NaN | ||
| c.subTextSize = Infinity | ||
| c.subTextSize = 0 | ||
| c.subTextSize = -5 | ||
| """) | ||
| harness.expectTrue("Math.abs(c.subTextSize - 16) < 0.01") | ||
| #expect(!harness.hasException) | ||
| } | ||
|
|
||
| @Test("querySize setter updates value") | ||
| func testQuerySizeSetter() { | ||
| let harness = makeHarness() | ||
| harness.eval(""" | ||
| var c = hs.chooser.create() | ||
| c.querySize = 26 | ||
| """) | ||
| harness.expectTrue("Math.abs(c.querySize - 26) < 0.01") | ||
| #expect(!harness.hasException) | ||
| } | ||
|
|
||
| @Test("querySize setter rejects non-finite and non-positive values") | ||
| func testQuerySizeSetterRejectsInvalid() { | ||
| let harness = makeHarness() | ||
| harness.eval(""" | ||
| var c = hs.chooser.create() | ||
| c.querySize = 26 | ||
| c.querySize = NaN | ||
| c.querySize = Infinity | ||
| c.querySize = 0 | ||
| c.querySize = -5 | ||
| """) | ||
| harness.expectTrue("Math.abs(c.querySize - 26) < 0.01") | ||
| #expect(!harness.hasException) | ||
| } | ||
|
|
||
| @Test("changing font sizes while the chooser is visible does not throw") | ||
| func testFontSizeChangeWhileVisible() { | ||
| let harness = makeHarness() | ||
| harness.eval(""" | ||
| var c = hs.chooser.create() | ||
| c.setChoices([{text: "Option A"}, {text: "Option B"}]) | ||
| c.show() | ||
| c.textSize = 22 | ||
| c.subTextSize = 16 | ||
| c.querySize = 28 | ||
| """) | ||
| #expect(!harness.hasException) | ||
|
cmsj marked this conversation as resolved.
|
||
| } | ||
|
|
||
| @Test("visibleRows setter updates value") | ||
| func testVisibleRowsSetter() { | ||
| let harness = makeHarness() | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.