diff --git a/cypress/e2e/table.cy.js b/cypress/e2e/table.cy.js index af869c6..0475ae9 100644 --- a/cypress/e2e/table.cy.js +++ b/cypress/e2e/table.cy.js @@ -1,5 +1,5 @@ context("table element", function() { - describe("when element have data-os-element=loop and data-os-view attributes", () => { + describe("when element have data-os-element=loop", () => { beforeEach(() => { cy.visit("/").then(() => { cy.request("/").then((response) => { @@ -19,67 +19,44 @@ context("table element", function() { }); }); - it("calls api/v1/response_views/view_uuid/items", function() { - cy.intercept( - "GET", - "**/api/v1/response_views/view_uuid/items", - { - data: [], - }, - ).as("responseViewsItems"); - - cy.visit("/"); - - cy.wait("@responseViewsItems").then((interceptor) => { - expect(interceptor.request.headers["workspace-id"]).to.equal("1"); - expect(interceptor.request.url).to.match( - /response_views\/view_uuid\/items/, - ); - }); - }); - - describe("when response view have items", () => { + describe("when initialized event has been triggered", () => { it("renders table with data", function() { - cy.intercept( - "GET", - "**/api/v1/response_views/view_uuid/items", - { - data: [ - [ - { - "columnId": 1, - "uuid": "column_uuid_1_1", - "name": "Name", - "value": "Mohamed Salah", - }, - { - "columnId": 2, - "uuid": "column_uuid_1_2", - "name": "City", - "value": "Zhytomyr", - }, - ], - [ - { - "columnId": 1, - "uuid": "column_uuid_1_1", - "name": "Name", - "value": "Lewis Hamilton", - }, - { - "columnId": 2, - "uuid": "column_uuid_1_2", - "name": "City", - "value": "Brovary", - }, - ], - ], - }, - ).as("responseViewsItems"); + const data = [ + [ + { + "columnId": 1, + "uuid": "column_uuid_1_1", + "name": "Name", + "value": "Mohamed Salah", + }, + { + "columnId": 2, + "uuid": "column_uuid_1_2", + "name": "City", + "value": "Zhytomyr", + }, + ], + [ + { + "columnId": 1, + "uuid": "column_uuid_1_1", + "name": "Name", + "value": "Lewis Hamilton", + }, + { + "columnId": 2, + "uuid": "column_uuid_1_2", + "name": "City", + "value": "Brovary", + }, + ], + ]; cy.visit("/"); - - cy.wait("@responseViewsItems").then(() => { + cy.get("os-table").trigger("initialized", { + detail: { value: data }, + force: true, + }).then(() => { cy.get("os-table").find("table").should("exist"); cy.get("os-table").find("thead").should("exist"); cy.get("os-table").find("tbody").should("exist"); @@ -119,265 +96,6 @@ context("table element", function() { }); }); }); - - it("renders empty element with os-hidden class", function() { - cy.intercept( - "GET", - "**/api/v1/response_views/view_uuid/items", - { - data: [ - [ - { - "columnId": 1, - "uuid": "column_uuid_1_1", - "name": "Name", - "value": "Mohamed Salah", - }, - ], - ], - }, - ).as("responseViewsItems"); - - cy.visit("/"); - - cy.wait("@responseViewsItems").then(() => { - cy.get("[data-os-element=empty]").should("have.class", "os-hidden"); - cy.get("[data-os-element=empty]").should( - "have.attr", - "data-os-for", - "view_uuid", - ); - cy.get("[data-os-element=empty]").should( - "have.text", - "No data found", - ); - }); - }); - - it("dispatches a table-success event", function() { - const data = [ - [ - { - columnId: 1, - uuid: "column_uuid_1_1", - name: "Name", - value: "Mohamed Salah", - }, - ], - ]; - cy.intercept( - "GET", - "**/api/v1/response_views/view_uuid/items", - { data }, - ).as("responseViewsItems"); - - cy.visit("/"); - - cy.get("os-table") - .then(($field) => { - cy.spy($field[0], "dispatchEvent").as("dispatchEventSpy"); - }); - cy.wait("@responseViewsItems").then(() => { - cy.get("@dispatchEventSpy").should((spy) => { - const { detail, type } = spy.args[0][0]; - expect(type).to.equal("table-success"); - expect(detail.data).to.deep.equal(data); - expect(detail.responseViewUuid).to.equal("view_uuid"); - }); - }); - }); - - it("dispatches a table-loading event with value: false", function() { - cy.intercept( - "GET", - "**/api/v1/response_views/view_uuid/items", - { - data: [ - [ - { - "columnId": 1, - "uuid": "column_uuid_1_1", - "name": "Name", - "value": "Mohamed Salah", - }, - ], - ], - }, - ).as("responseViewsItems"); - cy.visit("/"); - - cy.get("os-table") - .then(($field) => { - cy.spy($field[0], "dispatchEvent").as("dispatchEventSpy"); - }); - cy.wait("@responseViewsItems").then(() => { - cy.get("@dispatchEventSpy").should((spy) => { - const { detail, type } = spy.args[1][0]; - expect(type).to.equal("table-loading"); - expect(detail.value).to.equal(false); - }); - }); - }); - }); - - describe("when response view does not have items", () => { - it("removes os-hidden class from an empty element", function() { - cy.intercept( - "GET", - "**/api/v1/response_views/view_uuid/items", - { - data: [], - }, - ).as("responseViewsItems"); - - cy.visit("/"); - - cy.wait("@responseViewsItems").then(() => { - cy.get("[data-os-element=empty]").should( - "not.have.class", - "os-hidden", - ); - cy.get("[data-os-element=empty]").should("be.visible"); - }); - }); - - it("dispatches a table-empty event", function() { - cy.intercept( - "GET", - "**/api/v1/response_views/view_uuid/items", - { data: [] }, - ).as("responseViewsItems"); - - cy.visit("/"); - - cy.get("os-table") - .then(($field) => { - cy.spy($field[0], "dispatchEvent").as("dispatchEventSpy"); - }); - cy.wait("@responseViewsItems").then(() => { - cy.get("@dispatchEventSpy").should((spy) => { - const { detail, type } = spy.args[0][0]; - expect(type).to.equal("table-empty"); - expect(detail.responseViewUuid).to.equal("view_uuid"); - }); - }); - }); - }); - - describe("when items request does not succeeded", () => { - it("dispatches a table-error event", function() { - cy.intercept( - "GET", - "**/api/v1/response_views/view_uuid/items", - { forceNetworkError: true }, - ).as( - "itemsError", - ); - cy.visit("/"); - - cy.get("os-table") - .then(($field) => { - cy.spy($field[0], "dispatchEvent").as("dispatchEventSpy"); - }); - cy.wait("@itemsError").then(() => { - cy.get("@dispatchEventSpy").should((spy) => { - const { detail, type } = spy.args[0][0]; - expect(type).to.equal("table-error"); - expect(detail.error.message).to.equal("Failed to fetch"); - }); - }); - }); - - it("dispatches a table-loading event with value: false", function() { - cy.intercept( - "GET", - "**/api/v1/response_views/view_uuid/items", - { forceNetworkError: true }, - ).as( - "itemsError", - ); - cy.visit("/"); - - cy.get("os-table") - .then(($field) => { - cy.spy($field[0], "dispatchEvent").as("dispatchEventSpy"); - }); - cy.wait("@itemsError").then(() => { - cy.get("@dispatchEventSpy").should((spy) => { - const { detail, type } = spy.args[1][0]; - expect(type).to.equal("table-loading"); - expect(detail.value).to.equal(false); - }); - }); - }); - }); - }); - - describe("when element does not have data-os-element=loop attribute", () => { - beforeEach(() => { - cy.visit("/").then(() => { - cy.request("/").then((response) => { - const body = ` -
-