|
1 | 1 | package io.visual_regression_tracker.sdk_java; |
2 | 2 |
|
3 | | -import java.io.IOException; |
4 | | -import java.util.Objects; |
5 | | - |
6 | 3 | import com.google.gson.Gson; |
7 | 4 | import io.visual_regression_tracker.sdk_java.request.BuildRequest; |
8 | 5 | import io.visual_regression_tracker.sdk_java.request.TestRunRequest; |
|
24 | 21 | import org.testng.annotations.DataProvider; |
25 | 22 | import org.testng.annotations.Test; |
26 | 23 |
|
| 24 | +import java.io.IOException; |
| 25 | +import java.util.Objects; |
| 26 | + |
27 | 27 | import static org.hamcrest.CoreMatchers.containsString; |
28 | 28 | import static org.hamcrest.CoreMatchers.is; |
29 | 29 | import static org.hamcrest.MatcherAssert.assertThat; |
30 | 30 | import static org.mockito.ArgumentMatchers.any; |
31 | 31 | import static org.mockito.ArgumentMatchers.anyString; |
32 | | -import static org.mockito.Mockito.doCallRealMethod; |
33 | | -import static org.mockito.Mockito.mock; |
34 | | -import static org.mockito.Mockito.reset; |
35 | | -import static org.mockito.Mockito.verify; |
36 | | -import static org.mockito.Mockito.when; |
| 32 | +import static org.mockito.Mockito.*; |
37 | 33 |
|
38 | 34 | public class VisualRegressionTrackerTest { |
39 | 35 |
|
@@ -67,6 +63,7 @@ public void setup() { |
67 | 63 | this.config.setApiUrl(server.url("/").toString()); |
68 | 64 | vrt = new VisualRegressionTracker(config); |
69 | 65 | vrtMocked = mock(VisualRegressionTracker.class); |
| 66 | + vrtMocked.paths = new PathProvider("baseApiUrl"); |
70 | 67 | } |
71 | 68 |
|
72 | 69 | @SneakyThrows |
@@ -175,13 +172,19 @@ public Object[][] trackErrorCases() { |
175 | 172 | { |
176 | 173 | TestRunResponse.builder() |
177 | 174 | .url("https://someurl.com/test/123123") |
| 175 | + .imageName("imageName") |
| 176 | + .baselineName("baselineName") |
| 177 | + .diffName("diffName") |
178 | 178 | .status(TestRunStatus.UNRESOLVED) |
179 | 179 | .build(), |
180 | 180 | "Difference found: https://someurl.com/test/123123" |
181 | 181 | }, |
182 | 182 | { |
183 | 183 | TestRunResponse.builder() |
184 | 184 | .url("https://someurl.com/test/123123") |
| 185 | + .imageName("imageName") |
| 186 | + .baselineName("baselineName") |
| 187 | + .diffName("diffName") |
185 | 188 | .status(TestRunStatus.NEW) |
186 | 189 | .build(), |
187 | 190 | "No baseline: https://someurl.com/test/123123" |
@@ -214,22 +217,37 @@ public void trackShouldLogSevere(TestRunResponse testRunResponse, String expecte |
214 | 217 |
|
215 | 218 | @DataProvider(name = "shouldTrackPassCases") |
216 | 219 | public Object[][] shouldTrackPassCases() { |
217 | | - return new Object[][] { |
218 | | - { |
219 | | - TestRunResponse.builder() |
220 | | - .url("https://someurl.com/test/123123") |
221 | | - .status(TestRunStatus.OK) |
222 | | - .build(), |
223 | | - } |
| 220 | + return new Object[][] { |
| 221 | + { |
| 222 | + TestRunResponse.builder() |
| 223 | + .id("someId") |
| 224 | + .imageName("imageName") |
| 225 | + .baselineName("baselineName") |
| 226 | + .diffName("diffName") |
| 227 | + .diffPercent(12.32f) |
| 228 | + .diffTollerancePercent(0.01f) |
| 229 | + .pixelMisMatchCount(1) |
| 230 | + .merge(false) |
| 231 | + .url("https://someurl.com/test/123123") |
| 232 | + .status(TestRunStatus.OK) |
| 233 | + .build(), |
| 234 | + } |
224 | 235 | }; |
225 | 236 | } |
226 | 237 |
|
227 | 238 | @Test(dataProvider = "shouldTrackPassCases") |
228 | 239 | public void shouldTrackPass(TestRunResponse testRunResponse) throws IOException { |
229 | 240 | when(vrtMocked.submitTestRun(anyString(), anyString(), any())).thenReturn(testRunResponse); |
| 241 | + vrtMocked.paths = new PathProvider("backendUrl"); |
230 | 242 |
|
231 | 243 | doCallRealMethod().when(vrtMocked).track(anyString(), anyString(), any()); |
232 | | - vrtMocked.track("name", "image", TestRunOptions.builder().build()); |
| 244 | + TestRunResult testRunResult = vrtMocked.track("name", "image", TestRunOptions.builder().build()); |
| 245 | + |
| 246 | + assertThat(testRunResult.getTestRunResponse(), is(testRunResponse)); |
| 247 | + assertThat(testRunResult.getUrl(), is(testRunResponse.getUrl())); |
| 248 | + assertThat(testRunResult.getImageUrl(), is("backendUrl/".concat(testRunResponse.getImageName()))); |
| 249 | + assertThat(testRunResult.getDiffUrl(), is("backendUrl/".concat(testRunResponse.getDiffName()))); |
| 250 | + assertThat(testRunResult.getBaselineUrl(), is("backendUrl/".concat(testRunResponse.getBaselineName()))); |
233 | 251 | } |
234 | 252 |
|
235 | 253 | @Test() |
|
0 commit comments