| 1 | package main |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | func TestAcceptDeliveryToTabClearsOnlyAwaitingDelivery(t *testing.T) { |
| 6 | app := &App{tabs: map[string]*WorkspaceTab{}} |
| 7 | tab := &WorkspaceTab{ID: "tab-a", ActivityStatus: topicStatusAwaitingDelivery} |
| 8 | app.tabs[tab.ID] = tab |
| 9 | app.tabOrder = []string{tab.ID} |
| 10 | app.activeTabID = tab.ID |
| 11 | |
| 12 | if err := app.AcceptDeliveryToTab(tab.ID); err != nil { |
| 13 | t.Fatalf("AcceptDeliveryToTab: %v", err) |
| 14 | } |
| 15 | if tab.ActivityStatus != "" { |
| 16 | t.Fatalf("ActivityStatus = %q, want cleared", tab.ActivityStatus) |
| 17 | } |
| 18 | // Idempotent: a second acceptance is a no-op, not an error. |
| 19 | if err := app.AcceptDeliveryToTab(tab.ID); err != nil { |
| 20 | t.Fatalf("second AcceptDeliveryToTab: %v", err) |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | func TestAcceptDeliveryToTabLeavesOtherStatesUntouched(t *testing.T) { |
| 25 | app := &App{tabs: map[string]*WorkspaceTab{}} |
| 26 | tab := &WorkspaceTab{ID: "tab-a", ActivityStatus: topicStatusPaused} |
| 27 | app.tabs[tab.ID] = tab |
| 28 | app.tabOrder = []string{tab.ID} |
| 29 | app.activeTabID = tab.ID |
| 30 | |
| 31 | if err := app.AcceptDeliveryToTab(tab.ID); err != nil { |
| 32 | t.Fatalf("AcceptDeliveryToTab: %v", err) |
| 33 | } |
| 34 | if tab.ActivityStatus != topicStatusPaused { |
| 35 | t.Fatalf("ActivityStatus = %q, want %q", tab.ActivityStatus, topicStatusPaused) |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | func TestAwaitingDeliveryReportsTheBoundState(t *testing.T) { |
| 40 | if awaitingDelivery(nil) { |
| 41 | t.Fatal("nil tab must not report awaiting delivery") |
| 42 | } |
| 43 | if awaitingDelivery(&WorkspaceTab{ActivityStatus: topicStatusPaused}) { |
| 44 | t.Fatal("paused tab must not report awaiting delivery") |
| 45 | } |
| 46 | if !awaitingDelivery(&WorkspaceTab{ActivityStatus: topicStatusAwaitingDelivery}) { |
| 47 | t.Fatal("awaiting-delivery tab must report the state") |
| 48 | } |
| 49 | } |
| 50 |