SPB Git

Repository Public

WorkDatabaseTests.swift 26.6 KB 484 lines swift

1// SP Notes Core2// File: Tests/SPNotesFeaturesTests/WorkDatabaseTests.swift3// Description: The database view model and its pure pieces: the filter draft ⇄ `DatabaseViewFilter`, operators per type,4//              config merge, French cell display (computed and AI values), calendar and timeline geometry in the5//              server's time zone; then the model against the sample database: the six views, server rows vs local6//              evaluation, the "approximate offline" flag, the draft preview and its saving, row / view / property7//              writes, bulk actions, undoable deletion, offline and error states.8//9// Author: Simon-Pierre Boucher10// Contact: contact@spboucher.ai11import Foundation12import SPNotesAPI13import SPNotesDocument14import SPNotesSync15import Testing16@testable import SPNotesFeatures17@testable import SPNotesFeaturesCatalog1819@Suite("Work · database (pure)")20struct WorkDatabasePureTests {21    private func property(_ id: String, _ type: String, config: String = "{}") throws -> DatabaseProperty {22        try APIJSON.decoder().decode(DatabaseProperty.self, from: Data("""23        {"id":"\(id)","databaseId":"d","name":"\(id)","type":"\(type)","config":\(config),"position":1}24        """.utf8))25    }2627    @Test("filter draft: round trip of a nested tree; a bare rule is wrapped; empty groups disappear")28    func filterDraft() throws {29        let tree: DatabaseViewFilter = .all([.rule(property: "a", op: "gte", value: 430_000),30                                             .any([.rule(property: "b", op: "eq", value: "x"), .rule(property: "b", op: "empty", value: nil)])])31        var draft = DatabaseFilterDraft(filter: tree)32        #expect(draft.filter == tree)33        #expect(draft.ruleCount == 3)34        #expect(DatabaseFilterDraft(filter: .rule(property: "a", op: "eq", value: 1)).filter == .all([.rule(property: "a", op: "eq", value: 1)]))35        #expect(DatabaseFilterDraft(filter: nil).filter == nil)36        draft.addGroup()37        #expect(draft.filter == tree)                                          // the new empty group is not sent38        draft.addRule(.init(property: "c", op: "contains", value: "z"))39        #expect(draft.ruleCount == 4)40        guard case .rule(let first) = draft.root.nodes[0] else { Issue.record("expected a rule"); return }41        draft.update(first.id) { $0.op = "lt"; $0.value = 10 }42        #expect(draft.rule(first.id)?.op == "lt")43        draft.setConjunction(.any, of: draft.root.id)44        guard case .any(let nodes)? = draft.filter else { Issue.record("expected an or group"); return }45        #expect(nodes.first == .rule(property: "a", op: "lt", value: 10))46        draft.remove(first.id)47        #expect(draft.ruleCount == 3)48        // « is empty » carries no value even if one was typed before.49        var emptied = DatabaseFilterDraft()50        emptied.addRule(.init(property: "a", op: "empty", value: "reste"))51        #expect(emptied.filter == .all([.rule(property: "a", op: "empty", value: nil)]))52    }5354    @Test("operators per property type follow the server's engine")55    func operators() throws {56        #expect(DatabaseFilterOps.ops(for: "number").contains("gte"))57        #expect(!DatabaseFilterOps.ops(for: "number").contains("contains"))58        #expect(DatabaseFilterOps.ops(for: "date") == ["on", "before", "after", "empty", "not_empty"])59        #expect(DatabaseFilterOps.ops(for: "checkbox") == ["eq"])60        #expect(DatabaseFilterOps.ops(for: "multi_select").first == "contains")61        #expect(!DatabaseFilterOps.needsValue("not_empty"))62        let status = try property("s", "status", config: #"{"options":[{"id":"o1","name":"Un"}]}"#)63        #expect(DatabaseFilterOps.defaultRule(for: status).value == "o1")64        #expect(DatabaseFilterOps.defaultRule(for: try property("c", "checkbox")).value == true)65        for op in ["eq", "neq", "contains", "not_contains", "starts_with", "ends_with", "empty", "not_empty", "gt", "gte", "lt", "lte", "before", "after", "on"] {66            #expect(!DatabaseFilterOps.label(op).isEmpty)67        }68    }6970    @Test("query draft: merged into a view config without touching the other keys; dirtiness ignores local ids")71    func queryDraft() throws {72        let config: JSONValue = ["hidden": ["x"], "dateProperty": "d", "filter": ["and": [["property": "a", "op": "eq", "value": 1]]], "sorts": [["property": "a", "dir": "desc"]], "groupBy": "g"]73        var draft = DatabaseQueryDraft(config: config)74        #expect(draft.isSameQuery(as: DatabaseQueryDraft(config: config)))75        #expect(draft.sorts == [DatabaseViewSort(property: "a", descending: true)])76        #expect(draft.merged(into: config) == config)77        draft.groupBy = nil78        draft.sorts = []79        draft.filter = DatabaseFilterDraft()80        #expect(!draft.isSameQuery(as: DatabaseQueryDraft(config: config)))81        #expect(draft.merged(into: config) == ["hidden": ["x"], "dateProperty": "d"])82        // A rule alone is always sent inside a group (a bare rule is silently ignored by the server).83        var single = DatabaseQueryDraft()84        single.filter.addRule(.init(property: "a", op: "eq", value: 2))85        #expect(single.merged(into: nil)["filter"] == ["and": [["property": "a", "op": "eq", "value": 2]]])86    }8788    @Test("cells: French display of stored, computed, failed, pending and AI values")89    func cells() throws {90        let tz = DatabaseEvaluator.serverTimeZone91        #expect(DatabaseCellFormat.display(try property("n", "number", config: #"{"format":"currency"}"#), 48_000, timeZone: tz).text.contains("48"))92        #expect(DatabaseCellFormat.display(try property("c", "checkbox"), true, timeZone: tz) == DatabaseCellDisplay(kind: .checkbox(true), text: "Oui"))93        let select = try property("s", "select", config: #"{"options":[{"id":"o1","name":"Haute","color":"red"}]}"#)94        #expect(DatabaseCellFormat.display(select, "o1", timeZone: tz).kind == .options([.init(name: "Haute", color: "red")]))95        #expect(DatabaseCellFormat.display(select, "inconnu", timeZone: tz).text == "inconnu")96        let relation = try property("r", "relation")97        #expect(DatabaseCellFormat.display(relation, [["rowId": "1", "pageId": "p", "title": "Engle (1982)"]], timeZone: tz).kind == .relations(["Engle (1982)"]))98        #expect(DatabaseCellFormat.display(relation, [], timeZone: tz).kind == .empty)99        let formula = try property("f", "formula")100        #expect(DatabaseCellFormat.display(formula, ["error": "Unexpected end of formula"], timeZone: tz).kind == .error)101        #expect(DatabaseCellFormat.display(formula, 4000, timeZone: tz).kind == .number)102        #expect(DatabaseCellFormat.display(formula, nil, timeZone: tz).kind == .empty)103        let ai = try property("ai", "ai")104        #expect(DatabaseCellFormat.display(ai, ["pending": true], timeZone: tz).kind == .pending)105        let row = DatabaseRowValues(id: "1", title: "T", values: ["ai": "Un résumé."])106        #expect(DatabaseCellFormat.display(ai, row).isAI)107        #expect(!DatabaseCellFormat.display(try property("t", "text"), DatabaseRowValues(id: "1", title: "T", values: ["t": "x"])).isAI)108        #expect(DatabaseCellFormat.display(try property("ti", "title"), row).text == "T")109        #expect(DatabaseCellFormat.display(try property("u", "url"), "https://a.b", timeZone: tz).kind == .url("https://a.b"))110        for type in DatabasePropertyType.all {111            #expect(!DatabaseCellFormat.typeLabel(type).isEmpty)112            #expect(!DatabaseCellFormat.typeSymbol(type).isEmpty)113        }114        for type in DatabaseViewType.all { #expect(!DatabaseCellFormat.viewTypeLabel(type).isEmpty) }115    }116117    @Test("days are those of the server's time zone: an instant late in the evening UTC is still the same day in Toronto")118    func serverDays() throws {119        let toronto = try #require(TimeZone(identifier: "America/Toronto"))120        #expect(DatabaseCellFormat.day("2026-11-24", timeZone: toronto) == "2026-11-24")121        #expect(DatabaseCellFormat.day("2026-11-25T03:30:00.000Z", timeZone: toronto) == "2026-11-24")    // 22:30 on the 24th in Toronto122        #expect(DatabaseCellFormat.day("2026-11-25T03:30:00.000Z", timeZone: WorkDay.utc) == "2026-11-25")123        #expect(DatabaseCellFormat.day("", timeZone: toronto) == nil)124        #expect(DatabaseCellFormat.day(nil, timeZone: toronto) == nil)125        let date = try property("d", "date")126        let rows = [DatabaseRowValues(id: "a", title: "A", values: ["d": "2026-11-25T03:30:00.000Z"]), DatabaseRowValues(id: "b", title: "B", values: ["d": "2026-11-24"]),127                    DatabaseRowValues(id: "c", title: "C", values: [:])]128        let byDay = DatabaseCalendarLayout.rowsByDay(rows, property: date, timeZone: toronto)129        #expect(byDay["2026-11-24"]?.map(\.id) == ["a", "b"])130        #expect(byDay.count == 1)131    }132133    @Test("calendar month grid: weeks of seven slots starting on Monday or Sunday, month arithmetic")134    func monthGrid() {135        let november = DatabaseMonth(year: 2026, month: 11)                    // 1 Nov 2026 is a Sunday136        #expect(november.dayCount == 30)137        let monday = november.weeks(firstWeekday: 2)138        #expect(monday.allSatisfy { $0.count == 7 })139        #expect(monday[0] == [nil, nil, nil, nil, nil, nil, 1])140        #expect(monday.last?.first == 30)141        let sunday = november.weeks(firstWeekday: 1)142        #expect(sunday[0] == [1, 2, 3, 4, 5, 6, 7])143        #expect(sunday.count == 5)144        #expect(november.adding(2) == DatabaseMonth(year: 2027, month: 1))145        #expect(november.adding(-11) == DatabaseMonth(year: 2025, month: 12))146        #expect(november.key(day: 9) == "2026-11-09")147        #expect(DatabaseMonth(year: 2028, month: 2).dayCount == 29)148        #expect(DatabaseMonth(day: "2026-11-19") == november)149        #expect(DatabaseMonth.weekdaySymbols().count == 7)150        #expect(november.title.lowercased().contains("novembre"))151        #expect(DatabaseMonth(FeatureSamples.now, timeZone: DatabaseEvaluator.serverTimeZone) == november)152    }153154    @Test("timeline geometry: fractions of the whole range, inclusive days, inverted and undated rows")155    func timeline() throws {156        let start = try property("s", "date"), end = try property("e", "date")157        let rows = [158            DatabaseRowValues(id: "a", title: "A", values: ["s": "2026-11-01", "e": "2026-11-10"]),159            DatabaseRowValues(id: "b", title: "B", values: ["s": "2026-11-11", "e": "2026-11-20"]),160            DatabaseRowValues(id: "c", title: "C", values: ["s": "2026-11-05"]),161            DatabaseRowValues(id: "d", title: "D", values: ["s": "2026-11-08", "e": "2026-11-02"]),162            DatabaseRowValues(id: "e", title: "E", values: [:]),163        ]164        let layout = DatabaseTimelineLayout.layout(rows, start: start, end: end, timeZone: WorkDay.utc)165        #expect(layout.dayCount == 20)166        #expect(layout.firstDay == "2026-11-01")167        #expect(layout.lastDay == "2026-11-20")168        #expect(layout.undated == ["e"])169        #expect(layout.bars.map(\.id) == ["a", "c", "d", "b"])170        let a = try #require(layout.bars.first { $0.id == "a" }), b = try #require(layout.bars.first { $0.id == "b" })171        #expect(a.start == 0)172        #expect(abs(a.width - 0.5) < 1e-9)173        #expect(abs(b.start - 0.5) < 1e-9)174        #expect(abs(b.start + b.width - 1) < 1e-9)175        let c = try #require(layout.bars.first { $0.id == "c" }), d = try #require(layout.bars.first { $0.id == "d" })176        #expect(abs(c.width - 0.05) < 1e-9)                                    // no end: one day177        #expect(d.endDay == "2026-11-08")                                      // an end before its start: one day at the start178        #expect(layout.ticks.first?.position == 0)179        let none = DatabaseTimelineLayout.layout([rows[4]], start: start, end: end)180        #expect(none.bars.isEmpty)181        #expect(none.dayCount == 0)182        // Without an end property every bar is one day.183        #expect(DatabaseTimelineLayout.layout(rows, start: start, end: nil, timeZone: WorkDay.utc).bars.allSatisfy { $0.startDay == $0.endDay })184    }185}186187@Suite("Work · database (model)")188@MainActor189struct WorkDatabaseModelTests {190    private func loaded(_ world: FeatureWorld, router: FeatureRouterRecorder? = nil) async -> DatabaseModel {191        let model = DatabaseModel(repositories: world.repositories, databaseId: FeatureSamples.workDatabaseId, router: router, now: { FeatureSamples.now })192        await model.load()193        return model194    }195196    @Test("happy path: the definition, the default view sorted by the server, computed values present")197    func load() async throws {198        let world = try await FeatureWorld()199        let model = await loaded(world)200        #expect(model.phase == .loaded)201        #expect(model.database?.info.name == "Projets de recherche")202        #expect(model.views.count == 7)203        #expect(model.viewType == DatabaseViewType.table)204        #expect(model.source == .server)205        #expect(model.isExact)206        #expect(model.canWrite)207        #expect(model.rows.count == 8)208        #expect(model.rows.first?.id == "r-08")                                // earliest due date first, empty last209        #expect(model.rows.last?.id == "r-07")210        #expect(!model.visibleProperties.contains { $0.id == "p-created" })     // hidden by the view211        let first = try #require(model.row("r-01"))212        #expect(DatabaseCellFormat.display(try #require(model.property("p-refs")), first).kind == .relations(["Bollerslev (1986)", "Engle (1982)", "Hansen & Lunde (2005)"]))213        #expect(DatabaseCellFormat.display(try #require(model.property("p-monthly")), first).kind == .number)214        #expect(DatabaseCellFormat.display(try #require(model.property("p-ai")), first).isAI)215        #expect(model.isEditable(try #require(model.property("p-status"))))216        #expect(!model.isEditable(try #require(model.property("p-monthly"))))217        #expect(!model.isEditable(try #require(model.property("p-refs"))))218        #expect(!model.isEditable(try #require(model.property("p-ai"))))219    }220221    @Test("the host page id opens the same database")222    func byPageId() async throws {223        let world = try await FeatureWorld()224        let model = DatabaseModel(repositories: world.repositories, databaseId: FeatureSamples.workDatabasePageId)225        await model.load()226        #expect(model.database?.info.id == FeatureSamples.workDatabaseId)227        #expect(model.rows.count == 8)228    }229230    @Test("the six view kinds: board columns, grouped list, gallery, calendar days, timeline bars")231    func sixViews() async throws {232        let world = try await FeatureWorld()233        let model = await loaded(world)234        await model.selectView("v-board")235        #expect(model.viewType == DatabaseViewType.board)236        #expect(model.groups.map(\.label) == ["À lancer", "En cours", "En révision", "Publié"])237        #expect(model.groups.map(\.rows.count) == [2, 2, 2, 2])238        await model.selectView("v-list")239        #expect(model.groupProperty?.id == "p-prio")240        #expect(model.groups.map(\.label) == ["Haute", "Moyenne", "Basse"])241        await model.selectView("v-gallery")242        #expect(model.viewType == DatabaseViewType.gallery)243        #expect(model.groups.isEmpty)244        #expect(model.cardProperties.count == 4)245        await model.selectView("v-calendar")246        #expect(model.dateProperty?.id == "p-due")247        #expect(model.calendarMonth == DatabaseMonth(year: 2026, month: 11))248        #expect(model.rowsByDay["2026-11-19"]?.map(\.id) == ["r-06"])249        #expect(model.rowsByDay.keys.sorted().first == "2026-11-09")250        #expect(model.todayDay == "2026-11-19")251        await model.selectView("v-timeline")252        let timeline = try #require(model.timeline)253        #expect(model.timelineProperties?.start.id == "p-start")254        #expect(model.timelineProperties?.end?.id == "p-due")255        #expect(timeline.bars.count == 7)256        #expect(timeline.undated == ["r-07"])257        #expect(timeline.firstDay == "2026-08-10")258        #expect(timeline.lastDay == "2027-01-20")259    }260261    @Test("a view filtered on a formula: exact from the server; offline the device says approximate and names the property")262    func approximateOffline() async throws {263        let world = try await FeatureWorld()264        let model = await loaded(world)265        await model.selectView("v-funded")266        #expect(model.source == .server)267        #expect(model.isExact)268        #expect(model.rows.map(\.id) == ["r-08", "r-04", "r-01"])               // monthly budget > 3000, descending269        world.setOffline(true)270        await model.load()271        #expect(model.isOffline)272        #expect(model.source == .local)273        #expect(!model.isExact)274        #expect(model.notEvaluated == ["Budget / mois"])275        #expect(model.rows.count == 8)                                         // a superset: the rule could not be applied276        #expect(model.phase.failure?.isOffline == true)277        #expect(!model.canWrite)278        #expect(model.subtitle.contains("copie de l'appareil"))279    }280281    @Test("offline: read from the device, every write refused calmly, nothing queued")282    func offlineWrites() async throws {283        let world = try await FeatureWorld()284        let model = await loaded(world)285        world.setOffline(true)286        await model.load()287        #expect(model.rows.count == 8)288        #expect(model.isOffline)289        world.fake.clearLog()290        #expect(await model.setValue("s-done", rowId: "r-02", propertyId: "p-status") == false)291        #expect(model.actionFailure?.kind == .offline)292        #expect(await model.createRow(title: "Hors ligne") == false)293        #expect(await model.deleteRows(["r-01"]) == false)294        #expect(await model.saveView() == false)295        #expect(model.rows.count == 8)296        world.setOffline(false)297        #expect(world.fake.requests.filter { $0.status != 0 }.isEmpty)298        await model.load()299        #expect(!model.isOffline)300        #expect(model.row("r-02")?.values["p-status"] == "s-doing")301    }302303    @Test("offline and never synced: a typed failure")304    func neverCached() async throws {305        let world = try await FeatureWorld(samples: false)306        world.setOffline(true)307        let model = DatabaseModel(repositories: world.repositories, databaseId: FeatureSamples.workDatabaseId)308        await model.load()309        #expect(model.database == nil)310        #expect(model.phase.failure?.kind == .notCached)311    }312313    @Test("an unknown database and a server error are failures, not spinners")314    func errors() async throws {315        let world = try await FeatureWorld()316        world.fake.stub("GET", path: "^/api/databases/unknown$") { _ in .error(404, message: "Database not found") }317        let missing = DatabaseModel(repositories: world.repositories, databaseId: "unknown")318        await missing.load()319        #expect(missing.phase.failure?.kind == .notFound)320        let model = await loaded(world)321        world.fake.inject(.status(500), method: "PATCH", path: "/rows$")322        #expect(await model.setValue("s-done", rowId: "r-02", propertyId: "p-status") == false)323        #expect(model.actionFailure?.kind == .server)324        #expect(!model.isOffline)325    }326327    @Test("the builders: a draft is a preview asked to the server; saving writes it in the view; reset drops it")328    func draftAndSave() async throws {329        let world = try await FeatureWorld()330        let model = await loaded(world)331        #expect(!model.isDraftDirty)332        let status = try #require(model.property("p-status"))333        model.draft.filter.addRule(.init(property: status.id, op: "eq", value: "s-doing"))334        model.draft.sorts = [DatabaseViewSort(property: "p-budget", descending: true)]335        #expect(model.isDraftDirty)336        world.fake.clearLog()337        await model.applyDraft()338        #expect(model.rows.map(\.id) == ["r-04", "r-02"])339        #expect(model.source == .server)340        #expect(world.fake.count("POST", "/query$") == 1)341        #expect(world.fake.count("PATCH", "/views$") == 0)                     // a preview writes nothing342        #expect(await model.saveView())343        #expect(!model.isDraftDirty)344        #expect(model.currentView?.typedConfig.sorts?.first?.property == "p-budget")345        #expect(model.currentView?.typedConfig.hidden == ["p-created"])        // untouched keys survive346        #expect(model.rows.map(\.id) == ["r-04", "r-02"])347        model.draft.filter = DatabaseFilterDraft()348        await model.applyDraft()349        #expect(model.rows.count == 8)350        await model.resetDraft()351        #expect(model.rows.count == 2)352    }353354    @Test("offline preview of a draft is computed on the device")355    func offlineDraft() async throws {356        let world = try await FeatureWorld()357        let model = await loaded(world)358        world.setOffline(true)359        model.draft.filter.addRule(.init(property: "p-prio", op: "eq", value: "o-high"))360        model.draft.groupBy = "p-status"361        await model.applyDraft()362        #expect(model.source == .local)363        #expect(model.isExact)364        #expect(Set(model.rows.map(\.id)) == ["r-01", "r-02", "r-08"])365        #expect(model.groups.map(\.rows.count).reduce(0, +) == 3)366    }367368    @Test("search narrows the rows")369    func search() async throws {370        let world = try await FeatureWorld()371        let model = await loaded(world)372        model.search = "garch"373        await model.applyDraft()374        #expect(model.rows.map(\.id) == ["r-01"])375        #expect(model.total == 1)376        model.search = ""377        await model.applyDraft()378        #expect(model.rows.count == 8)379    }380381    @Test("cell edits: typed text is parsed by property type; a bad number or date is refused before any request")382    func cellEdits() async throws {383        let world = try await FeatureWorld()384        let model = await loaded(world)385        let budget = try #require(model.property("p-budget")), due = try #require(model.property("p-due")), title = try #require(model.titleProperty)386        #expect(await model.setText("52 500", rowId: "r-02", property: budget))387        #expect(model.row("r-02")?.values["p-budget"]?.doubleValue == 52_500)388        #expect(model.row("r-02")?.values["p-monthly"]?.doubleValue == 4375)     // the server recomputed the formula389        world.fake.clearLog()390        #expect(await model.setText("beaucoup", rowId: "r-02", property: budget) == false)391        #expect(await model.setText("demain", rowId: "r-02", property: due) == false)392        #expect(model.actionFailure != nil)393        #expect(world.fake.count("PATCH", "/rows$") == 0)394        #expect(await model.setText("2026-12-24", rowId: "r-02", property: due))395        #expect(model.row("r-02")?.values["p-due"] == "2026-12-24")396        #expect(await model.setText("", rowId: "r-02", property: due))397        #expect(model.row("r-02")?.values["p-due"] == nil)398        #expect(await model.setText("Courbe des taux (v2)", rowId: "r-02", property: title))399        #expect(model.row("r-02")?.title == "Courbe des taux (v2)")400        #expect(await model.setText("  ", rowId: "r-02", property: title) == false)401        #expect(await model.toggleOption("t-ia", rowId: "r-02", property: try #require(model.property("p-tags"))))402        #expect(model.row("r-02")?.values["p-tags"] == ["t-fin", "t-ia"])403        #expect(await model.toggleOption("t-fin", rowId: "r-02", property: try #require(model.property("p-tags"))))404        #expect(model.row("r-02")?.values["p-tags"] == ["t-ia"])405    }406407    @Test("board: moving a card sets the grouping property")408    func boardMove() async throws {409        let world = try await FeatureWorld()410        let model = await loaded(world)411        await model.selectView("v-board")412        #expect(await model.move(rowId: "r-05", toGroup: "s-done"))413        #expect(model.groups.first { $0.id == "s-done" }?.rows.map(\.id).contains("r-05") == true)414        #expect(model.groups.first { $0.id == "s-todo" }?.rows.map(\.id) == ["r-07"])415        #expect(await model.move(rowId: "r-05", toGroup: ""))416        #expect(model.groups.last?.label == "")417        #expect(model.groups.last?.rows.map(\.id) == ["r-05"])418    }419420    @Test("rows: create, multi-select, bulk set, delete with undo")421    func rowsAndBulk() async throws {422        let world = try await FeatureWorld()423        let router = FeatureRouterRecorder()424        let model = await loaded(world, router: router)425        model.newRowTitle = "Nouveau projet"426        #expect(await model.createRow())427        #expect(model.newRowTitle.isEmpty)428        #expect(model.rows.count == 9)429        let created = try #require(model.rows.first { $0.title == "Nouveau projet" })430        model.openRow(created)431        #expect(router.calls.count == 1)432        model.isSelecting = true433        model.toggleSelection(created.id)434        model.toggleSelection("r-07")435        #expect(model.selection.count == 2)436        #expect(model.bulkProperties.map(\.id) == ["p-status", "p-prio", "p-ready"])437        #expect(await model.bulkSet("s-review", propertyId: "p-status"))438        #expect(model.row("r-07")?.values["p-status"] == "s-review")439        #expect(model.row(created.id)?.values["p-status"] == "s-review")440        #expect(await model.bulkSet(true, propertyId: "p-ready"))441        #expect(model.row("r-07")?.values["p-ready"] == true)442        #expect(await model.deleteSelection())443        #expect(model.rows.count == 7)444        #expect(model.selection.isEmpty)445        #expect(model.lastDeleted.count == 2)446        #expect(await model.undoDelete())447        #expect(model.rows.count == 9)448        #expect(model.lastDeleted.isEmpty)449        model.selectAll()450        #expect(model.selection.count == 9)451        model.endSelection()452        #expect(!model.isSelecting)453        model.openURL("https://git.example.org/wp46")454        #expect(router.calls.last == .url(URL(string: "https://git.example.org/wp46")!))455    }456457    @Test("structure: a new property and a new view are created online and selected")458    func structure() async throws {459        let world = try await FeatureWorld()460        let model = await loaded(world)461        #expect(await model.createProperty(name: "  ", type: DatabasePropertyType.text) == false)462        #expect(await model.createProperty(name: "Revue visée", type: DatabasePropertyType.text))463        #expect(model.properties.contains { $0.name == "Revue visée" })464        #expect(await model.createView(type: DatabaseViewType.gallery, name: "Vignettes"))465        #expect(model.currentView?.name == "Vignettes")466        #expect(model.viewType == DatabaseViewType.gallery)467        #expect(model.views.count == 8)468        #expect(await model.deleteCurrentView())469        #expect(model.views.count == 7)470        #expect(model.currentView?.id == "v-table")471    }472473    @Test("an empty database view")474    func empty() async throws {475        let world = try await FeatureWorld()476        let model = await loaded(world)477        model.search = "aucune ligne ne contient ceci"478        await model.applyDraft()479        #expect(model.rows.isEmpty)480        #expect(model.phase == .loaded)481        #expect(model.total == 0)482    }483}484
Files main
Menu

Theme