-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Textbox testing - add, remove, edit (#3589)
- Loading branch information
Showing
2 changed files
with
115 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,145 @@ | ||
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, 'Dashboard api call returns dashboard slug'); | ||
return slug; | ||
}); | ||
} | ||
|
||
function archiveCurrentDashboard() { | ||
function editDashboard() { | ||
cy.getByTestId('DashboardMoreMenu') | ||
.click() | ||
.within(() => { | ||
cy.get('li') | ||
.contains('Archive') | ||
.contains('Edit') | ||
.click(); | ||
}); | ||
} | ||
|
||
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(); | ||
|
||
cy.get('.btn-warning') | ||
.contains('Archive') | ||
.click(); | ||
cy.get('.label-tag-archived').should('exist'); | ||
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}`); | ||
}); | ||
} | ||
|
||
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}`); | ||
|
||
archiveCurrentDashboard(); | ||
cy.getByTestId('DashboardMoreMenu') | ||
.click() | ||
.within(() => { | ||
cy.get('li') | ||
.contains('Archive') | ||
.click(); | ||
}); | ||
|
||
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('Textbox', () => { | ||
before(function () { | ||
cy.login(); | ||
createNewDashboardByAPI('Foo Bar') | ||
.then(slug => `/dashboard/${slug}`) | ||
.as('dashboardUrl'); | ||
}); | ||
|
||
beforeEach(function () { | ||
cy.visit(this.dashboardUrl); | ||
addTextbox('Hello World!').as('textboxEl'); | ||
}); | ||
|
||
it('removes textbox from X button', function () { | ||
editDashboard(); | ||
|
||
cy.get('@textboxEl').within(() => { | ||
cy.get('.widget-menu-remove').click(); | ||
}); | ||
|
||
cy.get('@textboxEl').should('not.exist'); | ||
}); | ||
|
||
it('removes textbox from menu', function () { | ||
cy.get('@textboxEl').within(() => { | ||
cy.get('.widget-menu-regular').click({ force: true }).within(() => { | ||
cy.get('li a').contains('Remove From Dashboard').click({ force: true }); | ||
}); | ||
}); | ||
|
||
cy.get('@textboxEl').should('not.exist'); | ||
}); | ||
|
||
it('edits textbox', function () { | ||
cy.get('@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.get('@textboxEl').should('contain', newContent); | ||
}); | ||
}); | ||
}); |