From cf5edf2db09fc2dafba0e50acf53c32e9c35f0cb Mon Sep 17 00:00:00 2001 From: Syed Tasnim Ahmed <55814513+SyedAhmedCU@users.noreply.github.com> Date: Thu, 24 Mar 2022 08:10:32 -0400 Subject: [PATCH] [clock] Timezone dropdown will collapse when clicked outside or on dropdown icon again (#4956) * Fix timezone dropdown collapse issue * Dropdown should collapse when click outside * Fix Lint error * add e2e test for autocomplete * updates based of code review * Typo fixed * Modification based on review Co-authored-by: Scott Bell --- e2e/tests/example/generator/Clock.e2e.spec.js | 66 +++++++++++++++++++ src/api/forms/FormController.js | 6 +- .../components/controls/AutoCompleteField.vue | 54 +++++++++++---- 3 files changed, 113 insertions(+), 13 deletions(-) create mode 100644 e2e/tests/example/generator/Clock.e2e.spec.js diff --git a/e2e/tests/example/generator/Clock.e2e.spec.js b/e2e/tests/example/generator/Clock.e2e.spec.js new file mode 100644 index 0000000000..7ff0274c81 --- /dev/null +++ b/e2e/tests/example/generator/Clock.e2e.spec.js @@ -0,0 +1,66 @@ +/***************************************************************************** + * Open MCT, Copyright (c) 2014-2022, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * Open MCT is licensed under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * Open MCT includes source code licensed under additional open source + * licenses. See the Open Source Licenses file (LICENSES.md) included with + * this source code distribution or the Licensing information page available + * at runtime from the About dialog for additional information. + *****************************************************************************/ + +/* +This test suite is dedicated to tests which verify the basic operations surrounding Clock. +*/ + +const { test, expect } = require('@playwright/test'); + +test.describe('Clock Generator', () => { + + test('Timezone dropdown will collapse when clicked outside or on dropdown icon again', async ({ page }) => { + test.info().annotations.push({ + type: 'issue', + description: 'https://github.com/nasa/openmct/issues/4878' + }); + //Go to baseURL + await page.goto('/', { waitUntil: 'networkidle' }); + + //Click the Create button + await page.click('button:has-text("Create")'); + + // Click Clock + await page.click('text=Clock'); + + // Click .icon-arrow-down + await page.locator('.icon-arrow-down').click(); + //verify if the autocomplete dropdown is visible + await expect(page.locator(".optionPreSelected")).toBeVisible(); + // Click .icon-arrow-down + await page.locator('.icon-arrow-down').click(); + + // Verify clicking on the autocomplete arrow collapses the dropdown + await expect(page.locator(".optionPreSelected")).not.toBeVisible(); + + // Click timezone input to open dropdown + await page.locator('.autocompleteInput').click(); + //verify if the autocomplete dropdown is visible + await expect(page.locator(".optionPreSelected")).toBeVisible(); + + // Verify clicking outside the autocomplete dropdown collapses it + await page.locator('text=Timezone').click(); + // Verify clicking on the autocomplete arrow collapses the dropdown + await expect(page.locator(".optionPreSelected")).not.toBeVisible(); + + }); +}); diff --git a/src/api/forms/FormController.js b/src/api/forms/FormController.js index a1cadcaeb5..95a5b4a28f 100644 --- a/src/api/forms/FormController.js +++ b/src/api/forms/FormController.js @@ -65,10 +65,11 @@ export default class FormControl { */ _getControlViewProvider(control) { const self = this; + let rowComponent; return { show(element, model, onChange) { - const rowComponent = new Vue({ + rowComponent = new Vue({ el: element, components: { FormControlComponent: DEFAULT_CONTROLS_MAP[control] @@ -86,6 +87,9 @@ export default class FormControl { }); return rowComponent; + }, + destroy() { + rowComponent.$destroy(); } }; } diff --git a/src/api/forms/components/controls/AutoCompleteField.vue b/src/api/forms/components/controls/AutoCompleteField.vue index 91d58a31f7..1c6e2aad8f 100644 --- a/src/api/forms/components/controls/AutoCompleteField.vue +++ b/src/api/forms/components/controls/AutoCompleteField.vue @@ -22,17 +22,19 @@