Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test for DataTable Prime components #884

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
110 changes: 110 additions & 0 deletions webapp/cypress/component/CollectionTableTest.cy.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import CollectionTable from "@/components/CollectionTable.vue";
import PrimeVue from "primevue/config";
import { createStore } from "vuex";

describe("CollectionTable Component Tests", () => {
let store;

beforeEach(() => {
store = createStore({
state() {
return {
collection_list: [
{
collection_id: "collection1",
type: "collections",
title: "Collection One",
creators: [{ display_name: "Creator A" }],
},
{
collection_id: "collection2",
type: "collections",
title: "Collection Two",
creators: [{ display_name: "Creator B" }, { display_name: "Creator C" }],
},
],
};
},
});

cy.mount(CollectionTable, {
global: {
plugins: [store, PrimeVue],
},
});
});

it("renders the correct buttons", () => {
cy.get('[data-testid="add-item-button"]').should("not.exist");
cy.get('[data-testid="batch-item-button"]').should("not.exist");
cy.get('[data-testid="scan-qr-button"]').should("not.exist");
cy.get('[data-testid="add-collection-button"]').should("exist");
cy.get('[data-testid="add-starting-material-button"]').should("not.exist");
cy.get('[data-testid="add-equipment-button"]').should("not.exist");
cy.get('[data-testid="add-to-collection-button"]').should("not.exist");
cy.get('[data-testid="delete-selected-button"]').should("not.exist");
cy.get('[data-testid="search-input"]').should("exist");
});

it("renders the correct columns in the table", () => {
const headers = [
"", //checkbox
"ID",
"Title",
"Creators",
];

cy.get(".p-datatable-column-header-content").should("have.length", headers.length);
cy.get(".p-datatable-column-header-content").each((header, index) => {
cy.wrap(header).should("contain.text", headers[index]);
});
});

it("displays data from the Vuex store", () => {
cy.get(".p-datatable-tbody")
.find("tr")
.eq(0)
.within(() => {
cy.get("td").eq(0).should("contain.text", "");
cy.get("td").eq(1).should("contain.text", "collection1");
cy.get("td").eq(2).should("contain.text", "Collection One");
cy.get("td").eq(3).find(".avatar").should("have.length", 1);
});

cy.get(".p-datatable-tbody")
.find("tr")
.eq(1)
.within(() => {
cy.get("td").eq(0).should("contain.text", "");
cy.get("td").eq(1).should("contain.text", "collection2");
cy.get("td").eq(2).should("contain.text", "Collection Two");
cy.get("td").eq(3).find(".avatar").should("have.length", 2);
});
});

it("renders the component FormattedCollectionName", () => {
cy.get(".p-datatable-tbody tr")
.eq(0)
.within(() => {
cy.get("td").eq(1).find(".formatted-collection-name").should("exist");
});
cy.get(".p-datatable-tbody tr")
.eq(1)
.within(() => {
cy.get("td").eq(1).find(".formatted-collection-name").should("exist");
});
});

it("renders the component Creators", () => {
cy.get(".p-datatable-tbody tr")
.eq(0)
.within(() => {
cy.get("td").eq(3).find(".avatar").should("exist");
});
cy.get(".p-datatable-tbody tr")
.eq(1)
.within(() => {
cy.get("td").eq(3).find(".avatar").should("exist");
});
});
});
133 changes: 133 additions & 0 deletions webapp/cypress/component/EquipmentTableTest.cy.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import EquipmentTable from "@/components/EquipmentTable.vue";
import PrimeVue from "primevue/config";
import { createStore } from "vuex";

const IsoDatetimeToDate = (value) => {
if (!value) return "";
const date = new Date(value);
return date.toLocaleDateString();
};

describe("EquipmentTable Component Tests", () => {
let store;

beforeEach(() => {
store = createStore({
state() {
return {
equipment_list: [
{
item_id: "equipment1",
type: "equipment",
name: "Equipment One",
date: "2023-09-01T12:34:56Z",
location: "Warehouse A",
creators: [{ display_name: "Maintainer A" }],
},
{
item_id: "equipment2",
type: "equipment",
name: "Equipment Two",
date: "2023-08-15T08:45:30Z",
location: "Warehouse B",
creators: [{ display_name: "Maintainer B" }, { display_name: "Maintainer C" }],
},
],
};
},
});

cy.mount(EquipmentTable, {
global: {
plugins: [store, PrimeVue],
config: {
globalProperties: {
$filters: {
IsoDatetimeToDate,
},
},
},
},
});
});

it("renders the correct buttons", () => {
cy.get('[data-testid="add-item-button"]').should("not.exist");
cy.get('[data-testid="batch-item-button"]').should("not.exist");
cy.get('[data-testid="scan-qr-button"]').should("not.exist");
cy.get('[data-testid="add-collection-button"]').should("not.exist");
cy.get('[data-testid="add-starting-material-button"]').should("not.exist");
cy.get('[data-testid="add-equipment-button"]').should("exist");
cy.get('[data-testid="add-to-collection-button"]').should("not.exist");
cy.get('[data-testid="delete-selected-button"]').should("not.exist");
cy.get('[data-testid="search-input"]').should("exist");
});

it("renders the correct columns in the table", () => {
const headers = [
"", // checkbox
"ID",
"Name",
"Date",
"Location",
"Maintainers",
];

cy.get(".p-datatable-column-header-content").should("have.length", headers.length);
cy.get(".p-datatable-column-header-content").each((header, index) => {
cy.wrap(header).should("contain.text", headers[index]);
});
});

it("displays data from the Vuex store", () => {
cy.get(".p-datatable-tbody")
.find("tr")
.eq(0)
.within(() => {
cy.get("td").eq(0).should("contain.text", "");
cy.get("td").eq(1).should("contain.text", "equipment1");
cy.get("td").eq(2).should("contain.text", "Equipment One");
cy.get("td").eq(3).should("contain.text", "01/09/2023");
cy.get("td").eq(4).should("contain.text", "Warehouse A");
cy.get("td").eq(5).find(".avatar").should("have.length", 1);
});

cy.get(".p-datatable-tbody")
.find("tr")
.eq(1)
.within(() => {
cy.get("td").eq(0).should("contain.text", "");
cy.get("td").eq(1).should("contain.text", "equipment2");
cy.get("td").eq(2).should("contain.text", "Equipment Two");
cy.get("td").eq(3).should("contain.text", "15/08/2023");
cy.get("td").eq(4).should("contain.text", "Warehouse B");
cy.get("td").eq(5).find(".avatar").should("have.length", 2);
});
});

it("renders the component FormattedItemName", () => {
cy.get(".p-datatable-tbody tr")
.eq(0)
.within(() => {
cy.get("td").eq(1).find(".formatted-item-name").should("exist");
});
cy.get(".p-datatable-tbody tr")
.eq(1)
.within(() => {
cy.get("td").eq(1).find(".formatted-item-name").should("exist");
});
});

it("renders the component Creators", () => {
cy.get(".p-datatable-tbody tr")
.eq(0)
.within(() => {
cy.get("td").eq(5).find(".avatar").should("exist");
});
cy.get(".p-datatable-tbody tr")
.eq(1)
.within(() => {
cy.get("td").eq(5).find(".avatar").should("exist");
});
});
});
Loading
Loading