Skip to content

Commit

Permalink
test: errors in build and build history (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 authored and Neal committed Nov 13, 2019
1 parent 3ea0ea9 commit 767998f
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 5 deletions.
86 changes: 84 additions & 2 deletions cypress/integration/build.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,68 @@
context("org/repo/build View Build Page", () => {
context("logged in and server returning single build", () => {
context("logged in and server returning build error", () => {
beforeEach(() => {
cy.server();
cy.stubBuildErrors();
cy.stubBuildsErrors();
cy.stubStepsErrors();
cy.login("/someorg/somerepo/1");
});
it("error alert should show", () => {
cy.get("[data-test=alerts]")
.should("exist")
.contains("Error");
});
});
context("logged in and server returning 5 builds", () => {
beforeEach(() => {
cy.server();
cy.fixture("builds_5.json").as("builds5");
cy.route({
method: "GET",
url: "api/v1/repos/*/*/builds?page=1&per_page=100",
response: "@builds5"
});
cy.login("/someorg/somerepo/1");
cy.get("[data-test=build-history]").as("buildHistory");
});

it("build history should show", () => {
cy.get("@buildHistory").should("be.visible");
});

it("build history should have 5 builds", () => {
cy.get("@buildHistory").should("be.visible");
cy.get("@buildHistory")
.children()
.should("have.length", 5);
});

it("clicking build history item should redirect to build page", () => {
cy.get("@buildHistory")
.children()
.last()
.click();
cy.location("pathname").should("eq", "/someorg/somerepo/105");
});
});

context("logged in and server returning 0 builds", () => {
beforeEach(() => {
cy.server();
cy.route({
method: "GET",
url: "api/v1/repos/*/*/builds?page=1&per_page=100",
response: []
});
cy.login("/someorg/somerepo/1");
});

it("build history should not show", () => {
cy.get("[data-test=build-history]").should("not.exist");
});
});

context("logged in and server returning builds and single build", () => {
beforeEach(() => {
cy.server();
cy.stubBuild();
Expand Down Expand Up @@ -66,7 +129,7 @@ context("org/repo/build View Build Page", () => {
cy.get("[data-test=restart-build]").as("restartBuild");
});

it("clicking Restart Build should show alert", () => {
it("clicking restart build should show alert", () => {
cy.get("@restartBuild").click();
cy.get("[data-test=alert]").should(
"contain",
Expand All @@ -81,6 +144,25 @@ context("org/repo/build View Build Page", () => {
});
});

context("server failing to restart build", () => {
beforeEach(() => {
cy.server();
cy.fixture("build_pending.json").as("restartedBuild");
cy.route({
method: "POST",
url: "api/v1/repos/*/*/builds/*",
status: 500,
response: "server error"
});
cy.get("[data-test=restart-build]").as("restartBuild");
});

it("clicking restart build should show error alert", () => {
cy.get("@restartBuild").click();
cy.get("[data-test=alert]").should("contain", "Error");
});
});

context("visit running build", () => {
beforeEach(() => {
cy.visit("/someorg/somerepo/1");
Expand Down
31 changes: 31 additions & 0 deletions cypress/integration/builds.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,35 @@ context("org/repo View Repository Builds Page", () => {
cy.location("pathname").should("eq", "/someorg/somerepo/1");
});
});

context("logged in and server returning builds error", () => {
beforeEach(() => {
cy.server();
cy.stubBuildsErrors();
cy.login("/someorg/somerepo");
});

it("error alert should show", () => {
cy.get("[data-test=alerts]")
.should("exist")
.contains("Error");
});
});

context("logged out and server returning 55 builds", () => {
beforeEach(() => {
cy.clearSession();
cy.server();
cy.stubBuilds();
cy.visit("/someorg/somerepo");
});

it("error alert should not show", () => {
cy.get("[data-test=alerts]").should("be.not.visible");
});

it("builds should redirect to login", () => {
cy.location("pathname").should("eq", "/account/login");
});
});
});
35 changes: 35 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ Cypress.Commands.add("login", (path = "/", fixture = "sessionstorage") => {
});
});

// Clear session storage helper
Cypress.Commands.add("clearSession", () => {
cy.window().then(win => {
win.sessionStorage.clear();
});
});

// Route stubbing helpers
Cypress.Commands.add("stubBuild", () => {
cy.server();
Expand Down Expand Up @@ -95,3 +102,31 @@ Cypress.Commands.add("stubStepsWithLogs", () => {
}
});
});

Cypress.Commands.add("stubBuildsErrors", () => {
cy.route({
method: "GET",
url: "*api/v1/repos/*/*/builds*",
status: 500,
response: "server error"
});
});


Cypress.Commands.add("stubBuildErrors", () => {
cy.route({
method: "GET",
url: "*api/v1/repos/*/*/builds/*",
status: 500,
response: "server error"
});
});

Cypress.Commands.add("stubStepsErrors", () => {
cy.route({
method: "GET",
url: "*api/v1/repos/*/*/builds/*/steps*",
status: 500,
response: "server error"
});
});
10 changes: 7 additions & 3 deletions src/elm/Build.elm
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,13 @@ viewBuildHistory now timezone page org repo builds =
if show then
case builds of
RemoteData.Success blds ->
div [ class "build-history", Util.testAttribute "build-history" ] <|
List.indexedMap (\idx -> \build -> recentBuild now timezone org repo build idx) <|
List.take 10 blds
if List.length blds > 0 then
div [ class "build-history", Util.testAttribute "build-history" ] <|
List.indexedMap (\idx -> \build -> recentBuild now timezone org repo build idx) <|
List.take 10 blds

else
text ""

RemoteData.Loading ->
div [ class "build-history" ] [ smallLoader ]
Expand Down

0 comments on commit 767998f

Please sign in to comment.