|
| 1 | +import dayjs from "dayjs" |
| 2 | +import utc from "dayjs/plugin/utc" |
| 3 | +import * as TypesGen from "../../api/typesGenerated" |
| 4 | +import * as Mocks from "../../testHelpers/entities" |
| 5 | +import { shouldDisplay } from "./WorkspaceScheduleBanner" |
| 6 | + |
| 7 | +dayjs.extend(utc) |
| 8 | + |
| 9 | +describe("WorkspaceScheduleBanner", () => { |
| 10 | + describe("shouldDisplay", () => { |
| 11 | + // Manual TTL case |
| 12 | + it("should not display if the build does not have a deadline", () => { |
| 13 | + // Given: a workspace with deadline of '"0001-01-01T00:00:00Z"' |
| 14 | + const workspace: TypesGen.Workspace = { |
| 15 | + ...Mocks.MockWorkspace, |
| 16 | + latest_build: { |
| 17 | + ...Mocks.MockWorkspaceBuild, |
| 18 | + deadline: "0001-01-01T00:00:00Z", |
| 19 | + transition: "start", |
| 20 | + }, |
| 21 | + } |
| 22 | + |
| 23 | + // Then: shouldDisplay is false |
| 24 | + expect(shouldDisplay(workspace)).toBeFalsy() |
| 25 | + }) |
| 26 | + |
| 27 | + // Transition Checks |
| 28 | + it("should not display if the latest build is not transition=start", () => { |
| 29 | + // Given: a workspace with latest build as "stop" |
| 30 | + const workspace: TypesGen.Workspace = { |
| 31 | + ...Mocks.MockWorkspace, |
| 32 | + latest_build: { |
| 33 | + ...Mocks.MockWorkspaceBuild, |
| 34 | + transition: "stop", |
| 35 | + }, |
| 36 | + } |
| 37 | + |
| 38 | + // Then: shouldDisplay is false |
| 39 | + expect(shouldDisplay(workspace)).toBeFalsy() |
| 40 | + }) |
| 41 | + |
| 42 | + // Provisioner Job Checks |
| 43 | + it("should not display if the latest build is canceling", () => { |
| 44 | + // Given: a workspace with latest build as "canceling" |
| 45 | + const workspace: TypesGen.Workspace = { |
| 46 | + ...Mocks.MockWorkspace, |
| 47 | + latest_build: { |
| 48 | + ...Mocks.MockWorkspaceBuild, |
| 49 | + job: Mocks.MockCancelingProvisionerJob, |
| 50 | + transition: "start", |
| 51 | + }, |
| 52 | + } |
| 53 | + |
| 54 | + // Then: shouldDisplay is false |
| 55 | + expect(shouldDisplay(workspace)).toBeFalsy() |
| 56 | + }) |
| 57 | + it("should not display if the latest build is canceled", () => { |
| 58 | + // Given: a workspace with latest build as "canceled" |
| 59 | + const workspace: TypesGen.Workspace = { |
| 60 | + ...Mocks.MockWorkspace, |
| 61 | + latest_build: { |
| 62 | + ...Mocks.MockWorkspaceBuild, |
| 63 | + job: Mocks.MockCanceledProvisionerJob, |
| 64 | + transition: "start", |
| 65 | + }, |
| 66 | + } |
| 67 | + |
| 68 | + // Then: shouldDisplay is false |
| 69 | + expect(shouldDisplay(workspace)).toBeFalsy() |
| 70 | + }) |
| 71 | + it("should not display if the latest build failed", () => { |
| 72 | + // Given: a workspace with latest build as "failed" |
| 73 | + const workspace: TypesGen.Workspace = { |
| 74 | + ...Mocks.MockWorkspace, |
| 75 | + latest_build: { |
| 76 | + ...Mocks.MockWorkspaceBuild, |
| 77 | + job: Mocks.MockFailedProvisionerJob, |
| 78 | + transition: "start", |
| 79 | + }, |
| 80 | + } |
| 81 | + |
| 82 | + // Then: shouldDisplay is false |
| 83 | + expect(shouldDisplay(workspace)).toBeFalsy() |
| 84 | + }) |
| 85 | + |
| 86 | + // Deadline Checks |
| 87 | + it("should display if deadline is within 30 minutes", () => { |
| 88 | + // Given: a workspace with latest build as start and deadline in ~30 mins |
| 89 | + const workspace: TypesGen.Workspace = { |
| 90 | + ...Mocks.MockWorkspace, |
| 91 | + latest_build: { |
| 92 | + ...Mocks.MockWorkspaceBuild, |
| 93 | + deadline: dayjs().add(27, "minutes").utc().format(), |
| 94 | + job: Mocks.MockRunningProvisionerJob, |
| 95 | + transition: "start", |
| 96 | + }, |
| 97 | + } |
| 98 | + |
| 99 | + // Then: shouldDisplay is true |
| 100 | + expect(shouldDisplay(workspace)).toBeTruthy() |
| 101 | + }) |
| 102 | + it("should not display if deadline is 45 minutes", () => { |
| 103 | + // Given: a workspace with latest build as start and deadline in 45 mins |
| 104 | + const workspace: TypesGen.Workspace = { |
| 105 | + ...Mocks.MockWorkspace, |
| 106 | + latest_build: { |
| 107 | + ...Mocks.MockWorkspaceBuild, |
| 108 | + deadline: dayjs().add(45, "minutes").utc().format(), |
| 109 | + transition: "start", |
| 110 | + }, |
| 111 | + } |
| 112 | + |
| 113 | + // Then: shouldDisplay is false |
| 114 | + expect(shouldDisplay(workspace)).toBeFalsy() |
| 115 | + }) |
| 116 | + }) |
| 117 | +}) |
0 commit comments