|
| 1 | +import { test, expect } from '@playwright/test' |
| 2 | +const plotName = 'Test plot' |
| 3 | + |
| 4 | +test('Open Sample Plot, apply time filter, and step forward in time', async ({ page }) => { |
| 5 | + // Navigate to the application |
| 6 | + await page.goto('/') |
| 7 | + |
| 8 | + // Wait for the application to load |
| 9 | + await page.waitForSelector('button:has-text("Sample plot")') |
| 10 | + |
| 11 | + // Click on Sample Plot button to create a new sample plot |
| 12 | + await page.click('button:has-text("Sample plot")') |
| 13 | + |
| 14 | + // Wait for the document name modal to appear |
| 15 | + await page.waitForSelector('div.ant-modal-content') |
| 16 | + |
| 17 | + // Enter a name for the document in the input field |
| 18 | + await page.locator('input.ant-input').fill(plotName) |
| 19 | + |
| 20 | + // Click the OK button to confirm |
| 21 | + await page.locator('button:has-text("OK")').click() |
| 22 | + |
| 23 | + // Wait for the plot to load after modal confirmation |
| 24 | + await page.waitForSelector('.flexlayout__tab_button_content') |
| 25 | + await page.waitForSelector('.step-forward') |
| 26 | + |
| 27 | + // Verify that the plot has been created |
| 28 | + expect (await page.locator('.flexlayout__tab_button_content').first().textContent()).toEqual(plotName) |
| 29 | + |
| 30 | + // Find the step forward button (TimeButton component with StepForwardOutlined icon) |
| 31 | + // Based on the application code, it's a button with tooltip 'Step forward' |
| 32 | + const stepForwardButton = page.locator('.step-forward') |
| 33 | + |
| 34 | + // Check if the TimePeriod component is visible |
| 35 | + await expect(page.locator('.time-period-panel')).toBeVisible() |
| 36 | + |
| 37 | + // check the time start and end are outer period of data |
| 38 | + const timeStart = page.locator('.time-start-txt') |
| 39 | + const timeEnd = page.locator('.time-end-txt') |
| 40 | + expect(await timeStart.textContent()).toEqual('Nov 141616Z') |
| 41 | + expect(await timeEnd.textContent()).toEqual('Nov 151017Z') |
| 42 | + |
| 43 | + // Get the initial time text before any actions |
| 44 | + const timeTextBeforeFilter = await page.locator('.time-period-panel p').textContent() |
| 45 | + console.log('Time period before filter:', timeTextBeforeFilter) |
| 46 | + |
| 47 | + // check time step buttons are disabled |
| 48 | + await expect(page.locator('.step-forward')).toBeDisabled() |
| 49 | + await expect(page.locator('.step-backward')).toBeDisabled() |
| 50 | + |
| 51 | + // Get the time text after clicking step forward (should be unchanged) |
| 52 | + const timeTextAfterClick = await page.locator('.time-period-panel p').textContent() |
| 53 | + console.log('Time period after clicking step forward (before filter):', timeTextAfterClick) |
| 54 | + |
| 55 | + // Verify that the time text has NOT changed (because filter is not applied) |
| 56 | + expect(timeTextAfterClick).toEqual(timeTextBeforeFilter) |
| 57 | + console.log('Verified: Time period did not change when filter is not applied') |
| 58 | + |
| 59 | + // Find and click the time filter button in the control panel |
| 60 | + // Based on the application code, it's a button with FilterOutlined/FilterFilled icon |
| 61 | + const timeFilterButton = page.locator('.apply-time-filter') |
| 62 | + |
| 63 | + // Check the time filter is currently disabled |
| 64 | + await expect(page.locator('.time-step-input')).toHaveClass(/.*ant-select-disabled.*/) |
| 65 | + |
| 66 | + // Alternative selector if the above doesn't work |
| 67 | + // const timeFilterButton = page.locator('button', { has: page.locator('.anticon-filter, .anticon-filter-filled') }) |
| 68 | + await timeFilterButton.click() |
| 69 | + |
| 70 | + // check the time start and end are clipped to new values |
| 71 | + expect(await timeStart.textContent()).toEqual('Nov 141600Z') |
| 72 | + expect(await timeEnd.textContent()).toEqual('Nov 141700Z') |
| 73 | + |
| 74 | + // Verify that the form containing the time-step-input is no longer disabled |
| 75 | + // This is a more accurate way to confirm the time filter is active |
| 76 | + await expect(page.locator('.time-step-input')).not.toHaveClass(/.*ant-select-disabled.*/) |
| 77 | + |
| 78 | + // Now click the step forward button after applying the filter (should work now) |
| 79 | + await stepForwardButton.click() |
| 80 | + |
| 81 | + // Verify that the time has changed after stepping forward |
| 82 | + |
| 83 | + // Wait for any animations or updates to complete |
| 84 | + await page.waitForTimeout(500) |
| 85 | + |
| 86 | + // Now specifically check that the TimePeriod component is visible |
| 87 | + await expect(page.locator('.time-period-panel')).toBeVisible() |
| 88 | + |
| 89 | + // Get the text content of the TimePeriod before stepping forward |
| 90 | + const initialTimeText = await page.locator('.time-period-panel p').textContent() |
| 91 | + console.log('Initial time period:', initialTimeText) |
| 92 | + |
| 93 | + // Click the step forward button again |
| 94 | + await stepForwardButton.click() |
| 95 | + |
| 96 | + // Wait for the time to update |
| 97 | + await page.waitForTimeout(500) |
| 98 | + |
| 99 | + // Get the updated text content |
| 100 | + const updatedTimeText = await page.locator('.time-period-panel p').textContent() |
| 101 | + console.log('Updated time period:', updatedTimeText) |
| 102 | + |
| 103 | + // Verify that the time text has changed |
| 104 | + expect(updatedTimeText).not.toEqual(initialTimeText) |
| 105 | + console.log('Time period changed successfully from', initialTimeText, 'to', updatedTimeText) |
| 106 | + |
| 107 | + // check the time start and end times have moved forwards |
| 108 | + expect(await timeStart.textContent()).toEqual('Nov 141800Z') |
| 109 | + expect(await timeEnd.textContent()).toEqual('Nov 141900Z') |
| 110 | + |
| 111 | + // get the large step fowards button |
| 112 | + const largeStepForwardButton = page.locator('.jump-to-end') |
| 113 | + await largeStepForwardButton.click() |
| 114 | + |
| 115 | + // Wait for the time to update |
| 116 | + await page.waitForTimeout(500) |
| 117 | + |
| 118 | + // Get the updated text content |
| 119 | + const updatedTimeText2 = await page.locator('.time-period-panel p').textContent() |
| 120 | + console.log('Updated time period:', updatedTimeText2) |
| 121 | + |
| 122 | + // Verify that the time text has changed |
| 123 | + expect(updatedTimeText2).not.toEqual(initialTimeText) |
| 124 | + console.log('Time period changed successfully from', initialTimeText, 'to', updatedTimeText2) |
| 125 | + |
| 126 | + // check the time start and end times have moved to end |
| 127 | + expect(await timeStart.textContent()).toEqual('Nov 151000Z') |
| 128 | + expect(await timeEnd.textContent()).toEqual('Nov 151100Z') |
| 129 | + |
| 130 | + // get the large step backwards button |
| 131 | + const largeStepBackButton = page.locator('.jump-to-start') |
| 132 | + await largeStepBackButton.click() |
| 133 | + |
| 134 | + // Wait for the time to update |
| 135 | + await page.waitForTimeout(500) |
| 136 | + |
| 137 | + // check the time start and end times have moved to start |
| 138 | + expect(await timeStart.textContent()).toEqual('Nov 141600Z') |
| 139 | + expect(await timeEnd.textContent()).toEqual('Nov 141700Z') |
| 140 | + |
| 141 | + // disable time filter |
| 142 | + await timeFilterButton.click() |
| 143 | + |
| 144 | + // Wait for the time to update |
| 145 | + await page.waitForTimeout(500) |
| 146 | + |
| 147 | + // check time step interval is disabled |
| 148 | + await expect(page.locator('.time-step-input')).toHaveClass(/.*ant-select-disabled.*/) |
| 149 | + |
| 150 | + // check time step buttons are disabled |
| 151 | + await expect(page.locator('.step-forward')).toBeDisabled() |
| 152 | + await expect(page.locator('.step-backward')).toBeDisabled() |
| 153 | +}) |
0 commit comments