|
| 1 | +import {Page} from 'puppeteer'; |
| 2 | +import {newTest, GotifyTest} from './setup'; |
| 3 | +import {clickByText, ClientCol, count, waitForExists, waitToDisappear} from './utils'; |
| 4 | +import {afterAll, beforeAll, describe, expect, it} from 'vitest'; |
| 5 | +import * as auth from './authentication'; |
| 6 | +import * as selector from './selector'; |
| 7 | + |
| 8 | +let page: Page; |
| 9 | +let gotify: GotifyTest; |
| 10 | +beforeAll(async () => { |
| 11 | + gotify = await newTest(); |
| 12 | + page = gotify.page; |
| 13 | +}); |
| 14 | + |
| 15 | +afterAll(async () => await gotify.close()); |
| 16 | + |
| 17 | +const $clientTable = selector.table('#client-table'); |
| 18 | +const $clientDialog = selector.form('#client-dialog'); |
| 19 | + |
| 20 | +// This expects the session to be already elevated. |
| 21 | +const cancelElevationViaUI = async (row: number) => { |
| 22 | + await page.goto(gotify.url + '/#/clients'); |
| 23 | + await waitForExists(page, selector.heading(), 'Clients'); |
| 24 | + |
| 25 | + await page.click($clientTable.cell(row, ClientCol.Elevate, '.elevate')); |
| 26 | + await page.waitForSelector('.elevate-client-dialog'); |
| 27 | + |
| 28 | + await page.click('.elevate-client-dialog .elevate-duration [role=combobox]'); |
| 29 | + await clickByText(page, '[role="option"]', 'Cancel elevation'); |
| 30 | + await waitToDisappear(page, '[role="listbox"]'); |
| 31 | + |
| 32 | + await page.click('.elevate-client-dialog .elevate-confirm'); |
| 33 | + await waitToDisappear(page, '.elevate-client-dialog'); |
| 34 | +}; |
| 35 | + |
| 36 | +const elevateViaForm = async (password: string) => { |
| 37 | + const passwordInput = '.elevation-password input'; |
| 38 | + await page.waitForSelector(passwordInput); |
| 39 | + await page.type(passwordInput, password); |
| 40 | + await page.click('.elevation-submit'); |
| 41 | +}; |
| 42 | + |
| 43 | +describe('Elevation', () => { |
| 44 | + it('does login', async () => await auth.login(page)); |
| 45 | + |
| 46 | + describe('setup', () => { |
| 47 | + it('navigates to clients', async () => { |
| 48 | + await page.click('#navigate-clients'); |
| 49 | + await waitForExists(page, selector.heading(), 'Clients'); |
| 50 | + }); |
| 51 | + it('creates a test client', async () => { |
| 52 | + await page.click('#create-client'); |
| 53 | + await page.waitForSelector($clientDialog.selector()); |
| 54 | + await page.type($clientDialog.input('.name'), 'test-client'); |
| 55 | + await page.click($clientDialog.button('.create')); |
| 56 | + await waitToDisappear(page, $clientDialog.selector()); |
| 57 | + await page.waitForSelector($clientTable.row(2)); |
| 58 | + expect(await count(page, $clientTable.rows())).toBe(2); |
| 59 | + }); |
| 60 | + }); |
| 61 | + |
| 62 | + describe('Users page requires elevation', () => { |
| 63 | + it('de-elevates the current client via UI', () => cancelElevationViaUI(1)); |
| 64 | + it('navigates to users and sees elevation form', async () => { |
| 65 | + await page.goto(gotify.url + '/#/users'); |
| 66 | + await waitForExists(page, selector.heading(), 'Authentication Required'); |
| 67 | + await page.waitForSelector('.elevation-password input'); |
| 68 | + }); |
| 69 | + it('elevates via password and sees users page', async () => { |
| 70 | + await elevateViaForm('admin'); |
| 71 | + await waitForExists(page, selector.heading(), 'Users'); |
| 72 | + expect(page.url()).toContain('/users'); |
| 73 | + }); |
| 74 | + }); |
| 75 | + |
| 76 | + describe('Client delete requires elevation', () => { |
| 77 | + it('de-elevates the current client via UI', () => cancelElevationViaUI(1)); |
| 78 | + it('navigates to clients', async () => { |
| 79 | + await page.goto(gotify.url + '/#/clients'); |
| 80 | + await waitForExists(page, selector.heading(), 'Clients'); |
| 81 | + }); |
| 82 | + it('clicks delete and sees elevation form in dialog', async () => { |
| 83 | + await page.click($clientTable.cell(2, ClientCol.Delete, '.delete')); |
| 84 | + await page.waitForSelector(selector.$confirmDialog.selector()); |
| 85 | + await page.waitForSelector('.confirm-dialog .elevation-password input'); |
| 86 | + }); |
| 87 | + it('elevates', () => elevateViaForm('admin')); |
| 88 | + it('confirms deletion', async () => { |
| 89 | + await page.waitForSelector(selector.$confirmDialog.button('.confirm')); |
| 90 | + await page.click(selector.$confirmDialog.button('.confirm')); |
| 91 | + }); |
| 92 | + it('has deleted the client', async () => { |
| 93 | + await waitToDisappear(page, $clientTable.row(2)); |
| 94 | + expect(await count(page, $clientTable.rows())).toBe(1); |
| 95 | + }); |
| 96 | + }); |
| 97 | +}); |
0 commit comments