feat(swift-ios): default new tasks to recent project (#5802)
This commit is contained in:
1 parent
50bd5cbba2
commit
69542f3162
4 files changed
+524
-12
No files matched your search
@@ -112,6 +112,57 @@ enum DailyUXCreationContext {
|
||||
)
|
||||
}
|
||||
|
||||
static func recentProjects(in snapshot: FeatureSnapshot) -> [DailyUXRecentProject] {
|
||||
let groups = projectGroups(in: snapshot)
|
||||
let availableProjectByID = projects(in: snapshot).reduce(
|
||||
into: [String: FeatureProject]()
|
||||
) { $0[$1.id] = $1 }
|
||||
let groupByProjectID = groups.reduce(into: [String: DailyUXProjectGroup]()) {
|
||||
result, group in
|
||||
for projectID in group.memberProjectIDs {
|
||||
result[projectID] = group
|
||||
}
|
||||
}
|
||||
var seenGroupIDs = Set<String>()
|
||||
|
||||
return snapshot.threads
|
||||
.sorted(by: recentUseOrder)
|
||||
.compactMap { thread in
|
||||
guard let group = groupByProjectID[thread.projectID],
|
||||
let sourceProject = availableProjectByID[thread.projectID],
|
||||
let project = DailyUXProjectGrouping.physicalRepresentative(
|
||||
for: sourceProject,
|
||||
in: group
|
||||
),
|
||||
seenGroupIDs.insert(group.id).inserted else {
|
||||
return nil
|
||||
}
|
||||
return DailyUXRecentProject(group: group, project: project)
|
||||
}
|
||||
}
|
||||
|
||||
static func initialProject(
|
||||
in snapshot: FeatureSnapshot,
|
||||
requestedProjectID: String?
|
||||
) -> FeatureProject? {
|
||||
let availableProjects = projects(in: snapshot)
|
||||
if let requestedProjectID,
|
||||
let requestedProject = availableProjects.first(where: { $0.id == requestedProjectID }),
|
||||
let group = DailyUXProjectGrouping.group(
|
||||
containing: requestedProjectID,
|
||||
in: projectGroups(in: snapshot)
|
||||
),
|
||||
let representative = DailyUXProjectGrouping.physicalRepresentative(
|
||||
for: requestedProject,
|
||||
in: group
|
||||
) {
|
||||
return representative
|
||||
}
|
||||
|
||||
return recentProjects(in: snapshot).first?.project
|
||||
?? projectGroups(in: snapshot).first?.projects.first
|
||||
}
|
||||
|
||||
static func logicalProjectID(
|
||||
for project: FeatureProject,
|
||||
in snapshot: FeatureSnapshot
|
||||
@@ -130,6 +181,35 @@ enum DailyUXCreationContext {
|
||||
)
|
||||
}
|
||||
|
||||
private static func recentUseOrder(_ lhs: FeatureThread, _ rhs: FeatureThread) -> Bool {
|
||||
let lhsDate = lhs.lastActivityAt ?? lhs.updatedAt
|
||||
let rhsDate = rhs.lastActivityAt ?? rhs.updatedAt
|
||||
if lhsDate != rhsDate { return lhsDate > rhsDate }
|
||||
return lhs.id < rhs.id
|
||||
}
|
||||
|
||||
static func shouldAdoptAutomaticProject(
|
||||
currentProjectID: String,
|
||||
nextRecentProjectID: String?,
|
||||
isAwaitingRecentActivity: Bool,
|
||||
projectSelectionIsExplicit: Bool,
|
||||
modelSelectionIsExplicit: Bool,
|
||||
workspaceSelectionIsExplicit: Bool,
|
||||
hasDraftContent: Bool,
|
||||
draftRestoreIsComplete: Bool
|
||||
) -> Bool {
|
||||
guard isAwaitingRecentActivity,
|
||||
let nextRecentProjectID,
|
||||
nextRecentProjectID != currentProjectID else {
|
||||
return false
|
||||
}
|
||||
return !projectSelectionIsExplicit
|
||||
&& !modelSelectionIsExplicit
|
||||
&& !workspaceSelectionIsExplicit
|
||||
&& !hasDraftContent
|
||||
&& draftRestoreIsComplete
|
||||
}
|
||||
|
||||
static func providers(
|
||||
for project: FeatureProject?,
|
||||
in snapshot: FeatureSnapshot
|
||||
@@ -187,6 +267,11 @@ enum DailyUXCreationContext {
|
||||
}
|
||||
}
|
||||
|
||||
struct DailyUXRecentProject: Equatable {
|
||||
let group: DailyUXProjectGroup
|
||||
let project: FeatureProject
|
||||
}
|
||||
|
||||
struct DailyUXProjectGroup: Identifiable, Equatable {
|
||||
let id: String
|
||||
let name: String
|
||||
@@ -264,6 +349,17 @@ enum DailyUXProjectGrouping {
|
||||
.preferredProject(environmentID: preferredEnvironmentID)
|
||||
}
|
||||
|
||||
static func physicalRepresentative(
|
||||
for project: FeatureProject,
|
||||
in group: DailyUXProjectGroup
|
||||
) -> FeatureProject? {
|
||||
let path = normalizedPath(project.path)
|
||||
return group.projects.first {
|
||||
$0.environmentID == project.environmentID
|
||||
&& normalizedPath($0.path) == path
|
||||
}
|
||||
}
|
||||
|
||||
private static func physicalKey(_ project: FeatureProject) -> String {
|
||||
"\(project.environmentID):\(normalizedPath(project.path))"
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ public struct NewThreadView: View {
|
||||
private let initialProjectID: String?
|
||||
|
||||
@State private var projectID = ""
|
||||
@State private var projectSelectionIsExplicit = false
|
||||
@State private var isAwaitingRecentProject = false
|
||||
@State private var prompt = ""
|
||||
@State private var selection: FeatureSelection?
|
||||
@State private var selectionIsExplicit = false
|
||||
@@ -89,22 +91,32 @@ public struct NewThreadView: View {
|
||||
}
|
||||
.onAppear {
|
||||
if projectID.isEmpty {
|
||||
let initialProject = creationProjects.first { $0.id == initialProjectID }
|
||||
let initialGroup = initialProject.flatMap {
|
||||
DailyUXProjectGrouping.group(
|
||||
containing: $0.id,
|
||||
in: creationProjectGroups
|
||||
)
|
||||
}
|
||||
let initialID = initialGroup?.preferredProject(
|
||||
environmentID: initialProject?.environmentID
|
||||
)?.id ?? creationProjectGroups.first?.projects.first?.id ?? ""
|
||||
let recentProject = DailyUXCreationContext.recentProjects(
|
||||
in: model.snapshot
|
||||
).first?.project
|
||||
let initialID = DailyUXCreationContext.initialProject(
|
||||
in: model.snapshot,
|
||||
requestedProjectID: initialProjectID
|
||||
)?.id ?? ""
|
||||
isAwaitingRecentProject = initialProjectID == nil && recentProject == nil
|
||||
selectInitialProject(initialID)
|
||||
}
|
||||
}
|
||||
.onChange(of: projectID) { prepareProjectIfNeeded(projectID) }
|
||||
.onChange(of: creationProjectIDs) { _, ids in
|
||||
guard !ids.contains(projectID) else { return }
|
||||
if projectID.isEmpty {
|
||||
let recentProject = DailyUXCreationContext.recentProjects(
|
||||
in: model.snapshot
|
||||
).first?.project
|
||||
let initialID = DailyUXCreationContext.initialProject(
|
||||
in: model.snapshot,
|
||||
requestedProjectID: initialProjectID
|
||||
)?.id ?? ""
|
||||
isAwaitingRecentProject = initialProjectID == nil && recentProject == nil
|
||||
selectInitialProject(initialID)
|
||||
return
|
||||
}
|
||||
persistCurrentDraftImmediately()
|
||||
let previousProject = model.snapshot.projects.first { $0.id == projectID }
|
||||
let previousGroupID = previousProject.map {
|
||||
@@ -115,6 +127,9 @@ public struct NewThreadView: View {
|
||||
?? creationProjectGroups.first?.projects.first
|
||||
selectInitialProject(replacement?.id ?? "")
|
||||
}
|
||||
.onChange(of: model.homePresentationRevision) { _, _ in
|
||||
refreshAutomaticProjectIfNeeded()
|
||||
}
|
||||
.onChange(of: prompt) { scheduleDraftSave() }
|
||||
.onChange(of: selection) { scheduleDraftSave() }
|
||||
.onChange(of: attachments) { scheduleDraftSave() }
|
||||
@@ -559,8 +574,10 @@ public struct NewThreadView: View {
|
||||
|
||||
@discardableResult
|
||||
private func selectProject(_ id: String) -> Bool {
|
||||
guard id != projectID else { return true }
|
||||
guard creationProjects.contains(where: { $0.id == id }) else { return false }
|
||||
projectSelectionIsExplicit = true
|
||||
isAwaitingRecentProject = false
|
||||
guard id != projectID else { return true }
|
||||
persistCurrentDraftImmediately()
|
||||
projectID = id
|
||||
prepareProjectIfNeeded(id)
|
||||
@@ -574,6 +591,7 @@ public struct NewThreadView: View {
|
||||
preferredEnvironmentID: selectedProject?.environmentID,
|
||||
in: creationProjectGroups
|
||||
) else { return false }
|
||||
projectSelectionIsExplicit = true
|
||||
guard group.id != selectedProjectGroup?.id else { return true }
|
||||
return selectProject(target.id)
|
||||
}
|
||||
@@ -590,6 +608,37 @@ public struct NewThreadView: View {
|
||||
prepareProjectIfNeeded(id)
|
||||
}
|
||||
|
||||
private func refreshAutomaticProjectIfNeeded() {
|
||||
guard isAwaitingRecentProject else { return }
|
||||
let nextProjectID = DailyUXCreationContext.recentProjects(
|
||||
in: model.snapshot
|
||||
).first?.project.id
|
||||
guard let nextProjectID else { return }
|
||||
if nextProjectID == projectID {
|
||||
isAwaitingRecentProject = false
|
||||
return
|
||||
}
|
||||
let draftRestoreIsComplete = restoredDraftProjectID == projectID
|
||||
guard DailyUXCreationContext.shouldAdoptAutomaticProject(
|
||||
currentProjectID: projectID,
|
||||
nextRecentProjectID: nextProjectID,
|
||||
isAwaitingRecentActivity: isAwaitingRecentProject,
|
||||
projectSelectionIsExplicit: projectSelectionIsExplicit,
|
||||
modelSelectionIsExplicit: selectionIsExplicit,
|
||||
workspaceSelectionIsExplicit: workspaceSelectionIsExplicit,
|
||||
hasDraftContent: !prompt.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
|
||||
|| !attachments.isEmpty,
|
||||
draftRestoreIsComplete: draftRestoreIsComplete
|
||||
) else {
|
||||
if draftRestoreIsComplete {
|
||||
isAwaitingRecentProject = false
|
||||
}
|
||||
return
|
||||
}
|
||||
isAwaitingRecentProject = false
|
||||
selectInitialProject(nextProjectID)
|
||||
}
|
||||
|
||||
private func prepareProjectIfNeeded(_ id: String) {
|
||||
guard draftRestoreContext?.projectID != id else { return }
|
||||
|
||||
@@ -747,6 +796,8 @@ public struct NewThreadView: View {
|
||||
if liveDraft != context.baseline {
|
||||
scheduleDraftSave()
|
||||
}
|
||||
refreshAutomaticProjectIfNeeded()
|
||||
guard projectID == requestedProjectID else { return }
|
||||
await loadBranches()
|
||||
}
|
||||
|
||||
|
||||
@@ -564,7 +564,7 @@ public struct WorkspaceView: View {
|
||||
}
|
||||
|
||||
private func openNewTaskOrProjectCreation() {
|
||||
openNewTaskOrProjectCreation(initialProjectID: nil)
|
||||
openNewTaskOrProjectCreation(initialProjectID: selectedProjectID)
|
||||
}
|
||||
|
||||
private func openNewTaskOrProjectCreation(initialProjectID: String?) {
|
||||
|
||||
@@ -5,6 +5,308 @@ import UIKit
|
||||
|
||||
@Suite("Message-first task creation")
|
||||
struct DailyUXNewTaskTests {
|
||||
@Test
|
||||
func recentProjectRankingDrivesTheDefaultAndKeepsUnusedProjectsOut() {
|
||||
let alpha = rankedProject("alpha", name: "Alpha")
|
||||
let beta = rankedProject("beta", name: "Beta")
|
||||
let unused = rankedProject("unused", name: "Unused")
|
||||
let value = rankedSnapshot(
|
||||
projects: [unused, beta, alpha],
|
||||
threads: [
|
||||
rankedThread("older", projectID: alpha.id, activity: 10),
|
||||
rankedThread("newer", projectID: beta.id, activity: 20),
|
||||
]
|
||||
)
|
||||
|
||||
let ranking = DailyUXCreationContext.recentProjects(in: value)
|
||||
|
||||
#expect(ranking.map(\.project.id) == [beta.id, alpha.id])
|
||||
#expect(
|
||||
DailyUXCreationContext.initialProject(in: value, requestedProjectID: nil)?.id
|
||||
== ranking.first?.project.id
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
func recentProjectRankingIsStableForTiesAndIgnoresMissingProjects() {
|
||||
let alpha = rankedProject("alpha", name: "Alpha")
|
||||
let beta = rankedProject("beta", name: "Beta")
|
||||
let value = rankedSnapshot(
|
||||
projects: [alpha, beta],
|
||||
threads: [
|
||||
rankedThread("z-thread", projectID: alpha.id, activity: 20),
|
||||
rankedThread("missing", projectID: "missing", activity: 30),
|
||||
rankedThread("a-thread", projectID: beta.id, activity: 20),
|
||||
]
|
||||
)
|
||||
|
||||
#expect(
|
||||
DailyUXCreationContext.recentProjects(in: value)
|
||||
.map(\.project.id) == [beta.id, alpha.id]
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
func recentProjectRankingUsesActivityInsteadOfMetadataChanges() {
|
||||
let alpha = rankedProject("alpha", name: "Alpha")
|
||||
let beta = rankedProject("beta", name: "Beta")
|
||||
let value = rankedSnapshot(
|
||||
projects: [alpha, beta],
|
||||
threads: [
|
||||
rankedThread(
|
||||
"metadata-change",
|
||||
projectID: alpha.id,
|
||||
updatedAt: 100,
|
||||
lastActivityAt: 10
|
||||
),
|
||||
rankedThread("actual-use", projectID: beta.id, activity: 20),
|
||||
]
|
||||
)
|
||||
|
||||
#expect(
|
||||
DailyUXCreationContext.recentProjects(in: value)
|
||||
.map(\.project.id) == [beta.id, alpha.id]
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
func archivedAndSettledThreadsStillRepresentProjectUse() {
|
||||
let archived = rankedProject("archived", name: "Archived")
|
||||
let settled = rankedProject("settled", name: "Settled")
|
||||
let value = rankedSnapshot(
|
||||
projects: [archived, settled],
|
||||
threads: [
|
||||
rankedThread(
|
||||
"archived-thread",
|
||||
projectID: archived.id,
|
||||
activity: 30,
|
||||
isArchived: true
|
||||
),
|
||||
rankedThread(
|
||||
"settled-thread",
|
||||
projectID: settled.id,
|
||||
activity: 20,
|
||||
isSettled: true
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
#expect(
|
||||
DailyUXCreationContext.recentProjects(in: value)
|
||||
.map(\.project.id) == [archived.id, settled.id]
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
func explicitProjectWinsAndNoActivityFallsBackAlphabetically() {
|
||||
let zulu = rankedProject("zulu", name: "Zulu")
|
||||
let alpha = rankedProject("alpha", name: "Alpha")
|
||||
let withActivity = rankedSnapshot(
|
||||
projects: [zulu, alpha],
|
||||
threads: [rankedThread("recent", projectID: zulu.id, activity: 20)]
|
||||
)
|
||||
let withoutActivity = rankedSnapshot(projects: [zulu, alpha], threads: [])
|
||||
|
||||
#expect(
|
||||
DailyUXCreationContext.initialProject(
|
||||
in: withActivity,
|
||||
requestedProjectID: alpha.id
|
||||
)?.id == alpha.id
|
||||
)
|
||||
#expect(DailyUXCreationContext.recentProjects(in: withoutActivity).isEmpty)
|
||||
#expect(
|
||||
DailyUXCreationContext.initialProject(
|
||||
in: withoutActivity,
|
||||
requestedProjectID: nil
|
||||
)?.id == alpha.id
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
func recentProjectRankingExcludesDisabledEnvironments() {
|
||||
let enabled = rankedProject("enabled", name: "Enabled", environmentID: "enabled-env")
|
||||
let disabled = rankedProject("disabled", name: "Disabled", environmentID: "disabled-env")
|
||||
let value = rankedSnapshot(
|
||||
environments: [
|
||||
FeatureEnvironment(
|
||||
id: "enabled-env",
|
||||
name: "Enabled",
|
||||
endpoint: "http://enabled",
|
||||
isEnabled: true
|
||||
),
|
||||
FeatureEnvironment(
|
||||
id: "disabled-env",
|
||||
name: "Disabled",
|
||||
endpoint: "http://disabled",
|
||||
isEnabled: false
|
||||
),
|
||||
],
|
||||
projects: [enabled, disabled],
|
||||
threads: [
|
||||
rankedThread("enabled-thread", projectID: enabled.id, activity: 10),
|
||||
rankedThread("disabled-thread", projectID: disabled.id, activity: 20),
|
||||
]
|
||||
)
|
||||
|
||||
#expect(
|
||||
DailyUXCreationContext.recentProjects(in: value).map(\.project.id) == [enabled.id]
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
func recentProjectRankingDeduplicatesARepositoryAcrossEnvironments() {
|
||||
let local = rankedProject(
|
||||
"local",
|
||||
name: "Project",
|
||||
environmentID: "local-env",
|
||||
repositoryKey: "github.com/example/project"
|
||||
)
|
||||
let remote = rankedProject(
|
||||
"remote",
|
||||
name: "Project",
|
||||
environmentID: "remote-env",
|
||||
repositoryKey: "github.com/example/project"
|
||||
)
|
||||
let value = rankedSnapshot(
|
||||
environments: [
|
||||
FeatureEnvironment(
|
||||
id: "local-env",
|
||||
name: "Local",
|
||||
endpoint: "http://local"
|
||||
),
|
||||
FeatureEnvironment(
|
||||
id: "remote-env",
|
||||
name: "Remote",
|
||||
endpoint: "http://remote"
|
||||
),
|
||||
],
|
||||
projects: [local, remote],
|
||||
threads: [
|
||||
rankedThread(
|
||||
"local-thread",
|
||||
projectID: local.id,
|
||||
environmentID: "local-env",
|
||||
activity: 10
|
||||
),
|
||||
rankedThread(
|
||||
"remote-thread",
|
||||
projectID: remote.id,
|
||||
environmentID: "remote-env",
|
||||
activity: 20
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
let ranking = DailyUXCreationContext.recentProjects(in: value)
|
||||
#expect(ranking.count == 1)
|
||||
#expect(ranking.first?.project.id == remote.id)
|
||||
}
|
||||
|
||||
@Test
|
||||
func recentProjectRankingKeepsTheExactWorktreeUsedByTheThread() {
|
||||
let root = rankedProject(
|
||||
"root",
|
||||
name: "Project",
|
||||
repositoryKey: "github.com/example/project"
|
||||
)
|
||||
let worktree = rankedProject(
|
||||
"worktree",
|
||||
name: "Project",
|
||||
repositoryKey: "github.com/example/project"
|
||||
)
|
||||
let value = rankedSnapshot(
|
||||
projects: [root, worktree],
|
||||
threads: [rankedThread("recent", projectID: worktree.id, activity: 20)]
|
||||
)
|
||||
|
||||
#expect(DailyUXCreationContext.recentProjects(in: value).first?.project.id == worktree.id)
|
||||
#expect(
|
||||
DailyUXCreationContext.initialProject(
|
||||
in: value,
|
||||
requestedProjectID: worktree.id
|
||||
)?.id == worktree.id
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
func automaticProjectAdoptionWaitsForRestoreAndStopsAfterExplicitChoices() {
|
||||
#expect(
|
||||
DailyUXCreationContext.shouldAdoptAutomaticProject(
|
||||
currentProjectID: "fallback",
|
||||
nextRecentProjectID: "recent",
|
||||
isAwaitingRecentActivity: true,
|
||||
projectSelectionIsExplicit: false,
|
||||
modelSelectionIsExplicit: false,
|
||||
workspaceSelectionIsExplicit: false,
|
||||
hasDraftContent: false,
|
||||
draftRestoreIsComplete: true
|
||||
)
|
||||
)
|
||||
|
||||
for explicitChoice in 0..<3 {
|
||||
#expect(
|
||||
!DailyUXCreationContext.shouldAdoptAutomaticProject(
|
||||
currentProjectID: "fallback",
|
||||
nextRecentProjectID: "recent",
|
||||
isAwaitingRecentActivity: true,
|
||||
projectSelectionIsExplicit: explicitChoice == 0,
|
||||
modelSelectionIsExplicit: explicitChoice == 1,
|
||||
workspaceSelectionIsExplicit: explicitChoice == 2,
|
||||
hasDraftContent: false,
|
||||
draftRestoreIsComplete: true
|
||||
)
|
||||
)
|
||||
}
|
||||
#expect(
|
||||
!DailyUXCreationContext.shouldAdoptAutomaticProject(
|
||||
currentProjectID: "fallback",
|
||||
nextRecentProjectID: "recent",
|
||||
isAwaitingRecentActivity: true,
|
||||
projectSelectionIsExplicit: false,
|
||||
modelSelectionIsExplicit: false,
|
||||
workspaceSelectionIsExplicit: false,
|
||||
hasDraftContent: false,
|
||||
draftRestoreIsComplete: false
|
||||
)
|
||||
)
|
||||
#expect(
|
||||
!DailyUXCreationContext.shouldAdoptAutomaticProject(
|
||||
currentProjectID: "fallback",
|
||||
nextRecentProjectID: "recent",
|
||||
isAwaitingRecentActivity: true,
|
||||
projectSelectionIsExplicit: false,
|
||||
modelSelectionIsExplicit: false,
|
||||
workspaceSelectionIsExplicit: false,
|
||||
hasDraftContent: true,
|
||||
draftRestoreIsComplete: true
|
||||
)
|
||||
)
|
||||
#expect(
|
||||
!DailyUXCreationContext.shouldAdoptAutomaticProject(
|
||||
currentProjectID: "fallback",
|
||||
nextRecentProjectID: "fallback",
|
||||
isAwaitingRecentActivity: true,
|
||||
projectSelectionIsExplicit: false,
|
||||
modelSelectionIsExplicit: false,
|
||||
workspaceSelectionIsExplicit: false,
|
||||
hasDraftContent: false,
|
||||
draftRestoreIsComplete: true
|
||||
)
|
||||
)
|
||||
#expect(
|
||||
!DailyUXCreationContext.shouldAdoptAutomaticProject(
|
||||
currentProjectID: "fallback",
|
||||
nextRecentProjectID: nil,
|
||||
isAwaitingRecentActivity: true,
|
||||
projectSelectionIsExplicit: false,
|
||||
modelSelectionIsExplicit: false,
|
||||
workspaceSelectionIsExplicit: false,
|
||||
hasDraftContent: false,
|
||||
draftRestoreIsComplete: true
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
func requestNormalizesLegacyModesAndKeepsImageBytes() {
|
||||
let image = FeatureDraftAttachment(
|
||||
@@ -398,6 +700,21 @@ struct DailyUXNewTaskTests {
|
||||
|
||||
#expect(group.projects.map(\.id) == ["remote", "current"])
|
||||
#expect(group.memberProjectIDs == ["stale", "current", "remote"])
|
||||
|
||||
let snapshot = rankedSnapshot(
|
||||
projects: [stale, current, remote],
|
||||
threads: [rankedThread("recent", projectID: stale.id, activity: 20)]
|
||||
)
|
||||
#expect(
|
||||
DailyUXCreationContext.recentProjects(in: snapshot).first?.project.id
|
||||
== current.id
|
||||
)
|
||||
#expect(
|
||||
DailyUXCreationContext.initialProject(
|
||||
in: snapshot,
|
||||
requestedProjectID: stale.id
|
||||
)?.id == current.id
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -521,4 +838,52 @@ struct DailyUXNewTaskTests {
|
||||
#expect(max(thumbnail.size.width, thumbnail.size.height) <= 160)
|
||||
#expect(attachment.mimeType == "image/jpeg")
|
||||
}
|
||||
|
||||
private func rankedProject(
|
||||
_ id: String,
|
||||
name: String,
|
||||
environmentID: String = "environment",
|
||||
repositoryKey: String? = nil
|
||||
) -> FeatureProject {
|
||||
FeatureProject(
|
||||
id: id,
|
||||
environmentID: environmentID,
|
||||
name: name,
|
||||
path: "/\(id)",
|
||||
repositoryIdentity: repositoryKey.map {
|
||||
FeatureRepositoryIdentity(canonicalKey: $0)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private func rankedThread(
|
||||
_ id: String,
|
||||
projectID: String,
|
||||
environmentID: String? = nil,
|
||||
activity: TimeInterval? = nil,
|
||||
updatedAt: TimeInterval? = nil,
|
||||
lastActivityAt: TimeInterval? = nil,
|
||||
isArchived: Bool = false,
|
||||
isSettled: Bool = false
|
||||
) -> FeatureThread {
|
||||
let updatedAt = updatedAt ?? activity ?? 0
|
||||
return FeatureThread(
|
||||
id: id,
|
||||
projectID: projectID,
|
||||
environmentID: environmentID,
|
||||
title: id,
|
||||
updatedAt: Date(timeIntervalSince1970: updatedAt),
|
||||
isArchived: isArchived,
|
||||
isSettled: isSettled,
|
||||
lastActivityAt: lastActivityAt.map(Date.init(timeIntervalSince1970:))
|
||||
)
|
||||
}
|
||||
|
||||
private func rankedSnapshot(
|
||||
environments: [FeatureEnvironment] = [],
|
||||
projects: [FeatureProject],
|
||||
threads: [FeatureThread]
|
||||
) -> FeatureSnapshot {
|
||||
FeatureSnapshot(environments: environments, projects: projects, threads: threads)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user