|
1 | | -import { Target, TargetLabel } from "@app/api/models"; |
| 1 | +import { Application, Target, TargetLabel } from "@app/api/models"; |
2 | 2 |
|
3 | | -import { updateSelectedTargetLabels } from "../utils"; |
| 3 | +import { isModeSupported, updateSelectedTargetLabels } from "../utils"; |
4 | 4 |
|
5 | 5 | const TARGET_LABELS: TargetLabel[] = [ |
6 | 6 | { |
@@ -56,6 +56,140 @@ const TARGET_B: Target = { |
56 | 56 | ], |
57 | 57 | }; |
58 | 58 |
|
| 59 | +describe("analysis-wizard utils - isModeSupported()", () => { |
| 60 | + it("should return true for binary-upload mode regardless of application state", () => { |
| 61 | + const application: Application = { |
| 62 | + id: 1, |
| 63 | + name: "Test App", |
| 64 | + migrationWave: null, |
| 65 | + }; |
| 66 | + expect(isModeSupported(application, "binary-upload")).toBe(true); |
| 67 | + }); |
| 68 | + |
| 69 | + it("should return true for binary mode when application has valid binary format", () => { |
| 70 | + const application: Application = { |
| 71 | + id: 1, |
| 72 | + name: "Test App", |
| 73 | + binary: "group:artifact:version", |
| 74 | + migrationWave: null, |
| 75 | + }; |
| 76 | + expect(isModeSupported(application, "binary")).toBe(true); |
| 77 | + }); |
| 78 | + |
| 79 | + it("should return false for binary mode when application binary is missing", () => { |
| 80 | + const application: Application = { |
| 81 | + id: 1, |
| 82 | + name: "Test App", |
| 83 | + migrationWave: null, |
| 84 | + }; |
| 85 | + expect(isModeSupported(application, "binary")).toBe(false); |
| 86 | + }); |
| 87 | + |
| 88 | + it("should return false for binary mode when application binary is empty", () => { |
| 89 | + const application: Application = { |
| 90 | + id: 1, |
| 91 | + name: "Test App", |
| 92 | + binary: "", |
| 93 | + migrationWave: null, |
| 94 | + }; |
| 95 | + expect(isModeSupported(application, "binary")).toBe(false); |
| 96 | + }); |
| 97 | + |
| 98 | + it("should return false for binary mode when application binary does not match pattern", () => { |
| 99 | + const application: Application = { |
| 100 | + id: 1, |
| 101 | + name: "Test App", |
| 102 | + binary: "invalid-format", |
| 103 | + migrationWave: null, |
| 104 | + }; |
| 105 | + expect(isModeSupported(application, "binary")).toBe(false); |
| 106 | + }); |
| 107 | + |
| 108 | + it("should return true for source-code-deps mode when repository URL exists", () => { |
| 109 | + const application: Application = { |
| 110 | + id: 1, |
| 111 | + name: "Test App", |
| 112 | + repository: { |
| 113 | + url: "https://github.com/user/repo.git", |
| 114 | + }, |
| 115 | + migrationWave: null, |
| 116 | + }; |
| 117 | + expect(isModeSupported(application, "source-code-deps")).toBe(true); |
| 118 | + }); |
| 119 | + |
| 120 | + it("should return false for source-code-deps mode when repository URL is missing", () => { |
| 121 | + const application: Application = { |
| 122 | + id: 1, |
| 123 | + name: "Test App", |
| 124 | + migrationWave: null, |
| 125 | + }; |
| 126 | + expect(isModeSupported(application, "source-code-deps")).toBe(false); |
| 127 | + }); |
| 128 | + |
| 129 | + it("should return false for source-code-deps mode when repository URL is empty", () => { |
| 130 | + const application: Application = { |
| 131 | + id: 1, |
| 132 | + name: "Test App", |
| 133 | + repository: { |
| 134 | + url: "", |
| 135 | + }, |
| 136 | + migrationWave: null, |
| 137 | + }; |
| 138 | + expect(isModeSupported(application, "source-code-deps")).toBe(false); |
| 139 | + }); |
| 140 | + |
| 141 | + it("should return true for source-code mode when repository URL exists", () => { |
| 142 | + const application: Application = { |
| 143 | + id: 1, |
| 144 | + name: "Test App", |
| 145 | + repository: { |
| 146 | + url: "https://github.com/user/repo.git", |
| 147 | + }, |
| 148 | + migrationWave: null, |
| 149 | + }; |
| 150 | + expect(isModeSupported(application, "source-code")).toBe(true); |
| 151 | + }); |
| 152 | + |
| 153 | + it("should return false for source-code mode when repository URL is missing", () => { |
| 154 | + const application: Application = { |
| 155 | + id: 1, |
| 156 | + name: "Test App", |
| 157 | + migrationWave: null, |
| 158 | + }; |
| 159 | + expect(isModeSupported(application, "source-code")).toBe(false); |
| 160 | + }); |
| 161 | + |
| 162 | + it("should return false for source-code mode when repository URL is empty", () => { |
| 163 | + const application: Application = { |
| 164 | + id: 1, |
| 165 | + name: "Test App", |
| 166 | + repository: { |
| 167 | + url: "", |
| 168 | + }, |
| 169 | + migrationWave: null, |
| 170 | + }; |
| 171 | + expect(isModeSupported(application, "source-code")).toBe(false); |
| 172 | + }); |
| 173 | + |
| 174 | + it("should return false for undefined mode", () => { |
| 175 | + const application: Application = { |
| 176 | + id: 1, |
| 177 | + name: "Test App", |
| 178 | + migrationWave: null, |
| 179 | + }; |
| 180 | + expect(isModeSupported(application, undefined)).toBe(false); |
| 181 | + }); |
| 182 | + |
| 183 | + it("should return false for unknown mode", () => { |
| 184 | + const application: Application = { |
| 185 | + id: 1, |
| 186 | + name: "Test App", |
| 187 | + migrationWave: null, |
| 188 | + }; |
| 189 | + expect(isModeSupported(application, "unknown-mode")).toBe(false); |
| 190 | + }); |
| 191 | +}); |
| 192 | + |
59 | 193 | describe("analysis-wizard utils - updateSelectedTargetLabels()", () => { |
60 | 194 | it("add a label to an empty list", () => { |
61 | 195 | const theResult = updateSelectedTargetLabels( |
|
0 commit comments