|
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) { |
8 | 2 | 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'); |
20 | 6 | return slug; |
21 | 7 | }); |
22 | 8 | } |
23 | 9 |
|
24 | | -function archiveCurrentDashboard() { |
| 10 | +function editDashboard() { |
25 | 11 | cy.getByTestId('DashboardMoreMenu') |
26 | 12 | .click() |
27 | 13 | .within(() => { |
28 | 14 | cy.get('li') |
29 | | - .contains('Archive') |
| 15 | + .contains('Edit') |
30 | 16 | .click(); |
31 | 17 | }); |
| 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(); |
32 | 33 |
|
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 | + }); |
37 | 39 | } |
38 | 40 |
|
39 | 41 | describe('Dashboard', () => { |
40 | 42 | beforeEach(() => { |
41 | 43 | cy.login(); |
42 | 44 | }); |
43 | 45 |
|
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 | + |
46 | 64 | cy.visit('/dashboards'); |
47 | 65 | cy.getByTestId('DashboardLayoutContent').within(() => { |
48 | | - cy.getByTestId(slug).should('exist').click(); |
| 66 | + cy.getByTestId(slug).should('exist'); |
49 | 67 | }); |
| 68 | + }); |
| 69 | + }); |
| 70 | + |
| 71 | + it('archives dashboard', function () { |
| 72 | + createNewDashboardByAPI('Foo Bar').then((slug) => { |
| 73 | + cy.visit(`/dashboard/${slug}`); |
50 | 74 |
|
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'); |
52 | 87 |
|
53 | 88 | cy.visit('/dashboards'); |
54 | 89 | cy.getByTestId('DashboardLayoutContent').within(() => { |
55 | 90 | cy.getByTestId(slug).should('not.exist'); |
56 | 91 | }); |
57 | 92 | }); |
58 | 93 | }); |
| 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 | + }); |
59 | 145 | }); |
0 commit comments