From 43c00d1bd9cc6e93e26e48165eb6a27a85ee9666 Mon Sep 17 00:00:00 2001 From: Ronnie Dutta <61982285+MetRonnie@users.noreply.github.com> Date: Mon, 21 Nov 2022 17:22:51 +0000 Subject: [PATCH] Add e2e tests for Edit-Runtime form --- .../graphqlFormGenerator/EditRuntimeForm.vue | 3 +- .../graphqlFormGenerator/components/List.vue | 1 + .../components/MapItem.vue | 2 + tests/e2e/specs/editRuntimeForm.cy.js | 134 ++++++++++++++++++ tests/e2e/specs/mutation.cy.js | 27 ++-- 5 files changed, 152 insertions(+), 15 deletions(-) create mode 100644 tests/e2e/specs/editRuntimeForm.cy.js diff --git a/src/components/graphqlFormGenerator/EditRuntimeForm.vue b/src/components/graphqlFormGenerator/EditRuntimeForm.vue index a73917100e..b349b7bcf9 100644 --- a/src/components/graphqlFormGenerator/EditRuntimeForm.vue +++ b/src/components/graphqlFormGenerator/EditRuntimeForm.vue @@ -29,6 +29,7 @@ along with this program. If not, see . . :key="key" > - + {{ startCase(key) }} diff --git a/src/components/graphqlFormGenerator/components/List.vue b/src/components/graphqlFormGenerator/components/List.vue index bfb325c085..63d96719eb 100644 --- a/src/components/graphqlFormGenerator/components/List.vue +++ b/src/components/graphqlFormGenerator/components/List.vue @@ -49,6 +49,7 @@ along with this program. If not, see . {{ svgPaths.open }} Add Item diff --git a/src/components/graphqlFormGenerator/components/MapItem.vue b/src/components/graphqlFormGenerator/components/MapItem.vue index c71e54794c..02bbfe81fd 100644 --- a/src/components/graphqlFormGenerator/components/MapItem.vue +++ b/src/components/graphqlFormGenerator/components/MapItem.vue @@ -33,6 +33,7 @@ along with this program. If not, see . :disabled="value.frozenKey" dense filled + class="c-input-key" /> @@ -48,6 +49,7 @@ along with this program. If not, see . v-model="value.value" dense filled + class="c-input-val" /> diff --git a/tests/e2e/specs/editRuntimeForm.cy.js b/tests/e2e/specs/editRuntimeForm.cy.js new file mode 100644 index 0000000000..b74b9dde36 --- /dev/null +++ b/tests/e2e/specs/editRuntimeForm.cy.js @@ -0,0 +1,134 @@ +/** + * Copyright (C) NIWA & British Crown (Met Office) & Contributors. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +import { upperFirst } from 'lodash' + +describe('Edit Runtime form', () => { + const receivedMutations = [] + + beforeEach(() => { + receivedMutations.splice(0) + // Patch graphql responses + cy.intercept('/graphql', (req) => { + const { query } = req.body + if (query.startsWith('mutation')) { + receivedMutations.push(query) + req.reply({ + data: { + [req.body.operationName]: { + result: [true, {}], + __typename: upperFirst(req.body.operationName) + } + } + }) + } + }) + cy.visit('/#/tree/one') + }) + + /** + * @param {string} nodeName - the tree node name, to search for and open the mutations form + */ + const openMenu = (nodeName) => { + cy.get('[data-cy=tree-view]').as('treeView') + .find('.c-task') + .should('be.visible') + cy.get('@treeView') + .find('span') + .contains(nodeName) + .parent() + .find('.c-task') + .click({ force: true }) + cy.get('#less-more-button') + .click() + } + + /** Get the Edit Runtime command from the menu */ + const getMenuItem = () => { + return cy + .get('.c-mutation-menu-list:first') + .find('.c-mutation .v-list-item__title') + .contains('Edit Runtime') + } + + /** + * Get the form input v-list-item element for a given label. + * + * @param {string} label + */ + const getInputListItem = (label) => { + return cy + .get('.c-edit-runtime-form') + .find('.c-input-label') + .contains(label) + .parent() + } + + it('handles editing and submitting the form', () => { + openMenu('retrying') + getMenuItem().click() + + getInputListItem('Init Script') + .find('.v-input') + .type('echo "Horseshoe Overlook"') + getInputListItem('Environment') + .as('envInput') + // Pre-existing items' keys should be immutable + .find('.c-input-key') + .find('input') + .should('be.disabled') + // Change a pre-existing item's value + .get('@envInput') + .find('.c-input-val:first') + .clear() + .type('Pinkerton Detective Agency') + // Add a new item + .get('@envInput') + .find('button[data-cy="add"]') + .click() + .get('@envInput') + .find('.c-input-key:first') + .type('HORSE') + .get('@envInput') + .find('.c-input-val:first') + .type('Dorothy') + getInputListItem('Outputs') + // Add an empty item + .find('button[data-cy="add"]') + .click() + + // Submit form + cy + .then(() => { + expect(receivedMutations.length).to.eq(0) + }) + .get('[data-cy="submit"]') + .click() + .then(() => { + expect(receivedMutations.length).to.eq(1) + }) + }) + + it('shows Edit Runtime as an option for namespaces only', () => { + // E.g. families + openMenu('GOOD') + getMenuItem() + // But not cycle points + openMenu('20000102T0000Z') + getMenuItem().should('not.exist') + }) +}) diff --git a/tests/e2e/specs/mutation.cy.js b/tests/e2e/specs/mutation.cy.js index 1faa26b064..6d10be928c 100644 --- a/tests/e2e/specs/mutation.cy.js +++ b/tests/e2e/specs/mutation.cy.js @@ -24,21 +24,20 @@ import { describe('Mutations component', () => { beforeEach(() => { // Patch graphql responses - cy - .intercept('/graphql', (req) => { - const query = req.body.query - if (!query.includes('__schema')) { // is a mutation - console.log(req) - req.reply({ - data: { - [req.body.operationName]: { - result: [true, {}], - __typename: upperFirst(req.body.operationName) - } + cy.intercept('/graphql', (req) => { + const { query } = req.body + if (query.startsWith('mutation')) { + console.log(req) + req.reply({ + data: { + [req.body.operationName]: { + result: [true, {}], + __typename: upperFirst(req.body.operationName) } - }) - } - }) + } + }) + } + }) }) /**