|
| 1 | +import { |
| 2 | + expect, |
| 3 | + findClearTracesButton, |
| 4 | + prepareDevDebuggerPairTest, |
| 5 | + Page, |
| 6 | + findSwitchTracingButton, |
| 7 | +} from './dev-dbg-test'; |
| 8 | + |
| 9 | +const test = prepareDevDebuggerPairTest(); |
| 10 | + |
| 11 | +const termEntry = ( |
| 12 | + page: Page, |
| 13 | + containerId: string, |
| 14 | + key: string, |
| 15 | + value: string |
| 16 | +) => |
| 17 | + page.locator( |
| 18 | + `xpath=//*[@id="${containerId}"]//*[contains(normalize-space(text()), "${key}:")]/../..//*[contains(normalize-space(text()), "${value}")]` |
| 19 | + ); |
| 20 | + |
| 21 | +const showButton = async (page: Page, selector: string) => { |
| 22 | + await page.evaluate((sel) => { |
| 23 | + const el = document.querySelector(sel); |
| 24 | + if (el) (el as HTMLElement).style.display = 'block'; |
| 25 | + }, selector); |
| 26 | +}; |
| 27 | + |
| 28 | +const clickPinButton = async (page: Page, assignKey: string) => { |
| 29 | + const selector = `#all-assigns button[phx-click="pin-assign"][phx-value-key="${assignKey}"]`; |
| 30 | + await showButton(page, selector); |
| 31 | + await page.locator(selector).click(); |
| 32 | +}; |
| 33 | + |
| 34 | +const clickUnpinButton = async (page: Page, assignKey: string) => { |
| 35 | + const selector = `#pinned-assigns button[phx-click="unpin-assign"][phx-value-key="${assignKey}"]`; |
| 36 | + await showButton(page, selector); |
| 37 | + await page.locator(selector).click(); |
| 38 | +}; |
| 39 | + |
| 40 | +test('user can search assigns using the searchbar', async ({ dbgApp }) => { |
| 41 | + await expect(termEntry(dbgApp, 'all-assigns', 'counter', '0')).toBeVisible(); |
| 42 | + |
| 43 | + await expect( |
| 44 | + dbgApp.locator('#all-assigns pre').filter({ hasText: '"deep value"' }) |
| 45 | + ).not.toBeVisible(); |
| 46 | + |
| 47 | + await dbgApp.locator('#assigns-search-input').fill('deep value'); |
| 48 | + await expect( |
| 49 | + dbgApp.locator('#all-assigns pre').filter({ hasText: '"deep value"' }) |
| 50 | + ).toBeVisible(); |
| 51 | + |
| 52 | + await dbgApp.reload(); |
| 53 | + |
| 54 | + await dbgApp.locator('button[aria-label="Icon expand"]').click(); |
| 55 | + |
| 56 | + await expect( |
| 57 | + dbgApp |
| 58 | + .locator('#all-assigns-fullscreen pre') |
| 59 | + .filter({ hasText: '"deep value"' }) |
| 60 | + ).not.toBeVisible(); |
| 61 | + |
| 62 | + await dbgApp.locator('#assigns-search-input-fullscreen').fill('deep value'); |
| 63 | + await expect( |
| 64 | + dbgApp |
| 65 | + .locator('#all-assigns-fullscreen pre') |
| 66 | + .filter({ hasText: '"deep value"' }) |
| 67 | + ).toBeVisible(); |
| 68 | +}); |
| 69 | + |
| 70 | +test('user can pin and unpin specific assigns', async ({ devApp, dbgApp }) => { |
| 71 | + await expect(dbgApp.locator('#pinned-assigns')).toContainText( |
| 72 | + 'No pinned assigns' |
| 73 | + ); |
| 74 | + |
| 75 | + await clickPinButton(dbgApp, 'counter'); |
| 76 | + await expect( |
| 77 | + termEntry(dbgApp, 'pinned-assigns', 'counter', '0') |
| 78 | + ).toBeVisible(); |
| 79 | + |
| 80 | + await devApp.locator('#increment-button').click(); |
| 81 | + await devApp.locator('#increment-button').click(); |
| 82 | + await devApp.locator('#send-button').click(); |
| 83 | + |
| 84 | + await expect(termEntry(dbgApp, 'all-assigns', 'counter', '2')).toBeVisible(); |
| 85 | + await expect( |
| 86 | + termEntry(dbgApp, 'pinned-assigns', 'counter', '2') |
| 87 | + ).toBeVisible(); |
| 88 | + |
| 89 | + await clickUnpinButton(dbgApp, 'counter'); |
| 90 | + await expect(dbgApp.locator('#pinned-assigns')).toContainText( |
| 91 | + 'No pinned assigns' |
| 92 | + ); |
| 93 | +}); |
| 94 | + |
| 95 | +test('user can see temporary assigns', async ({ devApp, dbgApp }) => { |
| 96 | + await expect( |
| 97 | + termEntry(dbgApp, 'temporary-assigns', 'message', 'nil') |
| 98 | + ).toBeVisible(); |
| 99 | + |
| 100 | + await devApp.locator('#append-message').click(); |
| 101 | + await expect( |
| 102 | + termEntry(dbgApp, 'temporary-assigns', 'message', '%{...}') |
| 103 | + ).toBeVisible(); |
| 104 | + |
| 105 | + await devApp.locator('#increment-button').click(); |
| 106 | + await expect( |
| 107 | + termEntry(dbgApp, 'temporary-assigns', 'message', '%{...}') |
| 108 | + ).toBeVisible(); |
| 109 | + |
| 110 | + await devApp.goto('/nested'); |
| 111 | + await dbgApp.getByRole('button', { name: 'Continue' }).click(); |
| 112 | + |
| 113 | + await expect(dbgApp.locator('#temporary-assigns')).toContainText( |
| 114 | + 'No temporary assigns' |
| 115 | + ); |
| 116 | +}); |
| 117 | + |
| 118 | +test('user can go through assigns change history', async ({ |
| 119 | + devApp, |
| 120 | + dbgApp, |
| 121 | +}) => { |
| 122 | + await devApp.locator('#increment-button').click(); |
| 123 | + await devApp.locator('#increment-button').click(); |
| 124 | + await devApp.locator('#send-button').click(); |
| 125 | + |
| 126 | + await dbgApp |
| 127 | + .locator('#all-assigns button[phx-click="open-assigns-history"]') |
| 128 | + .click(); |
| 129 | + |
| 130 | + await expect( |
| 131 | + termEntry(dbgApp, 'history-old-assigns', 'counter', '2') |
| 132 | + ).toBeVisible(); |
| 133 | + await expect( |
| 134 | + termEntry(dbgApp, 'history-old-assigns', 'datetime', 'nil') |
| 135 | + ).toBeVisible(); |
| 136 | + await expect( |
| 137 | + termEntry(dbgApp, 'history-new-assigns', 'counter', '2') |
| 138 | + ).toBeVisible(); |
| 139 | + await expect( |
| 140 | + termEntry(dbgApp, 'history-new-assigns', 'datetime', '~U[') |
| 141 | + ).toBeVisible(); |
| 142 | + |
| 143 | + await dbgApp.locator('button[phx-click="go-back"]').click(); |
| 144 | + await expect( |
| 145 | + termEntry(dbgApp, 'history-old-assigns', 'counter', '1') |
| 146 | + ).toBeVisible(); |
| 147 | + await expect( |
| 148 | + termEntry(dbgApp, 'history-old-assigns', 'datetime', 'nil') |
| 149 | + ).toBeVisible(); |
| 150 | + await expect( |
| 151 | + termEntry(dbgApp, 'history-new-assigns', 'counter', '2') |
| 152 | + ).toBeVisible(); |
| 153 | + await expect( |
| 154 | + termEntry(dbgApp, 'history-new-assigns', 'datetime', 'nil') |
| 155 | + ).toBeVisible(); |
| 156 | + |
| 157 | + await dbgApp.locator('button[phx-click="go-forward"]').click(); |
| 158 | + await expect( |
| 159 | + termEntry(dbgApp, 'history-old-assigns', 'counter', '2') |
| 160 | + ).toBeVisible(); |
| 161 | + await expect( |
| 162 | + termEntry(dbgApp, 'history-old-assigns', 'datetime', 'nil') |
| 163 | + ).toBeVisible(); |
| 164 | + await expect( |
| 165 | + termEntry(dbgApp, 'history-new-assigns', 'counter', '2') |
| 166 | + ).toBeVisible(); |
| 167 | + await expect( |
| 168 | + termEntry(dbgApp, 'history-new-assigns', 'datetime', '~U[') |
| 169 | + ).toBeVisible(); |
| 170 | + |
| 171 | + await dbgApp.locator('button[phx-click="go-back-end"]').click(); |
| 172 | + await expect( |
| 173 | + termEntry(dbgApp, 'history-new-assigns', 'counter', '0') |
| 174 | + ).toBeVisible(); |
| 175 | + await expect( |
| 176 | + termEntry(dbgApp, 'history-new-assigns', 'datetime', 'nil') |
| 177 | + ).toBeVisible(); |
| 178 | + |
| 179 | + await dbgApp.locator('button[phx-click="go-forward-end"]').click(); |
| 180 | + await expect( |
| 181 | + termEntry(dbgApp, 'history-new-assigns', 'counter', '2') |
| 182 | + ).toBeVisible(); |
| 183 | + await expect( |
| 184 | + termEntry(dbgApp, 'history-new-assigns', 'datetime', '~U[') |
| 185 | + ).toBeVisible(); |
| 186 | + |
| 187 | + await devApp.locator('#increment-button').click(); |
| 188 | + await devApp.locator('#increment-button').click(); |
| 189 | + |
| 190 | + await expect( |
| 191 | + termEntry(dbgApp, 'history-old-assigns', 'counter', '3') |
| 192 | + ).toBeVisible(); |
| 193 | + await expect( |
| 194 | + termEntry(dbgApp, 'history-new-assigns', 'counter', '4') |
| 195 | + ).toBeVisible(); |
| 196 | + |
| 197 | + await dbgApp.locator('#assigns-history-close').click(); |
| 198 | + await findSwitchTracingButton(dbgApp).click(); |
| 199 | + await findClearTracesButton(dbgApp).click(); |
| 200 | + await dbgApp |
| 201 | + .locator('#all-assigns button[phx-click="open-assigns-history"]') |
| 202 | + .click(); |
| 203 | + await expect(dbgApp.locator('#assigns-history')).toContainText( |
| 204 | + 'No history records' |
| 205 | + ); |
| 206 | +}); |
0 commit comments