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

Textbox testing - add, remove, edit #3589

Merged
merged 9 commits into from
Mar 17, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion client/app/pages/dashboards/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ <h3>
<div class="dashboard-widget-wrapper"
ng-repeat="widget in $ctrl.dashboard.widgets track by widget.id"
gridstack-item="widget.options.position" gridstack-item-id="{{ widget.id }}">
<div class="grid-stack-item-content">
<div class="grid-stack-item-content" data-test="WidgetId{{ widget.id }}">
<dashboard-widget widget="widget" dashboard="$ctrl.dashboard" on-delete="$ctrl.removeWidget(widget.id)"></dashboard-widget>
</div>
</div>
Expand Down
144 changes: 116 additions & 28 deletions cypress/integration/dashboard/dashboard_spec.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,147 @@
function createNewDashboard(dashboardName) {
cy.visit('/dashboards');
cy.getByTestId('CreateButton').click();
cy.get('li[role="menuitem"]')
.contains('Dashboard')
.click();

function createNewDashboardByAPI(name) {
cy.server();
cy.route('POST', 'api/dashboards').as('NewDashboard');

cy.getByTestId('EditDashboardDialog').within(() => {
cy.getByTestId('DashboardSaveButton').should('be.disabled');
cy.get('input').type(dashboardName);
cy.getByTestId('DashboardSaveButton').click();
});

return cy.wait('@NewDashboard').then((xhr) => {
const slug = Cypress._.get(xhr, 'response.body.slug');
assert.isDefined(slug, 'Dashboard api call returns slug');
return cy.request('POST', 'api/dashboards', { name }).then((response) => {
const slug = Cypress._.get(response, 'body.slug');
assert.isDefined(slug, 'Widget api call returns widget slug');
gabrieldutra marked this conversation as resolved.
Show resolved Hide resolved
return slug;
});
}

function archiveCurrentDashboard() {
function editDashboard() {
cy.getByTestId('DashboardMoreMenu')
.click()
.within(() => {
cy.get('li')
.contains('Archive')
.contains('Edit')
.click();
});
}

cy.get('.btn-warning')
.contains('Archive')
.click();
cy.get('.label-tag-archived').should('exist');
function addTextbox(text) {
cy.server();
cy.route('POST', 'api/widgets').as('NewWidget');

editDashboard();

cy.contains('a', 'Add Textbox').click();
cy.get('.add-textbox').within(() => {
cy.get('textarea').type(text);
});
cy.contains('button', 'Add to Dashboard').click();
cy.get('.add-textbox').should('not.exist');
cy.contains('button', 'Apply Changes').click();

return cy.wait('@NewWidget').then((xhr) => {
const id = Cypress._.get(xhr, 'response.body.id');
assert.isDefined(id, 'Widget api call returns widget id');
return cy.getByTestId(`WidgetId${id}`).should('exist');
});
}

describe('Dashboard', () => {
beforeEach(() => {
cy.login();
});

it('creates a new dashboard and archives it', () => {
createNewDashboard('Foo Bar').then((slug) => {
it('creates new dashboard', () => {
cy.visit('/dashboards');
cy.getByTestId('CreateButton').click();
cy.get('li[role="menuitem"]').contains('Dashboard').click();

cy.server();
cy.route('POST', 'api/dashboards').as('NewDashboard');

cy.getByTestId('EditDashboardDialog').within(() => {
cy.getByTestId('DashboardSaveButton').should('be.disabled');
cy.get('input').type('Foo Bar');
cy.getByTestId('DashboardSaveButton').click();
});

cy.wait('@NewDashboard').then((xhr) => {
const slug = Cypress._.get(xhr, 'response.body.slug');
assert.isDefined(slug, 'Dashboard api call returns slug');

cy.visit('/dashboards');
cy.getByTestId('DashboardLayoutContent').within(() => {
cy.getByTestId(slug).should('exist').click();
cy.getByTestId(slug).should('exist');
});
});
});

it('archives dashboard', function() {
createNewDashboardByAPI('Foo Bar').then((slug) => {
cy.visit(`/dashboard/${slug}`);

cy.getByTestId('DashboardMoreMenu')
.click()
.within(() => {
cy.get('li')
.contains('Archive')
.click();
});

archiveCurrentDashboard();
cy.get('.btn-warning')
.contains('Archive')
.click();
cy.get('.label-tag-archived').should('exist');

cy.visit('/dashboards');
cy.getByTestId('DashboardLayoutContent').within(() => {
cy.getByTestId(slug).should('not.exist');
});
});
});


describe('Editing a dashboard', () => {
gabrieldutra marked this conversation as resolved.
Show resolved Hide resolved
before(function() {
cy.login();
return createNewDashboardByAPI('Foo Bar').then((slug) => {
this.dashboardUrl = `/dashboard/${slug}`;
});
gabrieldutra marked this conversation as resolved.
Show resolved Hide resolved
});

beforeEach(function() {
cy.visit(this.dashboardUrl);
return addTextbox('Hello World!').then(($el) => {
this.$textboxEl = $el;
});
gabrieldutra marked this conversation as resolved.
Show resolved Hide resolved
});

it('removes textbox from X button', function() {
editDashboard();

cy.wrap(this.$textboxEl).within(() => {
cy.get('.widget-menu-remove').click();
});

cy.wrap(this.$textboxEl).should('not.exist');
});

it('removes textbox from menu', function() {
cy.wrap(this.$textboxEl).within(() => {
gabrieldutra marked this conversation as resolved.
Show resolved Hide resolved
cy.get('.widget-menu-regular').click({ force: true }).within(() => {
cy.get('li a').contains('Remove From Dashboard').click({ force: true });
});
});

cy.wrap(this.$textboxEl).should('not.exist');
});

it('edits textbox', function() {
cy.wrap(this.$textboxEl).within(() => {
cy.get('.widget-menu-regular').click({ force: true }).within(() => {
cy.get('li a').contains('Edit').click({ force: true });
});
});

const newContent = '[edited]';
cy.get('edit-text-box').should('exist').within(() => {
cy.get('textarea').clear().type(newContent);
cy.contains('button', 'Save').click();
});

cy.wrap(this.$textboxEl).should('contain', newContent);
});
});
});