diff options
Diffstat (limited to 'test/settings/ManageTest.mc')
| -rw-r--r-- | test/settings/ManageTest.mc | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/test/settings/ManageTest.mc b/test/settings/ManageTest.mc index 1f050c5..4c93f60 100644 --- a/test/settings/ManageTest.mc +++ b/test/settings/ManageTest.mc @@ -1,6 +1,7 @@ // Author: cirakg & claude ai // Summary: Tests for the Manage entry form: every action on unlocked entries, the PIN queue for locked ones, IDs, repeats and damage. +import Toybox.Application; import Toybox.Lang; import Toybox.Test; @@ -43,9 +44,29 @@ module ManageFixtures { return s; } + // What PinView runs after a correct PIN: promotion and waiting locks. + function applyLocks(v as Vault) as LockJob { + var job = new LockJob(v, true); + Jobs.runToCompletion(job, 1); + return job; + } + + // Every queued item, opened (the ones that verify). + function load(v as Vault) as Array<ManageAction> { + var items = ChangeQueue.items(v); + var out = [] as Array<ManageAction>; + for (var i = 0; i < items.size(); i++) { + var a = ChangeQueue.open(v, items[i], new Jobs.Wiper(), true); + if (a != null) { + out.add(a); + } + } + return out; + } + // Confirm the waiting changes, as after a correct PIN. function confirm(v as Vault) as ChangeQueueJob { - var job = new ChangeQueueJob(v); + var job = new ChangeQueueJob(v, null); Jobs.runToCompletion(job, 1); return job; } @@ -256,7 +277,7 @@ function manageLocksEntries(logger as Test.Logger) as Boolean { } // Waiting "Require PIN" changes apply at the next PIN without "Confirm -// all" (the PIN screen calls applyLocks); other changes keep waiting, and +// all" (the PIN screen runs LockJob); other changes keep waiting, and // the results of a following "Confirm all" list the locks too. (:test) function manageQueuedLocksApplyAtNextPin(logger as Test.Logger) as Boolean { @@ -271,14 +292,14 @@ function manageQueuedLocksApplyAtNextPin(logger as Test.Logger) as Boolean { s = ManageFixtures.send(vault, ids[1], ManageAction.LOCK); SettingsFixtures.run(vault, s); var counted = ChangeQueue.count(vault) == 3 && ChangeQueue.countLocks(vault) == 2; - ChangeQueue.applyLocks(vault); // still locked: nothing happens + ManageFixtures.applyLocks(vault); // still locked: nothing happens var untouched = ChangeQueue.count(vault) == 3 && !ManageFixtures.isLocked(vault, ids[0]); StorageFixtures.unlock(vault, StorageFixtures.PIN); - ChangeQueue.applyLocks(vault); + var locks = ManageFixtures.applyLocks(vault); var left = ChangeQueue.descriptions(vault); var applied = ManageFixtures.isLocked(vault, ids[0]) && ManageFixtures.isLocked(vault, ids[1]) && left.size() == 1 && left[0].equals("Delete: " + bank + " Bank (alice@example.com)") - && ChangeQueue.countLocks(vault) == 0 && vault.ids().indexOf(bank) >= 0; + && ChangeQueue.countLocks(vault) == 0 && vault.ids().indexOf(bank) >= 0 && locks.lines.size() == 2; var job = ManageFixtures.confirm(vault); var reported = job.lines.size() == 3 && job.lines[0].find(ids[0] + " ") == 0 && job.lines[0].find("now requires the PIN") != null && SettingsFixtures.hasLine(job.lines, "Deleted " + bank); @@ -299,7 +320,7 @@ function manageQueueKeepsLateArrivals(logger as Test.Logger) as Boolean { var safe = ManageFixtures.addLocked(vault, "Safe"); var s = ManageFixtures.send(vault, bank, ManageAction.DELETE); SettingsFixtures.run(vault, s); - var job = new ChangeQueueJob(vault); + var job = new ChangeQueueJob(vault, null); job.step(1); s = ManageFixtures.send(vault, safe, ManageAction.DELETE); SettingsFixtures.run(vault, s); @@ -337,10 +358,10 @@ function manageQueueIsSealedAndLimited(logger as Test.Logger) as Boolean { b.id = "M3P9"; b.action = ManageAction.DELETE; ChangeQueue.add(vault, b); - var raw = (vault.storage() as MemoryBackend).raw(ChangeQueue.KEY) as Array<ByteArray>; - var box = raw[0]; + var raw = (vault.storage() as MemoryBackend).raw(ChangeQueue.KEY) as Array<Array<Application.Storage.ValueType>>; + var box = raw[0][1] as ByteArray; box[20] = box[20] ^ 1; - var loaded = ChangeQueue.load(vault); + var loaded = ManageFixtures.load(vault); var sealed = loaded.size() == 1 && loaded[0].id.equals("M3P9") && loaded[0].action == ManageAction.DELETE; var roundTrip = ManageAction.fromBytes(a.toBytes()); var same = roundTrip != null && roundTrip.decoded && roundTrip.label.equals("Bank") |
