|
| 1 | +import { expect, test } from '@playwright/test'; |
| 2 | + |
| 3 | +import { |
| 4 | + acceptCookieConsentBanner, |
| 5 | + fillInputByLabelWithDelay, |
| 6 | +} from '../utils/common.ts'; |
| 7 | +import { |
| 8 | + generateRandomString, |
| 9 | + selectWalletAndUserProfile, |
| 10 | +} from '../utils/create-colony.ts'; |
| 11 | +import { generateCreateColonyUrl } from '../utils/graphqlHelpers.ts'; |
| 12 | + |
| 13 | +test.describe('Create Colony flow', () => { |
| 14 | + const colonyName = 'testcolonyname'; |
| 15 | + |
| 16 | + test.beforeEach(async ({ page }) => { |
| 17 | + const colonyUrl = await generateCreateColonyUrl(); |
| 18 | + |
| 19 | + await page.goto(colonyUrl); |
| 20 | + |
| 21 | + await selectWalletAndUserProfile(page); |
| 22 | + |
| 23 | + await acceptCookieConsentBanner(page); |
| 24 | + }); |
| 25 | + test.describe('Details step', () => { |
| 26 | + test('Should render Details step correctly', async ({ page }) => { |
| 27 | + // Heading of the step and form is shown |
| 28 | + await Promise.all([ |
| 29 | + expect( |
| 30 | + page |
| 31 | + .getByTestId('onboarding-heading') |
| 32 | + .filter({ hasText: /Welcome/i }), |
| 33 | + ).toBeVisible(), |
| 34 | + expect( |
| 35 | + page |
| 36 | + .getByTestId('onboarding-subheading') |
| 37 | + .filter({ hasText: /Let’s set up your Colony/i }), |
| 38 | + ).toBeVisible(), |
| 39 | + expect(page.getByLabel(/colony name/i)).toBeVisible(), |
| 40 | + expect(page.getByLabel(/custom colony URL/i)).toBeVisible(), |
| 41 | + expect(page.getByRole('button', { name: /continue/i })).toBeVisible(), |
| 42 | + ]); |
| 43 | + // Sidebar navigation and its components are visible |
| 44 | + const sidebarNav = page.getByRole('navigation'); |
| 45 | + |
| 46 | + await Promise.all([ |
| 47 | + expect(sidebarNav.getByText(/create your new colony/i)).toBeVisible(), |
| 48 | + expect(sidebarNav.getByText('Create', { exact: true })).toBeVisible(), |
| 49 | + expect(sidebarNav.getByText('Details')).toBeVisible(), |
| 50 | + expect(sidebarNav.getByText('Native Token')).toBeVisible(), |
| 51 | + expect(sidebarNav.getByText('Confirmation')).toBeVisible(), |
| 52 | + expect(sidebarNav.getByText('Complete')).toBeVisible(), |
| 53 | + expect( |
| 54 | + sidebarNav.getByRole('button', { name: 'Help & Feedback' }), |
| 55 | + ).toBeVisible(), |
| 56 | + ]); |
| 57 | + }); |
| 58 | + |
| 59 | + test('Should accept a valid Colony Name and Custom URL and navigate to the next step', async ({ |
| 60 | + page, |
| 61 | + }) => { |
| 62 | + // continue button is disabled initially |
| 63 | + await expect( |
| 64 | + page.getByRole('button', { name: /continue/i }), |
| 65 | + ).toBeDisabled(); |
| 66 | + |
| 67 | + // Fill in colony name and custom URL |
| 68 | + await fillInputByLabelWithDelay({ |
| 69 | + page, |
| 70 | + label: /colony name/i, |
| 71 | + value: colonyName, |
| 72 | + }); |
| 73 | + |
| 74 | + await fillInputByLabelWithDelay({ |
| 75 | + page, |
| 76 | + label: /custom colony URL/i, |
| 77 | + value: generateRandomString(), |
| 78 | + }); |
| 79 | + |
| 80 | + // Check if URL is available |
| 81 | + await expect(page.getByText(/URL available/i)).toBeVisible(); |
| 82 | + |
| 83 | + // Click continue and verify navigation to the next step |
| 84 | + await page.getByRole('button', { name: /continue/i }).click(); |
| 85 | + await expect( |
| 86 | + page.getByRole('heading', { name: /creating a new native token/i }), |
| 87 | + ).toBeVisible(); |
| 88 | + }); |
| 89 | + |
| 90 | + test('Should show an error message when the Colony URL is already taken', async ({ |
| 91 | + page, |
| 92 | + }) => { |
| 93 | + // Mock the response for the 'CheckColonyNameExists' query |
| 94 | + page.route('**/graphql', (route, request) => { |
| 95 | + const postData = request.postDataJSON(); |
| 96 | + |
| 97 | + if (postData.operationName === 'CheckColonyNameExists') { |
| 98 | + route.fulfill({ |
| 99 | + status: 200, |
| 100 | + contentType: 'application/json', |
| 101 | + body: JSON.stringify({ |
| 102 | + data: { |
| 103 | + getColonyByName: { |
| 104 | + items: ['someColonyId'], |
| 105 | + __typename: 'ModelColonyConnection', |
| 106 | + }, |
| 107 | + }, |
| 108 | + }), |
| 109 | + }); |
| 110 | + } else { |
| 111 | + route.continue(); |
| 112 | + } |
| 113 | + }); |
| 114 | + |
| 115 | + await fillInputByLabelWithDelay({ |
| 116 | + page, |
| 117 | + label: /custom colony URL/i, |
| 118 | + value: 'takenurl', |
| 119 | + }); |
| 120 | + |
| 121 | + await expect( |
| 122 | + page.getByText(/This colony URL is already taken/i), |
| 123 | + ).toBeVisible(); |
| 124 | + }); |
| 125 | + |
| 126 | + test('Should reject invalid colony name', async ({ page }) => { |
| 127 | + // More than 20 characters |
| 128 | + await fillInputByLabelWithDelay({ |
| 129 | + page, |
| 130 | + label: /colony name/i, |
| 131 | + value: 'A'.repeat(21), |
| 132 | + }); |
| 133 | + |
| 134 | + await expect(page.getByTestId('form-error')).toBeVisible(); |
| 135 | + }); |
| 136 | + |
| 137 | + test("Should reject invalid custom colony URL's", async ({ page }) => { |
| 138 | + await test.step('Invalid value', async () => { |
| 139 | + await fillInputByLabelWithDelay({ |
| 140 | + page, |
| 141 | + label: /custom colony URL/i, |
| 142 | + value: 'invalid name', |
| 143 | + }); |
| 144 | + |
| 145 | + await expect(page.getByTestId('form-error')).toBeVisible(); |
| 146 | + }); |
| 147 | + |
| 148 | + await test.step('Contains invalid character', async () => { |
| 149 | + await page.getByLabel(/custom colony URL/i).clear(); |
| 150 | + |
| 151 | + await fillInputByLabelWithDelay({ |
| 152 | + page, |
| 153 | + label: /custom colony URL/i, |
| 154 | + value: '/invalid', |
| 155 | + }); |
| 156 | + |
| 157 | + await expect(page.getByTestId('form-error')).toBeVisible(); |
| 158 | + }); |
| 159 | + |
| 160 | + await test.step('More than 20 characters', async () => { |
| 161 | + await page.getByLabel(/custom colony URL/i).clear(); |
| 162 | + |
| 163 | + await fillInputByLabelWithDelay({ |
| 164 | + page, |
| 165 | + label: /custom colony URL/i, |
| 166 | + value: 'a'.repeat(21), |
| 167 | + }); |
| 168 | + |
| 169 | + await expect(page.getByTestId('form-error')).toBeVisible(); |
| 170 | + }); |
| 171 | + |
| 172 | + await test.step('Reserved keyword', async () => { |
| 173 | + await page.getByLabel(/custom colony URL/i).clear(); |
| 174 | + |
| 175 | + await fillInputByLabelWithDelay({ |
| 176 | + page, |
| 177 | + label: /custom colony URL/i, |
| 178 | + value: 'account', |
| 179 | + }); |
| 180 | + |
| 181 | + await expect(page.getByTestId('form-error')).toBeVisible(); |
| 182 | + }); |
| 183 | + }); |
| 184 | + }); |
| 185 | +}); |
0 commit comments