Commit e61ef1ad41
Verified · cmc
Layout: unified · split
gitbay/Repos/RepoActionsViewModel.swift +2
| @@ -85,6 +85,7 @@ final class RepoActionsViewModel { | |||
| 85 | } | 85 | } |
| 86 | working = true | 86 | working = true |
| 87 | actionError = nil | 87 | actionError = nil |
| 88 | notice = nil | ||
| 88 | defer { working = false } | 89 | defer { working = false } |
| 89 | do { | 90 | do { |
| 90 | return try await client.run(argv, as: ForkResult.self) | 91 | return try await client.run(argv, as: ForkResult.self) |
| @@ -100,6 +101,7 @@ final class RepoActionsViewModel { | |||
| 100 | private func perform(_ argv: [String]) async { | 101 | private func perform(_ argv: [String]) async { |
| 101 | working = true | 102 | working = true |
| 102 | actionError = nil | 103 | actionError = nil |
| 104 | notice = nil | ||
| 103 | defer { working = false } | 105 | defer { working = false } |
| 104 | do { | 106 | do { |
| 105 | try await client.run(argv) | 107 | try await client.run(argv) |
gitbayTests/RepoActionTests.swift +21
| @@ -161,4 +161,25 @@ struct RepoActionsTests { | |||
| 161 | #expect(model.actionError?.isEmpty == false) | 161 | #expect(model.actionError?.isEmpty == false) |
| 162 | #expect(model.working == false) | 162 | #expect(model.working == false) |
| 163 | } | 163 | } |
| 164 | |||
| 165 | /// A stale `notice` from an earlier success must not survive a later | ||
| 166 | /// failure — the screen must never show a success banner and a | ||
| 167 | /// failure banner at once. | ||
| 168 | @Test func aFailedActionClearsAStaleNotice() async throws { | ||
| 169 | let (client, stub) = try makeClient() | ||
| 170 | let model = RepoActionsViewModel(client: client, repoPath: "krz/gitbay") | ||
| 171 | |||
| 172 | stub.enqueue(.init(status: 200, json: ok)) | ||
| 173 | await model.watch() | ||
| 174 | #expect(model.notice != nil) | ||
| 175 | |||
| 176 | stub.enqueue(.init(status: 200, json: """ | ||
| 177 | {"protocol_version":1,"error":"a repository named gitbay already exists",\ | ||
| 178 | "exit_code":1} | ||
| 179 | """)) | ||
| 180 | _ = await model.fork(named: nil) | ||
| 181 | |||
| 182 | #expect(model.notice == nil) | ||
| 183 | #expect(model.actionError?.isEmpty == false) | ||
| 184 | } | ||
| 164 | } | 185 | } |