1 import { AdminConfigPage } from '../po/admin-config.po'
2 import { AdminRegistrationPage } from '../po/admin-registration.po'
3 import { LoginPage } from '../po/login.po'
4 import { SignupPage } from '../po/signup.po'
16 function checkEndMessage (options: {
18 requiresEmailVerification: boolean
19 requiresApproval: boolean
20 afterEmailVerification: boolean
22 const { message, requiresApproval, requiresEmailVerification, afterEmailVerification } = options
25 const created = 'account has been created'
26 const request = 'account request has been sent'
28 if (requiresApproval) {
29 expect(message).toContain(request)
30 expect(message).not.toContain(created)
32 expect(message).not.toContain(request)
33 expect(message).toContain(created)
38 const checkEmail = 'Check your emails'
40 if (requiresEmailVerification) {
41 expect(message).toContain(checkEmail)
43 expect(message).not.toContain(checkEmail)
45 const moderatorsApproval = 'moderator will check your registration request'
46 if (requiresApproval) {
47 expect(message).toContain(moderatorsApproval)
49 expect(message).not.toContain(moderatorsApproval)
55 const emailVerified = 'email has been verified'
57 if (afterEmailVerification) {
58 expect(message).toContain(emailVerified)
60 expect(message).not.toContain(emailVerified)
65 describe('Signup', () => {
66 let loginPage: LoginPage
67 let adminConfigPage: AdminConfigPage
68 let signupPage: SignupPage
69 let adminRegistrationPage: AdminRegistrationPage
71 async function prepareSignup (options: {
73 requiresApproval?: boolean
74 requiresEmailVerification?: boolean
76 await loginPage.loginAsRootUser()
78 await adminConfigPage.navigateTo('basic-configuration')
79 await adminConfigPage.toggleSignup(options.enabled)
81 if (options.enabled) {
82 if (options.requiresApproval !== undefined) {
83 await adminConfigPage.toggleSignupApproval(options.requiresApproval)
86 if (options.requiresEmailVerification !== undefined) {
87 await adminConfigPage.toggleSignupEmailVerification(options.requiresEmailVerification)
91 await adminConfigPage.save()
93 await loginPage.logout()
94 await browser.refresh()
101 beforeEach(async () => {
102 loginPage = new LoginPage(isMobileDevice())
103 adminConfigPage = new AdminConfigPage()
104 signupPage = new SignupPage()
105 adminRegistrationPage = new AdminRegistrationPage()
107 await browser.maximizeWindow()
110 describe('Signup disabled', function () {
111 it('Should disable signup', async () => {
112 await prepareSignup({ enabled: false })
114 await expect(signupPage.getRegisterMenuButton()).not.toBeDisplayed()
118 describe('Email verification disabled', function () {
120 describe('Direct registration', function () {
122 it('Should enable signup without approval', async () => {
123 await prepareSignup({ enabled: true, requiresApproval: false, requiresEmailVerification: false })
125 await signupPage.getRegisterMenuButton().waitForDisplayed()
128 it('Should go on signup page', async function () {
129 await signupPage.clickOnRegisterInMenu()
132 it('Should validate the first step (about page)', async function () {
133 await signupPage.validateStep()
136 it('Should validate the second step (terms)', async function () {
137 await signupPage.checkTerms()
138 await signupPage.validateStep()
141 it('Should validate the third step (account)', async function () {
142 await signupPage.fillAccountStep({ username: 'user_1', displayName: 'user_1_dn' })
144 await signupPage.validateStep()
147 it('Should validate the third step (channel)', async function () {
148 await signupPage.fillChannelStep({ name: 'user_1_channel' })
150 await signupPage.validateStep()
153 it('Should be logged in', async function () {
154 await loginPage.ensureIsLoggedInAs('user_1_dn')
157 it('Should have a valid end message', async function () {
158 const message = await signupPage.getEndMessage()
162 requiresEmailVerification: false,
163 requiresApproval: false,
164 afterEmailVerification: false
167 await browser.saveScreenshot(getScreenshotPath('direct-without-email.png'))
169 await loginPage.logout()
173 describe('Registration with approval', function () {
175 it('Should enable signup with approval', async () => {
176 await prepareSignup({ enabled: true, requiresApproval: true, requiresEmailVerification: false })
178 await signupPage.getRegisterMenuButton().waitForDisplayed()
181 it('Should go on signup page', async function () {
182 await signupPage.clickOnRegisterInMenu()
185 it('Should validate the first step (about page)', async function () {
186 await signupPage.validateStep()
189 it('Should validate the second step (terms)', async function () {
190 await signupPage.checkTerms()
191 await signupPage.fillRegistrationReason('my super reason')
192 await signupPage.validateStep()
195 it('Should validate the third step (account)', async function () {
196 await signupPage.fillAccountStep({ username: 'user_2', displayName: 'user_2 display name', password: 'password' })
197 await signupPage.validateStep()
200 it('Should validate the third step (channel)', async function () {
201 await signupPage.fillChannelStep({ name: 'user_2_channel' })
202 await signupPage.validateStep()
205 it('Should have a valid end message', async function () {
206 const message = await signupPage.getEndMessage()
210 requiresEmailVerification: false,
211 requiresApproval: true,
212 afterEmailVerification: false
215 await browser.saveScreenshot(getScreenshotPath('request-without-email.png'))
218 it('Should display a message when trying to login with this account', async function () {
219 const error = await loginPage.getLoginError('user_2', 'password')
221 expect(error).toContain('awaiting approval')
224 it('Should accept the registration', async function () {
225 await loginPage.loginAsRootUser()
227 await adminRegistrationPage.navigateToRegistratonsList()
228 await adminRegistrationPage.accept('user_2', 'moderation response')
230 await loginPage.logout()
233 it('Should be able to login with this new account', async function () {
234 await loginPage.login({ username: 'user_2', password: 'password', displayName: 'user_2 display name' })
236 await loginPage.logout()
241 describe('Email verification enabled', function () {
242 const emails: any[] = []
243 let emailPort: number
246 // FIXME: typings are wrong, get returns a promise
247 emailPort = await (browser.sharedStore.get(browser.config.baseUrl + '-emailPort') as unknown as Promise<number>)
249 await MockSMTPServer.Instance.collectEmails(emailPort, emails)
252 describe('Direct registration', function () {
254 it('Should enable signup without approval', async () => {
255 await prepareSignup({ enabled: true, requiresApproval: false, requiresEmailVerification: true })
257 await signupPage.getRegisterMenuButton().waitForDisplayed()
260 it('Should go on signup page', async function () {
261 await signupPage.clickOnRegisterInMenu()
264 it('Should validate the first step (about page)', async function () {
265 await signupPage.validateStep()
268 it('Should validate the second step (terms)', async function () {
269 await signupPage.checkTerms()
270 await signupPage.validateStep()
273 it('Should validate the third step (account)', async function () {
274 await signupPage.fillAccountStep({ username: 'user_3', displayName: 'user_3 display name', email: 'user_3@example.com' })
276 await signupPage.validateStep()
279 it('Should validate the third step (channel)', async function () {
280 await signupPage.fillChannelStep({ name: 'user_3_channel' })
282 await signupPage.validateStep()
285 it('Should have a valid end message', async function () {
286 const message = await signupPage.getEndMessage()
290 requiresEmailVerification: true,
291 requiresApproval: false,
292 afterEmailVerification: false
295 await browser.saveScreenshot(getScreenshotPath('direct-with-email.png'))
298 it('Should validate the email', async function () {
299 let email: { text: string }
301 while (!(email = findEmailTo(emails, 'user_3@example.com'))) {
302 await browserSleep(100)
305 await go(getVerificationLink(email))
307 const message = await signupPage.getEndMessage()
311 requiresEmailVerification: false,
312 requiresApproval: false,
313 afterEmailVerification: true
316 await browser.saveScreenshot(getScreenshotPath('direct-after-email.png'))
320 describe('Registration with approval', function () {
322 it('Should enable signup without approval', async () => {
323 await prepareSignup({ enabled: true, requiresApproval: true, requiresEmailVerification: true })
325 await signupPage.getRegisterMenuButton().waitForDisplayed()
328 it('Should go on signup page', async function () {
329 await signupPage.clickOnRegisterInMenu()
332 it('Should validate the first step (about page)', async function () {
333 await signupPage.validateStep()
336 it('Should validate the second step (terms)', async function () {
337 await signupPage.checkTerms()
338 await signupPage.fillRegistrationReason('my super reason 2')
339 await signupPage.validateStep()
342 it('Should validate the third step (account)', async function () {
343 await signupPage.fillAccountStep({
345 displayName: 'user_4 display name',
346 email: 'user_4@example.com',
349 await signupPage.validateStep()
352 it('Should validate the third step (channel)', async function () {
353 await signupPage.fillChannelStep({ name: 'user_4_channel' })
354 await signupPage.validateStep()
357 it('Should have a valid end message', async function () {
358 const message = await signupPage.getEndMessage()
362 requiresEmailVerification: true,
363 requiresApproval: true,
364 afterEmailVerification: false
367 await browser.saveScreenshot(getScreenshotPath('request-with-email.png'))
370 it('Should display a message when trying to login with this account', async function () {
371 const error = await loginPage.getLoginError('user_4', 'password')
373 expect(error).toContain('awaiting approval')
376 it('Should accept the registration', async function () {
377 await loginPage.loginAsRootUser()
379 await adminRegistrationPage.navigateToRegistratonsList()
380 await adminRegistrationPage.accept('user_4', 'moderation response 2')
382 await loginPage.logout()
385 it('Should validate the email', async function () {
386 let email: { text: string }
388 while (!(email = findEmailTo(emails, 'user_4@example.com'))) {
389 await browserSleep(100)
392 await go(getVerificationLink(email))
394 const message = await signupPage.getEndMessage()
398 requiresEmailVerification: false,
399 requiresApproval: true,
400 afterEmailVerification: true
403 await browser.saveScreenshot(getScreenshotPath('request-after-email.png'))
408 MockSMTPServer.Instance.kill()