Skip to content

Commit

Permalink
test(e2e): write some tests for dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasRichel committed May 11, 2021
1 parent 76eebcc commit b0574f4
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 29 deletions.
2 changes: 1 addition & 1 deletion cypress.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"pluginsFile": "tests/e2e/plugins/index.js",
"baseUrl": "http://localhost:3030",
"chromeWebSecurity": true
"chromeWebSecurity": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
justify-content: flex-start;
}

.lang-btn {
.btn-lang {
.lang-badge {
margin-left: $spacing-unit/2;
padding: $spacing-unit/4 $spacing-unit/2;
Expand All @@ -59,7 +59,7 @@
}
}

.logout-btn {
.btn-logout {
margin: $spacing-unit/2 $spacing-unit;
justify-content: center;
}
Expand Down
7 changes: 4 additions & 3 deletions src/components/specific/app/app-header-menu/AppHeaderMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<span class="app-header-menu__btn__picture">
{{ initials }}
</span>
<span class="app-header-menu__btn__fullname">
<span data-test="user-name" class="app-header-menu__btn__fullname">
{{ `${firstName} ${lastName}` }}
</span>
<span class="app-header-menu__btn__email">
Expand All @@ -31,7 +31,7 @@
</BIMDataButton>
<div class="separator"></div>
<BIMDataButton
class="lang-btn"
class="btn-lang"
ghost
squared
@click="openLanguageSelector"
Expand All @@ -40,7 +40,8 @@
<span class="lang-badge">{{ $i18n.locale }}</span>
</BIMDataButton>
<BIMDataButton
class="logout-btn"
data-test="btn-logout"
class="btn-logout"
color="primary"
fill
radius
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/fixtures/projects/100/models.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"source": "UPLOAD",
"status": "C",
"version": "IFC2X3",
"viewer_360_file": "https://api-staging.bimdata.io/model-preview/1001",
"viewer_360_file": "https://file-storage/model-preview/1001",
"document": {
"id": 1001,
"name": "MyModel.ifc",
Expand All @@ -31,7 +31,7 @@
"source": "UPLOAD",
"status": "C",
"version": "IFC2X3",
"viewer_360_file": "https://api-staging.bimdata.io/model-preview/1002",
"viewer_360_file": "https://file-storage/model-preview/1002",
"document": {
"id": 1002,
"name": "AnotherModel-1234.ifc",
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/fixtures/spaces.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "My First Space",
"created_at": "2021-04-01T09:00:00Z",
"updated_at": "2021-04-10T09:00:00Z",
"image": null
"image": "https://file-storage/space-image/100"
},
{
"id": 200,
Expand Down
38 changes: 38 additions & 0 deletions tests/e2e/specs/auth_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
describe("Auth Scenarios", () => {

beforeEach(() => {
cy.setupMocks();
cy.logout();
});

it("Should land on login page when logged out", () => {
cy.visit("/");
cy.url().should("contain", Cypress.env("LOGIN_BASE_URL"));
});

it("Should land on home page when logged in", () => {
cy.login();
cy.visit("/");
cy.wait(["@user", "@spaces", "@projects"]);

cy.url().should("contain", Cypress.config("baseUrl"));
cy.getHook("user-name").should("contain", "Toto LABRICO");
});

/**
* This test currently fails because Cypress does not allow to visit
* more than one super domain in the same test (which is probably a good thing though).
* Needs refactoring.
*/
// it("Should be able to log out properly", () => {
// cy.login();
// cy.visit("/");
// cy.wait(["@user", "@spaces", "@projects"]);

// cy.getHook("user-name").click();
// cy.getHook("btn-logout").click();

// cy.url().should("contain", Cypress.env("LOGIN_BASE_URL"));
// });

});
15 changes: 0 additions & 15 deletions tests/e2e/specs/basic_spec.js

This file was deleted.

28 changes: 28 additions & 0 deletions tests/e2e/specs/dashboard_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
describe("Dashboard Scenarios", () => {

beforeEach(() => {
cy.setupMocks();
cy.login();
cy.visit("/");
cy.wait(["@user", "@spaces", "@projects"]);
});

it("Should be able to access user spaces", () => {
cy.getHook("dashboard.btn-spaces").click();
cy.location("pathname").should("eq", "/spaces");
});

it("Should be able to access user projects", () => {
cy.getHook("dashboard.btn-projects").click();
cy.location("pathname").should("eq", "/projects");
});

it("Should be able to access a specific space", () => {
// TODO
});

it("Should be able to access a specific project", () => {
// TODO
});

});
23 changes: 18 additions & 5 deletions tests/e2e/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
// https://docs.cypress.io/api/cypress-api/custom-commands
// ***********************************************

Cypress.Commands.add("getHook", names => {
const selector = names.split(".").map(name => `[data-test=${name}]`).join(" ");
return cy.get(selector);
});

Cypress.Commands.add("login", () => {
const key = `oidc.user:${Cypress.env("IAM_BASE_URL")}/auth/realms/bimdata:${Cypress.env("OIDC_CLIENT_ID")}`;
const user = {};
Expand All @@ -21,8 +26,12 @@ Cypress.Commands.add("apiMock", ({ name, method = "GET", path, data }) => {
}
});

Cypress.Commands.add("setupApiMocks", () => {
const mocks = [
Cypress.Commands.add("fileMock", ({ path, data }) => {
cy.intercept("GET", `https://file-storage${path}`, { fixture: data });
});

Cypress.Commands.add("setupMocks", () => {
const apiMocks = [
{ name: "user", path: "/user", data: "user.json" },
{ name: "spaces", path: "/cloud", data: "spaces.json" },
{ name: "projects", path: "/user/projects", data: "projects.json" },
Expand All @@ -44,10 +53,14 @@ Cypress.Commands.add("setupApiMocks", () => {
{ name: "project-300-users", path: "/cloud/300/project/300/user", data: "projects/300/users.json" },
{ name: "project-300-invitations", path: "/cloud/300/project/300/invitation", data: "projects/300/invitations.json" },
{ name: "project-300-models", path: "/cloud/300/project/300/ifc", data: "projects/300/models.json" },
{ name: "model-1001-preview", path: "/model-preview/1001", data: "models/1001/preview.png" },
{ name: "model-1001-site", path: "/cloud/100/project/100/ifc/1001/element?type=IfcSite", data: "models/1001/ifc-site.json" },
{ name: "model-1002-preview", path: "/model-preview/1002", data: "models/1002/preview.png" },
{ name: "model-1002-site", path: "/cloud/100/project/100/ifc/1002/element?type=IfcSite", data: "models/1002/ifc-site.json" }
];
mocks.forEach(cy.apiMock);
const fileMocks = [
{ path: "/space-image/100", data: "spaces/100/image.jpg" },
{ path: "/model-preview/1001", data: "models/1001/preview.png" },
{ path: "/model-preview/1002", data: "models/1002/preview.png" }
];
apiMocks.forEach(cy.apiMock);
fileMocks.forEach(cy.fileMock);
});

0 comments on commit b0574f4

Please sign in to comment.