|
| 1 | +import { authTest, expect } from '../../fixtures/auth.fixture' |
| 2 | +import { |
| 3 | + AdminUrlUtil, |
| 4 | + CollectionSlugs, |
| 5 | + getSelectInputOptions, |
| 6 | + getSelectInputValue, |
| 7 | + openDocControls, |
| 8 | + selectInput, |
| 9 | + waitForFormReady, |
| 10 | +} from '../../helpers' |
| 11 | + |
| 12 | +const SERVER_URL = 'http://localhost:3000' |
| 13 | +const tenantsUrl = new AdminUrlUtil(SERVER_URL, CollectionSlugs.tenants) |
| 14 | + |
| 15 | +authTest.describe('Tenants', () => { |
| 16 | + authTest.describe('Create', () => { |
| 17 | + authTest.describe.configure({ timeout: 60000 }) |
| 18 | + |
| 19 | + authTest('slug dropdown only shows unused slugs', async ({ adminPage }) => { |
| 20 | + await adminPage.goto(tenantsUrl.list) |
| 21 | + await adminPage.waitForLoadState('networkidle') |
| 22 | + |
| 23 | + await adminPage.goto(tenantsUrl.create) |
| 24 | + await adminPage.waitForLoadState('networkidle') |
| 25 | + await waitForFormReady(adminPage) |
| 26 | + |
| 27 | + const slugField = adminPage.locator('#field-slug') |
| 28 | + const options = await getSelectInputOptions({ selectLocator: slugField }) |
| 29 | + |
| 30 | + expect(options).not.toContain(expect.stringMatching(/nwac/i)) |
| 31 | + expect(options).not.toContain(expect.stringMatching(/dvac/i)) |
| 32 | + expect(options).not.toContain(expect.stringMatching(/sac/i)) |
| 33 | + expect(options).not.toContain(expect.stringMatching(/snfac/i)) |
| 34 | + }) |
| 35 | + |
| 36 | + authTest('selecting a slug auto-fills the name field', async ({ adminPage }) => { |
| 37 | + await adminPage.goto(tenantsUrl.create) |
| 38 | + await adminPage.waitForLoadState('networkidle') |
| 39 | + await waitForFormReady(adminPage) |
| 40 | + |
| 41 | + const slugField = adminPage.locator('#field-slug') |
| 42 | + const nameInput = adminPage.locator('#field-name') |
| 43 | + |
| 44 | + await expect(nameInput).toHaveValue('') |
| 45 | + |
| 46 | + const options = await getSelectInputOptions({ selectLocator: slugField }) |
| 47 | + if (options.length === 0) { |
| 48 | + authTest.skip() |
| 49 | + return |
| 50 | + } |
| 51 | + |
| 52 | + await selectInput({ selectLocator: slugField, option: options[0] }) |
| 53 | + |
| 54 | + await expect(nameInput).not.toHaveValue('', { timeout: 5000 }) |
| 55 | + }) |
| 56 | + }) |
| 57 | + |
| 58 | + authTest.describe('Read', () => { |
| 59 | + authTest.describe.configure({ timeout: 60000 }) |
| 60 | + |
| 61 | + authTest('slug field shows current value on existing tenant', async ({ adminPage }) => { |
| 62 | + await adminPage.goto(tenantsUrl.list) |
| 63 | + await adminPage.waitForLoadState('networkidle') |
| 64 | + |
| 65 | + const firstLink = adminPage.locator('table tbody tr td a').first() |
| 66 | + await firstLink.waitFor({ timeout: 15000 }) |
| 67 | + await firstLink.click() |
| 68 | + await adminPage.waitForURL(/\/collections\/tenants\/\d+/) |
| 69 | + await waitForFormReady(adminPage) |
| 70 | + |
| 71 | + const slugField = adminPage.locator('#field-slug') |
| 72 | + await expect(slugField).toBeVisible() |
| 73 | + |
| 74 | + const value = await getSelectInputValue({ selectLocator: slugField }) |
| 75 | + expect(value).toBeTruthy() |
| 76 | + }) |
| 77 | + }) |
| 78 | + |
| 79 | + authTest.describe('Delete', () => { |
| 80 | + authTest.describe.configure({ timeout: 90000 }) |
| 81 | + |
| 82 | + authTest('shows custom confirmation modal with type-to-confirm', async ({ adminPage }) => { |
| 83 | + await adminPage.goto(tenantsUrl.list) |
| 84 | + await adminPage.waitForLoadState('networkidle') |
| 85 | + |
| 86 | + // Click the first tenant to open edit view |
| 87 | + const firstLink = adminPage.locator('table tbody tr td a').first() |
| 88 | + await firstLink.waitFor({ timeout: 15000 }) |
| 89 | + await firstLink.click() |
| 90 | + await adminPage.waitForURL(/\/collections\/tenants\/\d+/) |
| 91 | + await waitForFormReady(adminPage) |
| 92 | + |
| 93 | + // Get the tenant name for verification |
| 94 | + const nameInput = adminPage.locator('#field-name') |
| 95 | + const tenantName = await nameInput.inputValue() |
| 96 | + |
| 97 | + // Open the doc controls dropdown and click Delete |
| 98 | + await openDocControls(adminPage) |
| 99 | + const deleteButton = adminPage.getByRole('button', { name: 'Delete', exact: true }) |
| 100 | + await deleteButton.waitFor({ timeout: 5000 }) |
| 101 | + await deleteButton.click() |
| 102 | + |
| 103 | + // The custom modal should appear (not Payload's default) |
| 104 | + const modal = adminPage.locator('.confirmation-modal') |
| 105 | + await expect(modal).toBeVisible({ timeout: 10000 }) |
| 106 | + |
| 107 | + // Should show the tenant name in the heading |
| 108 | + await expect(modal.locator('h1')).toContainText(tenantName) |
| 109 | + |
| 110 | + // Should have a text input for typing the name |
| 111 | + const confirmInput = modal.locator('input[type="text"]') |
| 112 | + await expect(confirmInput).toBeVisible() |
| 113 | + |
| 114 | + // Should have a prompt to type the name |
| 115 | + await expect(modal).toContainText('Type') |
| 116 | + await expect(modal.locator('strong')).toContainText(tenantName) |
| 117 | + |
| 118 | + // Cancel to avoid actually deleting |
| 119 | + const cancelButton = modal.getByRole('button', { name: 'Cancel' }) |
| 120 | + await cancelButton.click() |
| 121 | + |
| 122 | + // Modal should close |
| 123 | + await expect(modal).not.toBeVisible({ timeout: 5000 }) |
| 124 | + }) |
| 125 | + |
| 126 | + authTest('shows error when typing wrong name', async ({ adminPage }) => { |
| 127 | + await adminPage.goto(tenantsUrl.list) |
| 128 | + await adminPage.waitForLoadState('networkidle') |
| 129 | + |
| 130 | + const firstLink = adminPage.locator('table tbody tr td a').first() |
| 131 | + await firstLink.waitFor({ timeout: 15000 }) |
| 132 | + await firstLink.click() |
| 133 | + await adminPage.waitForURL(/\/collections\/tenants\/\d+/) |
| 134 | + await waitForFormReady(adminPage) |
| 135 | + |
| 136 | + // Open delete modal |
| 137 | + await openDocControls(adminPage) |
| 138 | + const deleteButton = adminPage.getByRole('button', { name: 'Delete', exact: true }) |
| 139 | + await deleteButton.waitFor({ timeout: 5000 }) |
| 140 | + await deleteButton.click() |
| 141 | + |
| 142 | + const modal = adminPage.locator('.confirmation-modal') |
| 143 | + await expect(modal).toBeVisible({ timeout: 10000 }) |
| 144 | + |
| 145 | + // Type wrong name |
| 146 | + const confirmInput = modal.locator('input[type="text"]') |
| 147 | + await confirmInput.fill('wrong name') |
| 148 | + |
| 149 | + // Click delete |
| 150 | + const confirmDelete = modal.getByRole('button', { name: 'Delete', exact: true }) |
| 151 | + await confirmDelete.click() |
| 152 | + |
| 153 | + // Should show error toast |
| 154 | + await expect( |
| 155 | + adminPage.locator( |
| 156 | + '.toast-error, .Toastify__toast--error, [data-sonner-toast][data-type="error"]', |
| 157 | + ), |
| 158 | + ).toBeVisible({ timeout: 10000 }) |
| 159 | + |
| 160 | + // Modal should still be open |
| 161 | + await expect(modal).toBeVisible() |
| 162 | + |
| 163 | + // Cancel to clean up |
| 164 | + const cancelButton = modal.getByRole('button', { name: 'Cancel' }) |
| 165 | + await cancelButton.click() |
| 166 | + }) |
| 167 | + }) |
| 168 | +}) |
0 commit comments