|
6 | 6 | "github.com/donislawdev/TestingFilesGenerator/internal/engine" |
7 | 7 | "github.com/donislawdev/TestingFilesGenerator/internal/format" |
8 | 8 | "github.com/donislawdev/TestingFilesGenerator/internal/gui/parts" |
| 9 | + "github.com/donislawdev/TestingFilesGenerator/internal/gui/text" |
9 | 10 | "github.com/donislawdev/TestingFilesGenerator/internal/gui/window" |
10 | 11 | "github.com/donislawdev/TestingFilesGenerator/internal/recipe" |
11 | 12 | ) |
@@ -67,6 +68,86 @@ func TestOneChangeOfABoxReadsTheFormOnce(t *testing.T) { |
67 | 68 | } |
68 | 69 | } |
69 | 70 |
|
| 71 | +// A menu, a switch or a press that lays the batch screen out again reads the |
| 72 | +// form once. |
| 73 | +// |
| 74 | +// The batch screen lays itself out again when a batch's format changes, when |
| 75 | +// the base is switched or chosen, and when a press adds, copies or takes away |
| 76 | +// a batch or what an archive holds. The layout said what the form comes to, |
| 77 | +// and until 2026-09-24 a menu or a switch was then followed by the live check, |
| 78 | +// which said it again: two readings, and with a base preset two expansions - |
| 79 | +// switching the base to upload-validation took 278-321 ms in the real window |
| 80 | +// (docs/GUI-MEMORY-2026-09-23.md section 4j). |
| 81 | +// |
| 82 | +// Exactly one, for the reason the guard above gives, and it matters here in |
| 83 | +// the other direction too: a press is followed by no check, so nought is a |
| 84 | +// press after which the line under the buttons still describes the old form. |
| 85 | +func TestAChangeThatLaysTheBatchScreenOutAgainReadsTheFormOnce(t *testing.T) { |
| 86 | + host := newFakeHost(t) |
| 87 | + rec := window.NewRecipe(host) |
| 88 | + body := rec.Object() |
| 89 | + once := func(what string, act func()) { |
| 90 | + t.Helper() |
| 91 | + host.settles = 0 |
| 92 | + act() |
| 93 | + switch { |
| 94 | + case host.settles == 0: |
| 95 | + t.Fatalf("%s told the host of no reading of the form - either nothing changed or the line under the buttons was not said, and this guard cannot tell which", |
| 96 | + what) |
| 97 | + case host.settles > 1: |
| 98 | + t.Errorf("%s read the form %d times, expected once", what, host.settles) |
| 99 | + } |
| 100 | + } |
| 101 | + press := func(name string) func() { |
| 102 | + return func() { |
| 103 | + t.Helper() |
| 104 | + b := buttonNamed(body, name) |
| 105 | + if b == nil { |
| 106 | + t.Fatalf("the batch screen has no %q button, so this guard cannot press it", name) |
| 107 | + } |
| 108 | + b.OnTapped() |
| 109 | + } |
| 110 | + } |
| 111 | + base := func() *parts.Chooser { |
| 112 | + for _, c := range reportingControls(findField(rec.Fields(), recipe.KeyExtends).Control) { |
| 113 | + if pick, is := c.(*parts.Chooser); is { |
| 114 | + return pick |
| 115 | + } |
| 116 | + } |
| 117 | + t.Fatal("the base is switched on and there is no menu of presets under it") |
| 118 | + return nil |
| 119 | + } |
| 120 | + |
| 121 | + once("choosing png for the first batch", func() { |
| 122 | + chooserIn(t, rec.Fields(), recipe.TargetAddress(1, recipe.KeyFormat)).SetSelected("png") |
| 123 | + }) |
| 124 | + once("switching the base on", func() { toggleIn(t, rec.Fields(), "start_from_preset").SetChecked(true) }) |
| 125 | + once("choosing text-encoding as the base", func() { base().SetSelected("text-encoding") }) |
| 126 | + once("switching the base off", func() { toggleIn(t, rec.Fields(), "start_from_preset").SetChecked(false) }) |
| 127 | + |
| 128 | + once("adding a batch", press(text.ButtonAddBatch())) |
| 129 | + once("duplicating a batch", press(text.ButtonDuplicateBatch())) |
| 130 | + once("removing a batch", press(text.ButtonRemoveBatch())) |
| 131 | + once("choosing zip for the first batch", func() { |
| 132 | + chooserIn(t, rec.Fields(), recipe.TargetAddress(1, recipe.KeyFormat)).SetSelected("zip") |
| 133 | + }) |
| 134 | + once("adding what an archive holds", press(text.ButtonAddContents())) |
| 135 | + once("removing what an archive holds", press(text.ButtonRemoveContents())) |
| 136 | + |
| 137 | + // The base switched off with no batch left, which brings a batch back and |
| 138 | + // is the one way a switch and a press meet. Raised by the review of #133 |
| 139 | + // (docs/REVIEW-133-2026-09-24.md): the batch came back through the press's |
| 140 | + // path, which says the line, and the switch's check then said it again. |
| 141 | + once("switching the base on again", func() { toggleIn(t, rec.Fields(), "start_from_preset").SetChecked(true) }) |
| 142 | + for findField(rec.Fields(), recipe.TargetAddress(1, recipe.KeyID)) != nil { |
| 143 | + once("removing a batch with the base on", press(text.ButtonRemoveBatch())) |
| 144 | + } |
| 145 | + once("switching the base off with no batch left", func() { toggleIn(t, rec.Fields(), "start_from_preset").SetChecked(false) }) |
| 146 | + if findField(rec.Fields(), recipe.TargetAddress(1, recipe.KeyID)) == nil { |
| 147 | + t.Error("the base was switched off with no batch left and no batch came back, so the screen can produce nothing") |
| 148 | + } |
| 149 | +} |
| 150 | + |
70 | 151 | // Typing into a box a preset is not given does not expand the preset again. |
71 | 152 | // |
72 | 153 | // The seed and the output directory are read with the preset's values but are |
|
0 commit comments