|
| 1 | +/***************************************************************************** |
| 2 | + * Open MCT, Copyright (c) 2014-2024, United States Government |
| 3 | + * as represented by the Administrator of the National Aeronautics and Space |
| 4 | + * Administration. All rights reserved. |
| 5 | + * |
| 6 | + * Open MCT is licensed under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0. |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | + * License for the specific language governing permissions and limitations |
| 15 | + * under the License. |
| 16 | + * |
| 17 | + * Open MCT includes source code licensed under additional open source |
| 18 | + * licenses. See the Open Source Licenses file (LICENSES.md) included with |
| 19 | + * this source code distribution or the Licensing information page available |
| 20 | + * at runtime from the About dialog for additional information. |
| 21 | + *****************************************************************************/ |
| 22 | + |
| 23 | +/* |
| 24 | +Tests to verify log plot functionality when objects are missing |
| 25 | +*/ |
| 26 | + |
| 27 | +import { createDomainObjectWithDefaults } from '../../../../appActions.js'; |
| 28 | +import { expect, test } from '../../../../pluginFixtures.js'; |
| 29 | + |
| 30 | +const SWG_NAME = 'Sine Wave Generator'; |
| 31 | +const OVERLAY_PLOT_NAME = 'Overlay Plot'; |
| 32 | +const STACKED_PLOT_NAME = 'Stacked Plot'; |
| 33 | + |
| 34 | +test.describe('For a default Plot View, Plot View Action:', () => { |
| 35 | + let download; |
| 36 | + |
| 37 | + test.beforeEach(async ({ page }) => { |
| 38 | + await page.goto('./', { waitUntil: 'domcontentloaded' }); |
| 39 | + |
| 40 | + const plot = await createDomainObjectWithDefaults(page, { |
| 41 | + type: SWG_NAME, |
| 42 | + name: SWG_NAME |
| 43 | + }); |
| 44 | + |
| 45 | + await page.goto(plot.url); |
| 46 | + |
| 47 | + // Set up dialog handler before clicking the export button |
| 48 | + await page.getByLabel('More actions').click(); |
| 49 | + }); |
| 50 | + |
| 51 | + test.afterEach(async ({ page }) => { |
| 52 | + if (download) { |
| 53 | + await download.cancel(); |
| 54 | + } |
| 55 | + }); |
| 56 | + |
| 57 | + test('Export as PNG, will suggest the correct default filename', async ({ page }) => { |
| 58 | + // Start waiting for download before clicking. Note no await. |
| 59 | + const downloadPromise = page.waitForEvent('download'); |
| 60 | + |
| 61 | + // trigger the download |
| 62 | + await page.getByLabel('Export as PNG').click(); |
| 63 | + |
| 64 | + download = await downloadPromise; |
| 65 | + |
| 66 | + // Verify the filename contains the expected pattern |
| 67 | + expect(download.suggestedFilename()).toBe(`${SWG_NAME} - plot.png`); |
| 68 | + }); |
| 69 | + |
| 70 | + test('Export as JPG, will suggest the correct default filename', async ({ page }) => { |
| 71 | + // Start waiting for download before clicking. Note no await. |
| 72 | + const downloadPromise = page.waitForEvent('download'); |
| 73 | + |
| 74 | + // trigger the download |
| 75 | + await page.getByLabel('Export as JPG').click(); |
| 76 | + |
| 77 | + download = await downloadPromise; |
| 78 | + |
| 79 | + // Verify the filename contains the expected pattern |
| 80 | + expect(download.suggestedFilename()).toBe(`${SWG_NAME} - plot.jpeg`); |
| 81 | + }); |
| 82 | +}); |
| 83 | + |
| 84 | +test.describe('For an Overlay Plot View, Plot View Action:', () => { |
| 85 | + let download; |
| 86 | + |
| 87 | + test.beforeEach(async ({ page }) => { |
| 88 | + await page.goto('./', { waitUntil: 'domcontentloaded' }); |
| 89 | + |
| 90 | + const overlayPlot = await createDomainObjectWithDefaults(page, { |
| 91 | + type: OVERLAY_PLOT_NAME, |
| 92 | + name: OVERLAY_PLOT_NAME |
| 93 | + }); |
| 94 | + |
| 95 | + await createDomainObjectWithDefaults(page, { |
| 96 | + type: SWG_NAME, |
| 97 | + name: SWG_NAME, |
| 98 | + parent: overlayPlot.uuid |
| 99 | + }); |
| 100 | + |
| 101 | + await page.goto(overlayPlot.url); |
| 102 | + |
| 103 | + // Set up dialog handler before clicking the export button |
| 104 | + await page.getByLabel('More actions').click(); |
| 105 | + }); |
| 106 | + |
| 107 | + test.afterEach(async ({ page }) => { |
| 108 | + if (download) { |
| 109 | + await download.cancel(); |
| 110 | + } |
| 111 | + }); |
| 112 | + |
| 113 | + test('Export as PNG, will suggest the correct default filename', async ({ page }) => { |
| 114 | + // Start waiting for download before clicking. Note no await. |
| 115 | + const downloadPromise = page.waitForEvent('download'); |
| 116 | + |
| 117 | + // trigger the download |
| 118 | + await page.getByLabel('Export as PNG').click(); |
| 119 | + |
| 120 | + download = await downloadPromise; |
| 121 | + |
| 122 | + // Verify the filename contains the expected pattern |
| 123 | + expect(download.suggestedFilename()).toBe(`${OVERLAY_PLOT_NAME} - plot.png`); |
| 124 | + }); |
| 125 | + |
| 126 | + test('Export as JPG, will suggest the correct default filename', async ({ page }) => { |
| 127 | + // Start waiting for download before clicking. Note no await. |
| 128 | + const downloadPromise = page.waitForEvent('download'); |
| 129 | + |
| 130 | + // trigger the download |
| 131 | + await page.getByLabel('Export as JPG').click(); |
| 132 | + |
| 133 | + download = await downloadPromise; |
| 134 | + |
| 135 | + // Verify the filename contains the expected pattern |
| 136 | + expect(download.suggestedFilename()).toBe(`${OVERLAY_PLOT_NAME} - plot.jpeg`); |
| 137 | + }); |
| 138 | +}); |
| 139 | + |
| 140 | +test.describe('For a Stacked Plot View, Plot View Action:', () => { |
| 141 | + let download; |
| 142 | + |
| 143 | + test.beforeEach(async ({ page }) => { |
| 144 | + await page.goto('./', { waitUntil: 'domcontentloaded' }); |
| 145 | + |
| 146 | + const stackedPlot = await createDomainObjectWithDefaults(page, { |
| 147 | + type: STACKED_PLOT_NAME, |
| 148 | + name: STACKED_PLOT_NAME |
| 149 | + }); |
| 150 | + |
| 151 | + await createDomainObjectWithDefaults(page, { |
| 152 | + type: SWG_NAME, |
| 153 | + name: SWG_NAME, |
| 154 | + parent: stackedPlot.uuid |
| 155 | + }); |
| 156 | + |
| 157 | + await page.goto(stackedPlot.url); |
| 158 | + |
| 159 | + // Set up dialog handler before clicking the export button |
| 160 | + await page.getByLabel('More actions').click(); |
| 161 | + }); |
| 162 | + |
| 163 | + test.afterEach(async ({ page }) => { |
| 164 | + if (download) { |
| 165 | + await download.cancel(); |
| 166 | + } |
| 167 | + }); |
| 168 | + |
| 169 | + test('Export as PNG, will suggest the correct default filename', async ({ page }) => { |
| 170 | + // Start waiting for download before clicking. Note no await. |
| 171 | + const downloadPromise = page.waitForEvent('download'); |
| 172 | + |
| 173 | + // trigger the download |
| 174 | + await page.getByLabel('Export as PNG').click(); |
| 175 | + |
| 176 | + download = await downloadPromise; |
| 177 | + |
| 178 | + // Verify the filename contains the expected pattern |
| 179 | + expect(download.suggestedFilename()).toBe(`${STACKED_PLOT_NAME} - stacked-plot.png`); |
| 180 | + }); |
| 181 | + |
| 182 | + test('Export as JPG, will suggest the correct default filename', async ({ page }) => { |
| 183 | + // Start waiting for download before clicking. Note no await. |
| 184 | + const downloadPromise = page.waitForEvent('download'); |
| 185 | + |
| 186 | + // trigger the download |
| 187 | + await page.getByLabel('Export as JPG').click(); |
| 188 | + |
| 189 | + download = await downloadPromise; |
| 190 | + |
| 191 | + // Verify the filename contains the expected pattern |
| 192 | + expect(download.suggestedFilename()).toBe(`${STACKED_PLOT_NAME} - stacked-plot.jpeg`); |
| 193 | + }); |
| 194 | +}); |
| 195 | + |
| 196 | +test.describe('Plot View Action:', () => { |
| 197 | + let download; |
| 198 | + |
| 199 | + test.beforeEach(async ({ page }) => { |
| 200 | + await page.goto('./', { waitUntil: 'domcontentloaded' }); |
| 201 | + |
| 202 | + const plot = await createDomainObjectWithDefaults(page, { |
| 203 | + type: SWG_NAME, |
| 204 | + name: `!@#${SWG_NAME}!@#><` |
| 205 | + }); |
| 206 | + |
| 207 | + await page.goto(plot.url); |
| 208 | + |
| 209 | + // Set up dialog handler before clicking the export button |
| 210 | + await page.getByLabel('More actions').click(); |
| 211 | + }); |
| 212 | + |
| 213 | + test.afterEach(async ({ page }) => { |
| 214 | + if (download) { |
| 215 | + await download.cancel(); |
| 216 | + } |
| 217 | + }); |
| 218 | + |
| 219 | + test('Export as PNG saved filenames will not include invalid characters', async ({ page }) => { |
| 220 | + // Start waiting for download before clicking. Note no await. |
| 221 | + const downloadPromise = page.waitForEvent('download'); |
| 222 | + |
| 223 | + // trigger the download |
| 224 | + await page.getByLabel('Export as PNG').click(); |
| 225 | + |
| 226 | + download = await downloadPromise; |
| 227 | + |
| 228 | + // Verify the filename contains the expected pattern |
| 229 | + expect(download.suggestedFilename()).toBe(`${SWG_NAME} - plot.png`); |
| 230 | + }); |
| 231 | + |
| 232 | + test('Export as JPG saved filenames will not include invalid characters', async ({ page }) => { |
| 233 | + // Start waiting for download before clicking. Note no await. |
| 234 | + const downloadPromise = page.waitForEvent('download'); |
| 235 | + |
| 236 | + // trigger the download |
| 237 | + await page.getByLabel('Export as JPG').click(); |
| 238 | + |
| 239 | + download = await downloadPromise; |
| 240 | + |
| 241 | + // Verify the filename contains the expected pattern |
| 242 | + expect(download.suggestedFilename()).toBe(`${SWG_NAME} - plot.jpeg`); |
| 243 | + }); |
| 244 | +}); |
0 commit comments