Skip to content

Commit e5d082b

Browse files
authored
Textbox testing - add, remove, edit (#3589)
1 parent 93aa6b5 commit e5d082b

File tree

2 files changed

+115
-29
lines changed

2 files changed

+115
-29
lines changed

client/app/pages/dashboards/dashboard.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ <h3>
9797
<div class="dashboard-widget-wrapper"
9898
ng-repeat="widget in $ctrl.dashboard.widgets track by widget.id"
9999
gridstack-item="widget.options.position" gridstack-item-id="{{ widget.id }}">
100-
<div class="grid-stack-item-content">
100+
<div class="grid-stack-item-content" data-test="WidgetId{{ widget.id }}">
101101
<dashboard-widget widget="widget" dashboard="$ctrl.dashboard" on-delete="$ctrl.removeWidget(widget.id)"></dashboard-widget>
102102
</div>
103103
</div>
Lines changed: 114 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,145 @@
1-
function createNewDashboard(dashboardName) {
2-
cy.visit('/dashboards');
3-
cy.getByTestId('CreateButton').click();
4-
cy.get('li[role="menuitem"]')
5-
.contains('Dashboard')
6-
.click();
7-
1+
function createNewDashboardByAPI(name) {
82
cy.server();
9-
cy.route('POST', 'api/dashboards').as('NewDashboard');
10-
11-
cy.getByTestId('EditDashboardDialog').within(() => {
12-
cy.getByTestId('DashboardSaveButton').should('be.disabled');
13-
cy.get('input').type(dashboardName);
14-
cy.getByTestId('DashboardSaveButton').click();
15-
});
16-
17-
return cy.wait('@NewDashboard').then((xhr) => {
18-
const slug = Cypress._.get(xhr, 'response.body.slug');
19-
assert.isDefined(slug, 'Dashboard api call returns slug');
3+
return cy.request('POST', 'api/dashboards', { name }).then((response) => {
4+
const slug = Cypress._.get(response, 'body.slug');
5+
assert.isDefined(slug, 'Dashboard api call returns dashboard slug');
206
return slug;
217
});
228
}
239

24-
function archiveCurrentDashboard() {
10+
function editDashboard() {
2511
cy.getByTestId('DashboardMoreMenu')
2612
.click()
2713
.within(() => {
2814
cy.get('li')
29-
.contains('Archive')
15+
.contains('Edit')
3016
.click();
3117
});
18+
}
19+
20+
function addTextbox(text) {
21+
cy.server();
22+
cy.route('POST', 'api/widgets').as('NewWidget');
23+
24+
editDashboard();
25+
26+
cy.contains('a', 'Add Textbox').click();
27+
cy.get('.add-textbox').within(() => {
28+
cy.get('textarea').type(text);
29+
});
30+
cy.contains('button', 'Add to Dashboard').click();
31+
cy.get('.add-textbox').should('not.exist');
32+
cy.contains('button', 'Apply Changes').click();
3233

33-
cy.get('.btn-warning')
34-
.contains('Archive')
35-
.click();
36-
cy.get('.label-tag-archived').should('exist');
34+
return cy.wait('@NewWidget').then((xhr) => {
35+
const id = Cypress._.get(xhr, 'response.body.id');
36+
assert.isDefined(id, 'Widget api call returns widget id');
37+
return cy.getByTestId(`WidgetId${id}`);
38+
});
3739
}
3840

3941
describe('Dashboard', () => {
4042
beforeEach(() => {
4143
cy.login();
4244
});
4345

44-
it('creates a new dashboard and archives it', () => {
45-
createNewDashboard('Foo Bar').then((slug) => {
46+
it('creates new dashboard', () => {
47+
cy.visit('/dashboards');
48+
cy.getByTestId('CreateButton').click();
49+
cy.get('li[role="menuitem"]').contains('Dashboard').click();
50+
51+
cy.server();
52+
cy.route('POST', 'api/dashboards').as('NewDashboard');
53+
54+
cy.getByTestId('EditDashboardDialog').within(() => {
55+
cy.getByTestId('DashboardSaveButton').should('be.disabled');
56+
cy.get('input').type('Foo Bar');
57+
cy.getByTestId('DashboardSaveButton').click();
58+
});
59+
60+
cy.wait('@NewDashboard').then((xhr) => {
61+
const slug = Cypress._.get(xhr, 'response.body.slug');
62+
assert.isDefined(slug, 'Dashboard api call returns slug');
63+
4664
cy.visit('/dashboards');
4765
cy.getByTestId('DashboardLayoutContent').within(() => {
48-
cy.getByTestId(slug).should('exist').click();
66+
cy.getByTestId(slug).should('exist');
4967
});
68+
});
69+
});
70+
71+
it('archives dashboard', function () {
72+
createNewDashboardByAPI('Foo Bar').then((slug) => {
73+
cy.visit(`/dashboard/${slug}`);
5074

51-
archiveCurrentDashboard();
75+
cy.getByTestId('DashboardMoreMenu')
76+
.click()
77+
.within(() => {
78+
cy.get('li')
79+
.contains('Archive')
80+
.click();
81+
});
82+
83+
cy.get('.btn-warning')
84+
.contains('Archive')
85+
.click();
86+
cy.get('.label-tag-archived').should('exist');
5287

5388
cy.visit('/dashboards');
5489
cy.getByTestId('DashboardLayoutContent').within(() => {
5590
cy.getByTestId(slug).should('not.exist');
5691
});
5792
});
5893
});
94+
95+
96+
describe('Textbox', () => {
97+
before(function () {
98+
cy.login();
99+
createNewDashboardByAPI('Foo Bar')
100+
.then(slug => `/dashboard/${slug}`)
101+
.as('dashboardUrl');
102+
});
103+
104+
beforeEach(function () {
105+
cy.visit(this.dashboardUrl);
106+
addTextbox('Hello World!').as('textboxEl');
107+
});
108+
109+
it('removes textbox from X button', function () {
110+
editDashboard();
111+
112+
cy.get('@textboxEl').within(() => {
113+
cy.get('.widget-menu-remove').click();
114+
});
115+
116+
cy.get('@textboxEl').should('not.exist');
117+
});
118+
119+
it('removes textbox from menu', function () {
120+
cy.get('@textboxEl').within(() => {
121+
cy.get('.widget-menu-regular').click({ force: true }).within(() => {
122+
cy.get('li a').contains('Remove From Dashboard').click({ force: true });
123+
});
124+
});
125+
126+
cy.get('@textboxEl').should('not.exist');
127+
});
128+
129+
it('edits textbox', function () {
130+
cy.get('@textboxEl').within(() => {
131+
cy.get('.widget-menu-regular').click({ force: true }).within(() => {
132+
cy.get('li a').contains('Edit').click({ force: true });
133+
});
134+
});
135+
136+
const newContent = '[edited]';
137+
cy.get('edit-text-box').should('exist').within(() => {
138+
cy.get('textarea').clear().type(newContent);
139+
cy.contains('button', 'Save').click();
140+
});
141+
142+
cy.get('@textboxEl').should('contain', newContent);
143+
});
144+
});
59145
});

0 commit comments

Comments
 (0)