Skip to content

Commit fe769d1

Browse files
committed
Flush queued actions whenever the panel closes
1 parent f77bcfd commit fe769d1

3 files changed

Lines changed: 53 additions & 2 deletions

File tree

Octodot/Panel/NotificationPanel.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ final class NotificationPanel: NSPanel {
5959
}
6060

6161
override func close() {
62+
appState.flushPendingActions()
6263
super.close()
6364
appState.isPanelVisible = false
6465
}

Octodot/Views/PanelContentView.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,14 +398,12 @@ struct PanelContentView: View {
398398
isSearchFieldFocused = false
399399
focusListSoon()
400400
case .closePanel:
401-
appState.flushPendingActions()
402401
closePanel()
403402
}
404403
}
405404

406405
private func openSelectedNotificationAndCloseIfNeeded() {
407406
if appState.openInBrowser() {
408-
appState.flushPendingActions()
409407
closePanel()
410408
}
411409
}

OctodotTests/AppShellTests.swift

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,58 @@ struct AppShellTests {
7777
#expect(message.contains("Another app may already be using it."))
7878
}
7979

80+
@Test func closingNotificationPanelFlushesQueuedActions() async {
81+
let defaults = AppStateTests.makeIsolatedUserDefaults()
82+
let session = StubNetworkSession(results: [
83+
.success((
84+
Data(),
85+
AppStateTests.httpResponse(
86+
url: "https://api.github.com/notifications/threads/0",
87+
statusCode: 204
88+
)
89+
))
90+
])
91+
let client = GitHubAPIClient(
92+
token: "ghp_secret",
93+
session: session,
94+
useGraphQLForSubjectMetadata: false
95+
)
96+
let state = AppStateTests.makeState(
97+
1,
98+
apiClient: client,
99+
actionDispatchDelayNanoseconds: 5_000_000_000,
100+
sleepHandler: AppStateTests.realSleep,
101+
userDefaults: defaults
102+
)
103+
let panel = NotificationPanel(
104+
appState: state,
105+
preferences: AppPreferences(userDefaults: defaults),
106+
updateChecker: UpdateChecker(
107+
session: StubNetworkSession(results: []),
108+
userDefaults: defaults
109+
),
110+
showSettings: {}
111+
)
112+
state.isPanelVisible = true
113+
114+
state.done()
115+
let requestsBeforeClose = await session.recordedRequests()
116+
#expect(requestsBeforeClose.contains { $0.httpMethod == "DELETE" } == false)
117+
118+
panel.close()
119+
120+
await AppStateTests.waitUntil {
121+
await session.recordedRequests().filter { $0.httpMethod == "DELETE" }.count == 1
122+
}
123+
let requestsAfterClose = await session.recordedRequests()
124+
#expect(requestsAfterClose.filter { $0.httpMethod == "DELETE" }.count == 1)
125+
#expect(state.isPanelVisible == false)
126+
127+
panel.close()
128+
let requestsAfterRepeatedClose = await session.recordedRequests()
129+
#expect(requestsAfterRepeatedClose.filter { $0.httpMethod == "DELETE" }.count == 1)
130+
}
131+
80132
@Test func outsideClickClosesPanelButStatusItemClickDoesNot() {
81133
let panelFrame = CGRect(x: 100, y: 100, width: 380, height: 500)
82134
let statusItemFrame = CGRect(x: 220, y: 620, width: 20, height: 24)

0 commit comments

Comments
 (0)