|
| 1 | +/* eslint-disable no-undef */ |
| 2 | + |
| 3 | +describe('Overview > Dashboard Tests', () => { |
| 4 | + const defaultCards = []; |
| 5 | + let newCard = ''; |
| 6 | + |
| 7 | + beforeEach(() => { |
| 8 | + cy.login(); |
| 9 | + cy.menu('Overview', 'Dashboard'); |
| 10 | + }); |
| 11 | + |
| 12 | + it('Dashboard loads correctly', () => { |
| 13 | + cy.get('#main-menu'); |
| 14 | + cy.get('.card-pf').then((cards) => { |
| 15 | + const nums = [...Array(cards.length).keys()]; |
| 16 | + nums.forEach((index) => { |
| 17 | + defaultCards[index] = cards[index].firstChild.innerText; |
| 18 | + }); |
| 19 | + }); |
| 20 | + }); |
| 21 | + |
| 22 | + it('Default dashboard widgets loaded', () => { |
| 23 | + cy.get('.card-pf').then((cards) => { |
| 24 | + const nums = [...Array(cards.length).keys()]; |
| 25 | + nums.forEach((index) => { |
| 26 | + cy.get(cards[index]).contains(defaultCards[index]); |
| 27 | + }); |
| 28 | + }); |
| 29 | + }); |
| 30 | + |
| 31 | + it('Reset dashboard back to default widgets', () => { |
| 32 | + cy.get('#dropdown-custom-2').click().then(() => { |
| 33 | + cy.get('.scrollable-options').then((list) => { |
| 34 | + cy.get(list.children()[0]).click(); |
| 35 | + }); |
| 36 | + }); |
| 37 | + |
| 38 | + cy.get('#dropdown-custom-2').click().then(() => { |
| 39 | + cy.get('.scrollable-options').then((list) => { |
| 40 | + cy.get(list.children()[1]).click(); |
| 41 | + }); |
| 42 | + }); |
| 43 | + |
| 44 | + cy.get('.card-pf').its('length').should('eq', defaultCards.length + 2); |
| 45 | + |
| 46 | + cy.intercept('POST', '/dashboard/reset_widgets').as('post'); |
| 47 | + cy.get('.miq-toolbar-group > .btn').click(); |
| 48 | + |
| 49 | + cy.wait('@post').then((getCall) => { |
| 50 | + expect(getCall.state).to.equal('Complete'); |
| 51 | + expect(getCall.response).to.include({ |
| 52 | + statusCode: 200, |
| 53 | + }); |
| 54 | + }); |
| 55 | + |
| 56 | + cy.get('.card-pf').then((cards) => { |
| 57 | + const nums = [...Array(cards.length).keys()]; |
| 58 | + nums.forEach((index) => { |
| 59 | + cy.get(cards[index]).contains(defaultCards[index]); |
| 60 | + }); |
| 61 | + }); |
| 62 | + }); |
| 63 | + |
| 64 | + it('Can add a widget', () => { |
| 65 | + const newCards = []; |
| 66 | + cy.get('#dropdown-custom-2').click().then(() => { |
| 67 | + cy.get('.scrollable-options').then((list) => { |
| 68 | + newCard = list.children()[0].innerText.trim(); |
| 69 | + cy.get(list.children()[0]).click().then(() => { |
| 70 | + cy.get('.card-pf').its('length').should('eq', defaultCards.length + 1); |
| 71 | + cy.get('.card-pf').then((cards) => { |
| 72 | + const nums = [...Array(cards.length).keys()]; |
| 73 | + nums.forEach((index) => { |
| 74 | + newCards[index] = cards[index].firstChild.innerText; |
| 75 | + }); |
| 76 | + expect(newCards).to.include(newCard); |
| 77 | + }); |
| 78 | + }); |
| 79 | + }); |
| 80 | + }); |
| 81 | + }); |
| 82 | + |
| 83 | + it('Can minimize / maximize a widget', () => { |
| 84 | + cy.get('.card-pf').then((cards) => { |
| 85 | + const nums = [...Array(cards.length).keys()]; |
| 86 | + nums.forEach((index) => { |
| 87 | + if (cards[index].firstChild.innerText === newCard) { |
| 88 | + cy.get(cards[index]).then((card) => { |
| 89 | + cy.get(card.children()[0].children[0].children[0]).click().then(() => { |
| 90 | + cy.get('.bx--overflow-menu-options').then((menuItems) => { |
| 91 | + cy.get(menuItems.children()[1]).click().then(() => { |
| 92 | + expect(card.children()[1].style.display).to.equal('none'); |
| 93 | + }); |
| 94 | + }); |
| 95 | + }); |
| 96 | + }); |
| 97 | + } |
| 98 | + }); |
| 99 | + }); |
| 100 | + cy.get('.card-pf').then((cards) => { |
| 101 | + const nums = [...Array(cards.length).keys()]; |
| 102 | + nums.forEach((index) => { |
| 103 | + if (cards[index].firstChild.innerText === newCard) { |
| 104 | + cy.get(cards[index]).then((card) => { |
| 105 | + cy.get(card.children()[0].children[0].children[0]).click().then(() => { |
| 106 | + cy.get('.bx--overflow-menu-options').then((menuItems) => { |
| 107 | + cy.get(menuItems.children()[1]).click().then(() => { |
| 108 | + expect(card.children()[1].style.display).to.equal('block'); |
| 109 | + }); |
| 110 | + }); |
| 111 | + }); |
| 112 | + }); |
| 113 | + } |
| 114 | + }); |
| 115 | + }); |
| 116 | + }); |
| 117 | + |
| 118 | + it('Can zoom a widget', () => { |
| 119 | + cy.get('#lightbox-panel').then((div) => { |
| 120 | + expect(div[0].style.display).to.equal(''); |
| 121 | + }); |
| 122 | + cy.get('.card-pf').then((cards) => { |
| 123 | + const nums = [...Array(cards.length).keys()]; |
| 124 | + nums.forEach((index) => { |
| 125 | + if (cards[index].firstChild.innerText === newCard) { |
| 126 | + cy.get(cards[index]).then((card) => { |
| 127 | + cy.get(card.children()[0].children[0].children[0]).click().then(() => { |
| 128 | + cy.get('.bx--overflow-menu-options').then((menuItems) => { |
| 129 | + cy.get(menuItems.children()[2]).click().then(() => { |
| 130 | + cy.get('#zoomed_chart_div').contains(newCard); |
| 131 | + cy.get('#lightbox-panel').then((div) => { |
| 132 | + expect(div[0].style.display).to.equal('block'); |
| 133 | + }); |
| 134 | + }); |
| 135 | + }); |
| 136 | + }); |
| 137 | + }); |
| 138 | + } |
| 139 | + }); |
| 140 | + }); |
| 141 | + }); |
| 142 | + |
| 143 | + it('Can refresh a widget', () => { |
| 144 | + cy.get('.card-pf').then((cards) => { |
| 145 | + cy.intercept('GET', '/dashboard/widget_chart_data/1').as('get'); |
| 146 | + const nums = [...Array(cards.length).keys()]; |
| 147 | + nums.forEach((index) => { |
| 148 | + if (cards[index].firstChild.innerText === newCard) { |
| 149 | + cy.get(cards[index]).then((card) => { |
| 150 | + cy.get(card.children()[0].children[0].children[0]).click().then(() => { |
| 151 | + cy.get('.bx--overflow-menu-options').then((menuItems) => { |
| 152 | + cy.get(menuItems.children()[3]).click().then(() => { |
| 153 | + cy.wait('@get').then((getCall) => { |
| 154 | + expect(getCall.state).to.equal('Complete'); |
| 155 | + expect([200, 304]).to.include(getCall.response.statusCode); |
| 156 | + }); |
| 157 | + }); |
| 158 | + }); |
| 159 | + }); |
| 160 | + }); |
| 161 | + } |
| 162 | + }); |
| 163 | + }); |
| 164 | + }); |
| 165 | + |
| 166 | + it('Can remove a widget', () => { |
| 167 | + cy.get('.card-pf').then((cards) => { |
| 168 | + const nums = [...Array(cards.length - 1).keys()]; |
| 169 | + nums.forEach((index) => { |
| 170 | + if (cards[index].firstChild.innerText === newCard) { |
| 171 | + cy.get(cards[index]).then((card) => { |
| 172 | + cy.get(card.children()[0].children[0].children[0]).click().then(() => { |
| 173 | + cy.get('.bx--overflow-menu-options').then((menuItems) => { |
| 174 | + cy.get(menuItems.children()[0]).click().then(() => { |
| 175 | + cy.get('.card-pf').its('length').should('eq', defaultCards.length); |
| 176 | + cy.get('.card-pf').then((cards) => { |
| 177 | + const nums = [...Array(cards.length).keys()]; |
| 178 | + nums.forEach((index) => { |
| 179 | + cy.get(cards[index]).contains(defaultCards[index]); |
| 180 | + }); |
| 181 | + }); |
| 182 | + }); |
| 183 | + }); |
| 184 | + }); |
| 185 | + }); |
| 186 | + } |
| 187 | + }); |
| 188 | + }); |
| 189 | + }); |
| 190 | +}); |
0 commit comments