|
| 1 | +/** |
| 2 | + * Copyright (C) NIWA & British Crown (Met Office) & Contributors. |
| 3 | + * |
| 4 | + * This program is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | + |
| 18 | +import InfoComponent from '@/components/cylc/Info.vue' |
| 19 | +import { Tokens } from '@/utils/uid' |
| 20 | + |
| 21 | +const DESCRIPTION = `Lorem ipsum dolor sit amet, consectetur adipiscing elit. |
| 22 | +Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. |
| 23 | +Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi. |
| 24 | +` |
| 25 | +const TOKENS = new Tokens('~user/workflow//1234/foo') |
| 26 | +const TASK = { |
| 27 | + id: TOKENS.id, |
| 28 | + name: TOKENS.task, |
| 29 | + tokens: TOKENS, |
| 30 | + node: { |
| 31 | + state: 'running', |
| 32 | + task: { |
| 33 | + meta: { |
| 34 | + title: 'My Foo', |
| 35 | + description: DESCRIPTION, |
| 36 | + URL: 'https://cylc.org', |
| 37 | + customMeta: { |
| 38 | + answer: '42', |
| 39 | + question: 'mutually exclusive', |
| 40 | + } |
| 41 | + } |
| 42 | + }, |
| 43 | + prerequisites: [ |
| 44 | + { |
| 45 | + satisfied: false, |
| 46 | + expression: '(c0 & c1) | c2', |
| 47 | + conditions: [ |
| 48 | + { |
| 49 | + taskId: 'a', |
| 50 | + message: 'succeeded', |
| 51 | + reqState: 'succeeded', |
| 52 | + exprAlias: 'c0', |
| 53 | + satisfied: true, |
| 54 | + }, |
| 55 | + { |
| 56 | + taskId: 'b', |
| 57 | + message: 'custom message', |
| 58 | + reqState: 'custom_output', |
| 59 | + exprAlias: 'c1', |
| 60 | + satisfied: false, |
| 61 | + }, |
| 62 | + { |
| 63 | + taskId: 'a', |
| 64 | + message: 'expired', |
| 65 | + reqState: 'expired', |
| 66 | + exprAlias: 'c2', |
| 67 | + satisfied: false, |
| 68 | + }, |
| 69 | + ], |
| 70 | + }, |
| 71 | + { |
| 72 | + satisfied: true, |
| 73 | + expression: 'c0', |
| 74 | + conditions: [ |
| 75 | + { |
| 76 | + taskId: 'x', |
| 77 | + message: 'succeeded', |
| 78 | + reqState: 'succeeded', |
| 79 | + exprAlias: 'c0', |
| 80 | + satisfied: true, |
| 81 | + }, |
| 82 | + ], |
| 83 | + }, |
| 84 | + ], |
| 85 | + outputs: [ |
| 86 | + { |
| 87 | + label: 'started', |
| 88 | + message: 'started', |
| 89 | + satisfied: true, |
| 90 | + }, |
| 91 | + { |
| 92 | + label: 'succeeded', |
| 93 | + message: 'succeeded', |
| 94 | + satisfied: false, |
| 95 | + }, |
| 96 | + { |
| 97 | + label: 'failed', |
| 98 | + message: 'failed', |
| 99 | + satisfied: false, |
| 100 | + }, |
| 101 | + { |
| 102 | + label: 'x', |
| 103 | + message: 'xxx', |
| 104 | + satisfied: true, |
| 105 | + } |
| 106 | + ], |
| 107 | + runtime: { |
| 108 | + completion: '(succeeded and x) or failed' |
| 109 | + } |
| 110 | + }, |
| 111 | + children: [ |
| 112 | + { |
| 113 | + id: TOKENS.clone({ job: '01' }).id, |
| 114 | + tokens: TOKENS.clone({ job: '01' }), |
| 115 | + name: '01', |
| 116 | + node: { |
| 117 | + state: 'failed' |
| 118 | + } |
| 119 | + }, |
| 120 | + { |
| 121 | + id: TOKENS.clone({ job: '02' }).id, |
| 122 | + tokens: TOKENS.clone({ job: '02' }), |
| 123 | + name: '02', |
| 124 | + node: { |
| 125 | + state: 'succeeded' |
| 126 | + } |
| 127 | + }, |
| 128 | + ], |
| 129 | +} |
| 130 | + |
| 131 | +describe('Info component', () => { |
| 132 | + it('displays task information', () => { |
| 133 | + cy.vmount(InfoComponent, { |
| 134 | + props: { |
| 135 | + task: TASK, |
| 136 | + class: 'job_theme--default', |
| 137 | + // NOTE: expand all sections by default |
| 138 | + panelExpansion: [0, 1, 2, 3], |
| 139 | + } |
| 140 | + }) |
| 141 | + |
| 142 | + // there should be a task icon (running) |
| 143 | + cy.get('.c-graph-node .c8-task.running').should('be.visible') |
| 144 | + |
| 145 | + // and two job icons (succeeded & failed) |
| 146 | + cy.get('.c-graph-node .c-job').should('have.length', 2) |
| 147 | + .get('.c-graph-node .c-job .failed').should('be.visible') |
| 148 | + .get('.c-graph-node .c-job .succeeded').should('be.visible') |
| 149 | + |
| 150 | + // the metadata panel |
| 151 | + cy.get('.metadata-panel.v-expansion-panel--active').should('be.visible') |
| 152 | + .contains('My Foo') |
| 153 | + .get('.metadata-panel') // the description should be displayed |
| 154 | + .contains(/Lorem ipsum dolor sit amet.*/) |
| 155 | + .get('.metadata-panel a:first') // the URL should be an anchor |
| 156 | + .should('have.attr', 'href', 'https://cylc.org') |
| 157 | + .contains(/^https:\/\/cylc.org$/) |
| 158 | + |
| 159 | + // the prerequisites panel |
| 160 | + cy.get('.prerequisites-panel.v-expansion-panel--active').should('be.visible') |
| 161 | + .find('.prerequisite-alias.condition') |
| 162 | + .should('have.length', 6) |
| 163 | + .then((selector) => { |
| 164 | + expect(selector[0].innerText).to.equal('(0 & 1) | 2') |
| 165 | + expect(selector[0]).to.not.have.class('satisfied') |
| 166 | + |
| 167 | + expect(selector[1].innerText).to.equal('0 a:succeeded') |
| 168 | + expect(selector[1]).to.have.class('satisfied') |
| 169 | + |
| 170 | + expect(selector[2].innerText).to.equal('1 b:custom_output') |
| 171 | + expect(selector[2]).to.not.have.class('satisfied') |
| 172 | + |
| 173 | + expect(selector[3].innerText).to.equal('2 a:expired') |
| 174 | + expect(selector[3]).to.not.have.class('satisfied') |
| 175 | + |
| 176 | + expect(selector[4].innerText).to.equal('0') |
| 177 | + expect(selector[4]).to.have.class('satisfied') |
| 178 | + |
| 179 | + expect(selector[5].innerText).to.equal('0 x:succeeded') |
| 180 | + expect(selector[5]).to.have.class('satisfied') |
| 181 | + }) |
| 182 | + |
| 183 | + // the outputs panel |
| 184 | + cy.get('.outputs-panel.v-expansion-panel--active').should('be.visible') |
| 185 | + .find('.condition') |
| 186 | + .should('have.length', 4) |
| 187 | + .then((selector) => { |
| 188 | + expect(selector[0]).to.contain('started') |
| 189 | + expect(selector[0].classList.toString()).to.equal('condition satisfied') |
| 190 | + |
| 191 | + expect(selector[1]).to.contain('succeeded') |
| 192 | + expect(selector[1].classList.toString()).to.equal('condition') |
| 193 | + |
| 194 | + expect(selector[2]).to.contain('failed') |
| 195 | + expect(selector[2].classList.toString()).to.equal('condition') |
| 196 | + |
| 197 | + expect(selector[3]).to.contain('x') |
| 198 | + expect(selector[3].classList.toString()).to.equal('condition satisfied') |
| 199 | + }) |
| 200 | + |
| 201 | + // the completion panel |
| 202 | + cy.get('.completion-panel.v-expansion-panel--active').should('be.visible') |
| 203 | + .find('.condition') |
| 204 | + .should('have.length', 5) |
| 205 | + .then((selector) => { |
| 206 | + expect(selector[0]).to.contain('(') |
| 207 | + expect(selector[0].classList.toString()).to.equal('condition blank') |
| 208 | + |
| 209 | + expect(selector[1]).to.contain('succeeded') |
| 210 | + expect(selector[1].classList.toString()).to.equal('condition') |
| 211 | + |
| 212 | + expect(selector[2]).to.contain('and x') |
| 213 | + expect(selector[2].classList.toString()).to.equal('condition satisfied') |
| 214 | + |
| 215 | + expect(selector[3]).to.contain(')') |
| 216 | + expect(selector[3].classList.toString()).to.equal('condition blank') |
| 217 | + |
| 218 | + expect(selector[4]).to.contain('or failed') |
| 219 | + expect(selector[4].classList.toString()).to.equal('condition') |
| 220 | + }) |
| 221 | + }) |
| 222 | + |
| 223 | + it('should expand sections as intended', () => { |
| 224 | + const spy = cy.spy() |
| 225 | + cy.vmount(InfoComponent, { |
| 226 | + props: { |
| 227 | + task: TASK, |
| 228 | + class: 'job_theme--default' |
| 229 | + }, |
| 230 | + listeners: { |
| 231 | + 'update:panelExpansion': spy, |
| 232 | + } |
| 233 | + }).as('wrapper') |
| 234 | + |
| 235 | + // ONLY the metadata panel should be expanded by default |
| 236 | + cy.get('.v-expansion-panel--active') |
| 237 | + .should('have.length', 1) |
| 238 | + .should('have.class', 'metadata-panel') |
| 239 | + |
| 240 | + // the update:panelExpansion event should be emitted when a panel is |
| 241 | + // expanded/collapsed |
| 242 | + cy.get('.prerequisites-panel') |
| 243 | + .find('button') |
| 244 | + .should('be.visible') |
| 245 | + .click({ force: true }) |
| 246 | + .get('@wrapper').then(({ wrapper }) => { |
| 247 | + expect( |
| 248 | + wrapper.emitted('update:panelExpansion')[0][0] |
| 249 | + ).to.deep.equal([0, 1]) |
| 250 | + }) |
| 251 | + }) |
| 252 | + |
| 253 | + it('should work for a task with no data', () => { |
| 254 | + // ensure the component can be mounted without errors for empty states |
| 255 | + // i.e. no metadata, prerequisites, outputs or jobs |
| 256 | + const tokens = new Tokens('~user/workflow//1234/foo') |
| 257 | + const task = { |
| 258 | + id: tokens.id, |
| 259 | + name: tokens.task, |
| 260 | + tokens, |
| 261 | + node: { |
| 262 | + task: { |
| 263 | + meta: { |
| 264 | + customMeta: {} |
| 265 | + } |
| 266 | + }, |
| 267 | + prerequisites: [], |
| 268 | + outputs: [], |
| 269 | + }, |
| 270 | + children: [], |
| 271 | + } |
| 272 | + |
| 273 | + cy.vmount(InfoComponent, { |
| 274 | + props: { |
| 275 | + task, |
| 276 | + class: 'job_theme--default', |
| 277 | + // NOTE: expand all sections by default |
| 278 | + panelExpansion: [0, 1, 2], |
| 279 | + } |
| 280 | + }) |
| 281 | + }) |
| 282 | +}) |
0 commit comments