|
| 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 TreeItem from '@/components/cylc/tree/TreeItem.vue' |
| 19 | +import { |
| 20 | + simpleCyclepointNode, |
| 21 | +} from '$tests/unit/components/cylc/tree/tree.data' |
| 22 | + |
| 23 | +// Get lists of: a) all tree item nodes; b) only visible ones. |
| 24 | +Cypress.Commands.add('getNodeTypes', () => { |
| 25 | + cy.get('.c-treeitem') |
| 26 | + .then(($els) => { |
| 27 | + const all = Array.from($els, ({ dataset }) => dataset.nodeType) |
| 28 | + const visible = all.filter((val, i) => $els[i].checkVisibility()) |
| 29 | + return { all, visible } |
| 30 | + }) |
| 31 | +}) |
| 32 | + |
| 33 | +// Expand/collapse the first node of this type. |
| 34 | +Cypress.Commands.add('toggleNode', (nodeType) => { |
| 35 | + cy.get(`[data-node-type=${nodeType}] .node-expand-collapse-button:first`).click() |
| 36 | +}) |
| 37 | + |
| 38 | +describe('TreeItem component', () => { |
| 39 | + it('expands/collapses children', () => { |
| 40 | + cy.vmount(TreeItem, { |
| 41 | + props: { |
| 42 | + node: simpleCyclepointNode, |
| 43 | + filteredOutNodesCache: new WeakMap(), |
| 44 | + }, |
| 45 | + }) |
| 46 | + cy.addVuetifyStyles(cy) |
| 47 | + |
| 48 | + cy.getNodeTypes() |
| 49 | + .should('deep.equal', { |
| 50 | + // Auto expand everything down to task nodes by default |
| 51 | + all: ['cycle', 'task'], |
| 52 | + visible: ['cycle', 'task'] |
| 53 | + }) |
| 54 | + |
| 55 | + cy.toggleNode('task') |
| 56 | + cy.getNodeTypes() |
| 57 | + .should('deep.equal', { |
| 58 | + all: ['cycle', 'task', 'job'], |
| 59 | + visible: ['cycle', 'task', 'job'] |
| 60 | + }) |
| 61 | + |
| 62 | + cy.toggleNode('cycle') |
| 63 | + cy.getNodeTypes() |
| 64 | + .should('deep.equal', { |
| 65 | + // All previously expanded nodes under cycle should be hidden but remain rendered |
| 66 | + all: ['cycle', 'task', 'job'], |
| 67 | + visible: ['cycle'] |
| 68 | + }) |
| 69 | + |
| 70 | + cy.toggleNode('cycle') |
| 71 | + cy.toggleNode('job') |
| 72 | + cy.getNodeTypes() |
| 73 | + .should('deep.equal', { |
| 74 | + // Job node does not use a child TreeItem |
| 75 | + all: ['cycle', 'task', 'job'], |
| 76 | + visible: ['cycle', 'task', 'job'] |
| 77 | + }) |
| 78 | + }) |
| 79 | +}) |
0 commit comments