Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions packages/core/src/settings/updateStatus.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,41 @@ describe("deriveUpdateStatus", () => {
});
});

it("reports an available update with a version", () => {
expect(
deriveUpdateStatus({
checking: false,
available: true,
availableVersion: "1.2.3",
}),
).toEqual({
message: "Update 1.2.3 available",
type: "success",
checking: false,
});
});

it("reports an available update without a version", () => {
expect(deriveUpdateStatus({ checking: false, available: true })).toEqual({
message: "Update available",
type: "success",
checking: false,
});
});

it("reports a check error", () => {
expect(
deriveUpdateStatus({
checking: false,
error: "Update check timed out. Please try again.",
}),
).toEqual({
message: "Update check timed out. Please try again.",
type: "error",
checking: false,
});
});

it("clears checking when finished with no other signal", () => {
expect(deriveUpdateStatus({ checking: false })).toEqual({
checking: false,
Expand Down
15 changes: 15 additions & 0 deletions packages/core/src/settings/updateStatus.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
export interface RawUpdateStatus {
checking?: boolean;
downloading?: boolean;
available?: boolean;
upToDate?: boolean;
updateReady?: boolean;
version?: string;
availableVersion?: string;
error?: string;
}

export interface DerivedUpdateStatus {
Expand Down Expand Up @@ -34,6 +37,18 @@ export function deriveUpdateStatus(
checking: false,
};
}
if (status.checking === false && status.available) {
return {
message: status.availableVersion
? `Update ${status.availableVersion} available`
: "Update available",
type: "success",
checking: false,
};
}
if (status.checking === false && status.error) {
return { message: status.error, type: "error", checking: false };
}
if (status.checking === false) {
return { checking: false };
}
Expand Down
Loading