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
25 changes: 23 additions & 2 deletions src/_test/stub.helper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
/* global cy */
import { buildsService, projectsService, testRunService } from "../services";
import {
buildsService,
projectsService,
testRunService,
staticService,
testVariationService,
} from "../services";
import { Build, Project, TestRun } from "../types";

const projectStub = {
Expand All @@ -24,4 +30,19 @@ const testRunServiceStub = {
cy.stub(testRunService, "getList").resolves(testRuns),
};

export { projectStub, buildsServiceStub, testRunServiceStub };
const staticServiceStub = {
getImage: () => cy.stub(staticService, "getImage"),
};

const testVariationServiceStub = {
getDetails: () => cy.stub(testVariationService, "getDetails"),
getList: () => cy.stub(testVariationService, "getList"),
};

export {
projectStub,
buildsServiceStub,
testRunServiceStub,
staticServiceStub,
testVariationServiceStub,
};
218 changes: 215 additions & 3 deletions src/_test/test.data.helper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Project, TestRun, User } from "../types";
import { Build, Project, TestRun, TestVariation, User } from "../types";
import { BuildStatus } from "../types/buildStatus";
import { TestStatus } from "../types/testStatus";

export const projectMock: Project = {
export const TEST_PROJECT: Project = {
id: "someProjectId",
name: "Project name",
mainBranchName: "Main branch name",
Expand All @@ -10,7 +11,7 @@ export const projectMock: Project = {
createdAt: "2020-09-14T06:57:25.845Z",
};

export const userMock: User = {
export const TEST_USER: User = {
id: "1",
token: 123567,
apiKey: "SOME KEY SECRET",
Expand Down Expand Up @@ -41,3 +42,214 @@ export const testRunMock: TestRun = {
baselineBranchName: "baselineBranchName",
merge: false,
};

export const TEST_VARIATION_ONE: TestVariation = {
id: "testVariationId",
name: "test run name",
baselineName: "baselineName.png",
os: "OS",
browser: "browser",
viewport: "viewport",
device: "device",
ignoreAreas: "[]",
comment: "some comment",
branchName: "branch name",
projectId: TEST_PROJECT.id,
baselines: [
{
id: "some baseline id1",
baselineName: "baseline1.png",
testRunId: "testRunId1",
testVariationId: "some test variation id",
createdAt: "2020-09-14T06:57:25.845Z",
updatedAt: "2020-09-14T06:57:25.845Z",
testRun: testRunMock,
},
{
id: "some baseline id2",
baselineName: "baseline2.png",
testRunId: "testRunId2",
testVariationId: "some test variation id",
createdAt: "2020-09-12T06:57:25.845Z",
updatedAt: "2020-09-12T06:57:25.845Z",
testRun: testRunMock,
},
],
};

export const TEST_VARIATION_TWO: TestVariation = {
id: "some test variation id2",
name: "test run name2",
baselineName: "baseline2.png",
os: "OS",
browser: "browser",
viewport: "viewport",
device: "device",
ignoreAreas: "[]",
comment: "some comment",
branchName: "branch name",
projectId: TEST_PROJECT.id,
baselines: [
{
id: "some baseline id1",
baselineName: "baseline1.png",
testRunId: "testRunId1",
testVariationId: "some test variation id",
createdAt: "2020-09-14T06:57:25.845Z",
updatedAt: "2020-09-14T06:57:25.845Z",
testRun: testRunMock,
},
{
id: "some baseline id2",
baselineName: "baseline2.png",
testRunId: "testRunId2",
testVariationId: "some test variation id",
createdAt: "2020-09-12T06:57:25.845Z",
updatedAt: "2020-09-12T06:57:25.845Z",
testRun: testRunMock,
},
],
};

export const TEST_BUILD_FAILED: Build = {
id: "someId",
number: 1,
ciBuildId: "some build id",
projectName: "Project name",
branchName: "Branch name",
status: BuildStatus.failed,
createdAt: "2020-09-14T06:57:25.845Z",
createdBy: "2020-09-14T06:57:25.845Z",
testRuns: [],
unresolvedCount: 0,
passedCount: 2,
failedCount: 1,
isRunning: false,
merge: false,
};

export const TEST_BUILD_PASSED: Build = {
id: "someId2",
number: 2,
ciBuildId: "",
projectName: "Project name",
branchName: "Branch name",
status: BuildStatus.passed,
createdAt: "2020-09-14T06:57:25.845Z",
createdBy: "2020-09-14T06:57:25.845Z",
testRuns: [],
unresolvedCount: 0,
passedCount: 2,
failedCount: 0,
isRunning: false,
merge: false,
};

export const TEST_BUILD_UNRESOLVED: Build = {
id: "someId3",
number: 3,
ciBuildId: "",
projectName: "Project name",
branchName: "Branch name",
status: BuildStatus.unresolved,
createdAt: "2020-09-14T06:57:25.845Z",
createdBy: "2020-09-14T06:57:25.845Z",
testRuns: [],
unresolvedCount: 2,
passedCount: 0,
failedCount: 0,
isRunning: false,
merge: true,
};

export const TEST_UNRESOLVED: TestRun = {
id: "some test run id",
buildId: "some build id",
imageName: "image.png",
diffName: "diff.png",
baselineName: "baseline.png",
diffPercent: 1.24,
diffTollerancePercent: 3.21,
status: TestStatus.unresolved,
testVariationId: "some test variation id",
name: "test run name",
os: "OS",
browser: "browser",
viewport: "viewport",
device: "device",
ignoreAreas: `[{"id":"1606901916571","x":232,"y":123,"width":166,"height":138}]`,
tempIgnoreAreas: `[{"x":100,"y":300,"width":600,"height":700}]`,
comment: "some comment",
branchName: "branch name",
baselineBranchName: "baselineBranchName",
merge: false,
};

export const TEST_RUN_APPROVED: TestRun = {
id: "some test run id2",
buildId: "some build id",
imageName: "imageName",
diffName: "diffName",
diffPercent: 1.24,
diffTollerancePercent: 3.21,
status: TestStatus.approved,
testVariationId: "some test variation id",
name: "test run name2",
baselineName: "baselineName",
os: "OS",
browser: "browser",
viewport: "viewport",
device: "device",
ignoreAreas: "[]",
tempIgnoreAreas: "[]",
comment: "some comment",
branchName: "branch name",
baselineBranchName: "baselineBranchName",
merge: false,
};

export const TEST_RUN_NEW: TestRun = {
id: "some test run id3",
buildId: "some build id",
imageName: "imageName",
diffName: "diffName",
diffPercent: 1.24,
diffTollerancePercent: 3.21,
status: TestStatus.new,
testVariationId: "some test variation id",
name: "test run name3",
baselineName: "baselineName",
os: "",
browser: "",
viewport: "",
device: "",
ignoreAreas: "[]",
tempIgnoreAreas: "[]",
comment: "some comment",
branchName: "branch name",
baselineBranchName: "baselineBranchName",
merge: false,
};

export const TEST_RUN_OK: TestRun = {
id: "some test run id4",
buildId: "some build id",
imageName: "imageName",
diffName: "diffName",
diffPercent: 1.24,
diffTollerancePercent: 3.21,
status: TestStatus.ok,
testVariationId: "some test variation id",
name: "test run name4",
baselineName: "baselineName",
os: "",
browser: "",
viewport: "",
device: "",
ignoreAreas: "[]",
tempIgnoreAreas: "[]",
comment: "some comment",
branchName: "branch name",
baselineBranchName: "baselineBranchName",
merge: false,
};
4 changes: 2 additions & 2 deletions src/components/Header.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Header from "./Header";
import { AuthProvider } from "../contexts";
import { BrowserRouter } from "react-router-dom";
import { haveUserLogged } from "../_test/precondition.helper";
import { userMock } from "../_test/test.data.helper";
import { TEST_USER } from "../_test/test.data.helper";

describe("Header", () => {
describe("image", () => {
Expand All @@ -23,7 +23,7 @@ describe("Header", () => {
});

it("Logged", () => {
haveUserLogged(userMock);
haveUserLogged(TEST_USER);
mount(
<BrowserRouter>
<AuthProvider>
Expand Down
4 changes: 0 additions & 4 deletions src/pages/LoginPage.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
import React from "react";
import LoginPage from "./LoginPage";
import { mountVrtComponent } from "../_test/test.moun.helper";
import { projectStub } from "../_test/stub.helper";

describe("Login page", () => {
before(() => {
projectStub.getAll([]);
});
it("image", () => {
mountVrtComponent({
component: <LoginPage />,
Expand Down
6 changes: 3 additions & 3 deletions src/pages/ProfilePage.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import {
haveUserLogged,
haveWindowsEnvSet,
} from "../_test/precondition.helper";
import { projectMock, userMock } from "../_test/test.data.helper";
import { TEST_PROJECT, TEST_USER } from "../_test/test.data.helper";
import { mountVrtComponent } from "../_test/test.moun.helper";
import { projectStub } from "../_test/stub.helper";

describe("Profile page", () => {
before(() => {
haveUserLogged(userMock);
haveUserLogged(TEST_USER);
haveWindowsEnvSet({
REACT_APP_API_URL: "http://localhost:4200",
});
projectStub.getAll([projectMock]);
projectStub.getAll([TEST_PROJECT]);
});

it("image", () => {
Expand Down
20 changes: 4 additions & 16 deletions src/pages/ProjectListPage.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
/* global cy */
import React from "react";
import ProjectListPage from "./ProjectListPage";
import { projectsService } from "../services";
import { haveUserLogged } from "../_test/precondition.helper";
import { userMock } from "../_test/test.data.helper";
import { TEST_PROJECT, TEST_USER } from "../_test/test.data.helper";
import { mountVrtComponent } from "../_test/test.moun.helper";
import { projectStub } from "../_test/stub.helper";

describe("Project List page", () => {
before(() => {
haveUserLogged(userMock);
});

it("image", () => {
cy.stub(projectsService, "getAll").resolves([
{
id: "some id",
name: "Project name",
mainBranchName: "Main branch name",
builds: [],
updatedAt: "2020-09-14T06:57:25.845Z",
createdAt: "2020-09-14T06:57:25.845Z",
},
]);
haveUserLogged(TEST_USER);
projectStub.getAll([TEST_PROJECT]);

mountVrtComponent({
component: <ProjectListPage />,
Expand Down
Loading