Skip to content

Commit 1a88db1

Browse files
committed
fix(#193): issue with combination unmovable and alwaysOnTop
1 parent 3dafa67 commit 1a88db1

File tree

2 files changed

+84
-10
lines changed

2 files changed

+84
-10
lines changed

Notification Agent Core/Extensions/EFCLController-Extension.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -194,28 +194,28 @@ extension EFCLController {
194194

195195
private func buildDict(from keys: [String], and values: [String]) throws -> [String: Any] {
196196
var checkedValues = values
197+
var checkedKeys = keys
197198
guard !keys.isEmpty && !values.isEmpty else {
198199
HelpBuilder.printNoArgumentsPage()
199200
throw NAError.efclController(type: .invalidArgumentsSyntax)
200201
}
201202
for arg in Self.standaloneBooleanArguments {
202-
guard let index = keys.firstIndex(where: { $0 == arg }) else { continue }
203-
if index > checkedValues.count {
204-
checkedValues.append("true")
205-
} else {
206-
checkedValues.insert("true", at: index)
207-
}
203+
guard let index = checkedKeys.firstIndex(where: { $0 == arg }) else { continue }
204+
let standAloneArgument = checkedKeys[index]
205+
checkedKeys.remove(at: index)
206+
checkedKeys.append(standAloneArgument)
207+
checkedValues.append("true")
208208
}
209-
guard keys.count == checkedValues.count else {
209+
guard checkedKeys.count == checkedValues.count else {
210210
throw NAError.efclController(type: .invalidArgumentsFormat)
211211
}
212212
var dict: [String: Any] = [:]
213-
for index in keys.indices {
214-
dict[keys[index]] = checkedValues[index]
213+
for index in checkedKeys.indices {
214+
dict[checkedKeys[index]] = checkedValues[index]
215215
}
216216
return dict
217217
}
218-
218+
219219
/// Try to create a NotificationObject from the passed dictionary.
220220
/// - Parameter dict: the passed dictionary.
221221
/// - Throws: NAError.

Notification Agent Popup UI Tests/NAPUITests.swift

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,5 +980,79 @@ class NAPUITests: XCTestCase {
980980
XCTAssert(false, "Failed to encode the usecase.")
981981
}
982982
}
983+
984+
/// Testing Pop-up with:
985+
/// Title: This is a title
986+
/// Subtitle: This is a subtitle
987+
/// Main Button: Primary
988+
/// Secondary Button: Secondary
989+
/// Unmovable: true
990+
func testD4Popup() throws {
991+
let useCase = """
992+
{"notification":{"topicID":"untracked","mainButton":{"label":"Primary","callToActionType":"none","callToActionPayload":""},"secondaryButton":{"label":"Secondary","callToActionType":"none","callToActionPayload":""},"iconPath":"","hideTitleBarButtons":false,"retainValues":false,"alwaysOnTop":false,"type":"popup","title":"This is a title","subtitle":"This is a subtitle","silent":false,"showSuppressionButton":false,"miniaturizable":false,"timeout":"30","barTitle":"Some","forceLightMode":false,"notificationID":"untracked","isMovable":false,"disableQuit":false, "accessoryViews":[]},"settings":{"isVerboseModeEnabled":false,"environment":"prod"}}
993+
""" // pragma: allowlist-secret
994+
if let useCaseData = useCase.data(using: .utf8) {
995+
let app = XCUIApplication()
996+
app.launchArguments = [useCaseData.base64EncodedString()]
997+
app.launch()
998+
XCTAssert(app.windows["main_window"].exists)
999+
XCTAssert(app.windows["main_window"].isHittable)
1000+
XCTAssert(app.buttons["main_button"].exists)
1001+
XCTAssert(app.buttons["main_button"].isEnabled)
1002+
XCTAssert(app.buttons["secondary_button"].exists)
1003+
XCTAssert(app.staticTexts["popup_title"].exists)
1004+
XCTAssertEqual(app.staticTexts["popup_title"].value as? String ?? "", "This is a title")
1005+
XCTAssert(app.staticTexts["popup_subtitle"].exists)
1006+
XCTAssertEqual(app.staticTexts["popup_subtitle"].value as? String ?? "", "This is a subtitle")
1007+
let initialPositionY = app.windows["main_window"].frame.minY
1008+
let initialPositionX = app.windows["main_window"].frame.minX
1009+
let coordinate = app.windows["main_window"].coordinate(withNormalizedOffset: CGVector(dx: 0.02, dy: 0.04))
1010+
coordinate.click(forDuration: 1, thenDragTo: app.buttons["main_button"].coordinate(withNormalizedOffset: .zero))
1011+
let finalPositionY = app.windows["main_window"].frame.minY
1012+
let finalPositionX = app.windows["main_window"].frame.minX
1013+
XCTAssert(initialPositionX == finalPositionX)
1014+
XCTAssert(initialPositionY == finalPositionY)
1015+
app.terminate()
1016+
} else {
1017+
XCTAssert(false, "Failed to encode the usecase.")
1018+
}
1019+
}
1020+
1021+
/// Testing Pop-up with:
1022+
/// Title: This is a title
1023+
/// Subtitle: This is a subtitle
1024+
/// Main Button: Primary
1025+
/// Secondary Button: Secondary
1026+
/// Unmovable: false
1027+
func testD5Popup() throws {
1028+
let useCase = """
1029+
{"notification":{"topicID":"untracked","mainButton":{"label":"Primary","callToActionType":"none","callToActionPayload":""},"secondaryButton":{"label":"Secondary","callToActionType":"none","callToActionPayload":""},"iconPath":"","hideTitleBarButtons":false,"retainValues":false,"alwaysOnTop":false,"type":"popup","title":"This is a title","subtitle":"This is a subtitle","silent":false,"showSuppressionButton":false,"miniaturizable":false,"timeout":"30","barTitle":"Some","forceLightMode":false,"notificationID":"untracked","isMovable":true,"disableQuit":false, "accessoryViews":[]},"settings":{"isVerboseModeEnabled":false,"environment":"prod"}}
1030+
""" // pragma: allowlist-secret
1031+
if let useCaseData = useCase.data(using: .utf8) {
1032+
let app = XCUIApplication()
1033+
app.launchArguments = [useCaseData.base64EncodedString()]
1034+
app.launch()
1035+
XCTAssert(app.windows["main_window"].exists)
1036+
XCTAssert(app.windows["main_window"].isHittable)
1037+
XCTAssert(app.buttons["main_button"].exists)
1038+
XCTAssert(app.buttons["main_button"].isEnabled)
1039+
XCTAssert(app.buttons["secondary_button"].exists)
1040+
XCTAssert(app.staticTexts["popup_title"].exists)
1041+
XCTAssertEqual(app.staticTexts["popup_title"].value as? String ?? "", "This is a title")
1042+
XCTAssert(app.staticTexts["popup_subtitle"].exists)
1043+
XCTAssertEqual(app.staticTexts["popup_subtitle"].value as? String ?? "", "This is a subtitle")
1044+
let initialPositionY = app.windows["main_window"].frame.minY
1045+
let initialPositionX = app.windows["main_window"].frame.minX
1046+
let coordinate = app.windows["main_window"].coordinate(withNormalizedOffset: CGVector(dx: 0.02, dy: 0.04))
1047+
coordinate.click(forDuration: 1, thenDragTo: app.buttons["main_button"].coordinate(withNormalizedOffset: .zero))
1048+
let finalPositionY = app.windows["main_window"].frame.minY
1049+
let finalPositionX = app.windows["main_window"].frame.minX
1050+
XCTAssertFalse(initialPositionX == finalPositionX)
1051+
XCTAssertFalse(initialPositionY == finalPositionY)
1052+
app.terminate()
1053+
} else {
1054+
XCTAssert(false, "Failed to encode the usecase.")
1055+
}
1056+
}
9831057
}
9841058
// swiftlint:enable type_body_length file_length

0 commit comments

Comments
 (0)