From 8f6ee06447cdacb78f7ca1b1399e736f02ab38a6 Mon Sep 17 00:00:00 2001 From: Ran Byron Date: Thu, 14 Mar 2019 18:30:38 +0200 Subject: [PATCH] Added widget tests - add, remove, auto height --- .../integration/dashboard/dashboard_spec.js | 65 ++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/cypress/integration/dashboard/dashboard_spec.js b/cypress/integration/dashboard/dashboard_spec.js index 212309b0aa..086d70ea1c 100644 --- a/cypress/integration/dashboard/dashboard_spec.js +++ b/cypress/integration/dashboard/dashboard_spec.js @@ -44,6 +44,36 @@ function addTextbox() { cy.contains('button', 'Add to Dashboard').click(); } +function addWidget(queryData) { + const defaultQueryData = { data_source_id: 1, options: { parameters: [] }, schedule: null }; + const merged = Object.assign(defaultQueryData, queryData); + + cy.server(); + + // create query + return cy.request('POST', '/api/queries', merged) + .then(({ body }) => { + // publish it so it's avail for widget + return cy.request('POST', `/api/queries/${body.id}`, { is_draft: false }); + }) + .then(({ body }) => { + // create widget + cy.contains('a', 'Add Widget').click(); + cy.getByTestId('AddWidgetDialog').within(() => { + cy.get(`.query-selector-result[data-test="QueryId${body.id}"]`).click(); + }); + + cy.route('POST', 'api/widgets').as('NewWidget'); + cy.contains('button', 'Add to Dashboard').click(); + return cy.wait('@NewWidget'); + }) + .then((xhr) => { + const body = Cypress._.get(xhr, 'response.body'); + assert.isDefined(body, 'Widget api call returns body'); + return body; + }); +} + describe('Dashboard', () => { beforeEach(() => { cy.login(); @@ -65,7 +95,7 @@ describe('Dashboard', () => { }); }); - describe('Textbox', () => { + describe('Textbox and Widget', () => { beforeEach(() => { createNewDashboard('Foo Bar'); cy.contains('button', 'Apply Changes').click(); @@ -125,5 +155,38 @@ describe('Dashboard', () => { }); }); }); + + it('adds and removes widget', () => { + const queryData = { + name: 'Test Query 01', + query: 'select 1', + }; + + addWidget(queryData).then(({ id }) => { + cy.getByTestId(`WidgetId${id}`).should('exist').within(() => { + cy.get('.widget-menu-remove').click(); + }); + cy.getByTestId(`WidgetId${id}`).should('not.exist'); + }); + }); + + it('renders widget auto height by table row count', () => { + const testAutoHeight = (rowCount, expectedWidgetHeight) => { + const queryData = { + name: 'Test Query Auto Height', + query: `select s.a FROM generate_series(1,${rowCount}) AS s(a)`, + }; + + addWidget(queryData).then(({ id, options }) => { + expect(options.position.autoHeight).to.be.true; + cy.getByTestId(`WidgetId${id}`) + .its('0.offsetHeight') + .should('eq', expectedWidgetHeight); + }); + } + + testAutoHeight(2, 235); + testAutoHeight(5, 335); + }); }); });