2022-09-23 20:15:08 +03:00
import moment from 'moment-timezone' ;
2017-11-10 17:19:20 +03:00
import windowProxy from 'ghost-admin/utils/window-proxy' ;
2022-03-08 14:32:01 +03:00
import { Response } from 'miragejs' ;
2017-05-29 21:50:03 +03:00
import { afterEach , beforeEach , describe , it } from 'mocha' ;
2019-01-02 12:58:55 +03:00
import { authenticateSession , invalidateSession } from 'ember-simple-auth/test-support' ;
import {
blur ,
click ,
currentRouteName ,
currentURL ,
fillIn ,
find ,
findAll ,
focus ,
2022-10-05 14:05:31 +03:00
triggerEvent
2019-01-02 12:58:55 +03:00
} from '@ember/test-helpers' ;
2022-10-04 19:55:20 +03:00
import { enableLabsFlag } from '../helpers/labs-flag' ;
import { enableMembers } from '../helpers/members' ;
import { enableStripe } from '../helpers/stripe' ;
2017-05-29 21:50:03 +03:00
import { expect } from 'chai' ;
2022-10-04 19:55:20 +03:00
import { keyDown } from 'ember-keyboard/test-support/test-helpers' ;
2019-01-02 12:58:55 +03:00
import { setupApplicationTest } from 'ember-mocha' ;
2019-05-27 11:37:05 +03:00
import { setupMirage } from 'ember-cli-mirage/test-support' ;
2022-10-05 14:05:31 +03:00
import { submitForm } from '../helpers/forms' ;
2019-01-02 12:58:55 +03:00
import { visit } from '../helpers/visit' ;
2015-12-07 00:24:06 +03:00
2019-02-22 12:43:35 +03:00
describe ( 'Acceptance: Staff' , function ( ) {
2019-01-02 12:58:55 +03:00
let hooks = setupApplicationTest ( ) ;
setupMirage ( hooks ) ;
2015-12-07 00:24:06 +03:00
2017-04-24 15:29:48 +03:00
it ( 'redirects to signin when not authenticated' , async function ( ) {
2019-01-02 12:58:55 +03:00
await invalidateSession ( ) ;
2021-11-04 11:40:24 +03:00
await visit ( '/settings/staff' ) ;
2015-12-07 00:24:06 +03:00
2017-04-24 15:29:48 +03:00
expect ( currentURL ( ) ) . to . equal ( '/signin' ) ;
2015-12-07 00:24:06 +03:00
} ) ;
2018-02-07 12:42:46 +03:00
it ( 'redirects correctly when authenticated as contributor' , async function ( ) {
2019-01-02 12:58:55 +03:00
let role = this . server . create ( 'role' , { name : 'Contributor' } ) ;
this . server . create ( 'user' , { roles : [ role ] , slug : 'test-user' } ) ;
2018-02-07 12:42:46 +03:00
2019-01-02 12:58:55 +03:00
this . server . create ( 'user' , { slug : 'no-access' } ) ;
2018-02-07 12:42:46 +03:00
2019-01-02 12:58:55 +03:00
await authenticateSession ( ) ;
2021-11-04 11:40:24 +03:00
await visit ( '/settings/staff/no-access' ) ;
2018-02-07 12:42:46 +03:00
2021-11-04 11:40:24 +03:00
expect ( currentURL ( ) , 'currentURL' ) . to . equal ( '/settings/staff/test-user' ) ;
2018-02-07 12:42:46 +03:00
} ) ;
2017-04-24 15:29:48 +03:00
it ( 'redirects correctly when authenticated as author' , async function ( ) {
2019-01-02 12:58:55 +03:00
let role = this . server . create ( 'role' , { name : 'Author' } ) ;
this . server . create ( 'user' , { roles : [ role ] , slug : 'test-user' } ) ;
2015-12-07 00:24:06 +03:00
2019-01-02 12:58:55 +03:00
this . server . create ( 'user' , { slug : 'no-access' } ) ;
2015-12-07 00:24:06 +03:00
2019-01-02 12:58:55 +03:00
await authenticateSession ( ) ;
2021-11-04 11:40:24 +03:00
await visit ( '/settings/staff/no-access' ) ;
2015-12-07 00:24:06 +03:00
2021-11-04 11:40:24 +03:00
expect ( currentURL ( ) , 'currentURL' ) . to . equal ( '/settings/staff/test-user' ) ;
2015-12-07 00:24:06 +03:00
} ) ;
2017-04-24 15:29:48 +03:00
it ( 'redirects correctly when authenticated as editor' , async function ( ) {
2019-01-02 12:58:55 +03:00
let role = this . server . create ( 'role' , { name : 'Editor' } ) ;
this . server . create ( 'user' , { roles : [ role ] , slug : 'test-user' } ) ;
2015-12-07 00:24:06 +03:00
2019-01-02 12:58:55 +03:00
this . server . create ( 'user' , { slug : 'no-access' } ) ;
2015-12-07 00:24:06 +03:00
2019-01-02 12:58:55 +03:00
await authenticateSession ( ) ;
2021-11-04 11:40:24 +03:00
await visit ( '/settings/staff/no-access' ) ;
2015-12-07 00:24:06 +03:00
2021-11-04 11:40:24 +03:00
expect ( currentURL ( ) , 'currentURL' ) . to . equal ( '/settings/staff' ) ;
2015-12-07 00:24:06 +03:00
} ) ;
2016-09-26 19:03:53 +03:00
describe ( 'when logged in as admin' , function ( ) {
2017-03-08 21:21:35 +03:00
let admin , adminRole , suspendedUser ;
2016-06-14 14:46:24 +03:00
2019-01-02 12:58:55 +03:00
beforeEach ( async function ( ) {
this . server . loadFixtures ( 'roles' ) ;
2022-08-25 13:17:14 +03:00
this . server . loadFixtures ( 'settings' ) ;
2019-01-02 12:58:55 +03:00
adminRole = this . server . schema . roles . find ( 1 ) ;
2022-08-25 13:17:14 +03:00
enableMembers ( this . server ) ;
enableStripe ( this . server ) ;
enableLabsFlag ( this . server , 'emailAlerts' ) ;
2015-12-07 00:24:06 +03:00
2019-01-02 12:58:55 +03:00
admin = this . server . create ( 'user' , { email : 'admin@example.com' , roles : [ adminRole ] } ) ;
2015-12-07 00:24:06 +03:00
2017-02-27 16:11:39 +03:00
// add an expired invite
2019-01-02 12:58:55 +03:00
this . server . create ( 'invite' , { expires : moment . utc ( ) . subtract ( 1 , 'day' ) . valueOf ( ) , role : adminRole } ) ;
2017-02-27 16:11:39 +03:00
2017-03-08 21:21:35 +03:00
// add a suspended user
2019-01-02 12:58:55 +03:00
suspendedUser = this . server . create ( 'user' , { email : 'suspended@example.com' , roles : [ adminRole ] , status : 'inactive' } ) ;
2017-03-08 21:21:35 +03:00
2019-01-02 12:58:55 +03:00
return await authenticateSession ( ) ;
2015-12-07 00:24:06 +03:00
} ) ;
2017-04-24 15:29:48 +03:00
it ( 'it renders and navigates correctly' , async function ( ) {
2019-01-02 12:58:55 +03:00
let user1 = this . server . create ( 'user' ) ;
let user2 = this . server . create ( 'user' ) ;
2015-12-07 00:24:06 +03:00
2021-11-04 11:40:24 +03:00
await visit ( '/settings/staff' ) ;
2015-12-07 00:24:06 +03:00
2017-04-24 15:29:48 +03:00
// doesn't do any redirecting
2021-11-04 11:40:24 +03:00
expect ( currentURL ( ) , 'currentURL' ) . to . equal ( '/settings/staff' ) ;
2015-12-07 00:24:06 +03:00
2017-04-24 15:29:48 +03:00
// it has correct page title
2019-02-22 12:43:35 +03:00
expect ( document . title , 'page title' ) . to . equal ( 'Staff - Test Blog' ) ;
2017-04-24 15:29:48 +03:00
// it shows active users in active section
expect (
2019-01-02 12:58:55 +03:00
findAll ( '[data-test-active-users] [data-test-user-id]' ) . length ,
2017-04-24 15:29:48 +03:00
'number of active users'
) . to . equal ( 3 ) ;
expect (
2017-08-11 18:28:05 +03:00
find ( ` [data-test-active-users] [data-test-user-id=" ${ user1 . id } "] ` )
2017-04-24 15:29:48 +03:00
) . to . exist ;
expect (
2017-08-11 18:28:05 +03:00
find ( ` [data-test-active-users] [data-test-user-id=" ${ user2 . id } "] ` )
2017-04-24 15:29:48 +03:00
) . to . exist ;
expect (
2017-08-11 18:28:05 +03:00
find ( ` [data-test-active-users] [data-test-user-id=" ${ admin . id } "] ` )
2017-04-24 15:29:48 +03:00
) . to . exist ;
// it shows suspended users in suspended section
expect (
2019-01-02 12:58:55 +03:00
findAll ( '[data-test-suspended-users] [data-test-user-id]' ) . length ,
2017-04-24 15:29:48 +03:00
'number of suspended users'
) . to . equal ( 1 ) ;
expect (
2017-08-11 18:28:05 +03:00
find ( ` [data-test-suspended-users] [data-test-user-id=" ${ suspendedUser . id } "] ` )
2017-04-24 15:29:48 +03:00
) . to . exist ;
2017-08-11 18:28:05 +03:00
await click ( ` [data-test-user-id=" ${ user2 . id } "] ` ) ;
2017-04-24 15:29:48 +03:00
// url is correct
2021-11-04 11:40:24 +03:00
expect ( currentURL ( ) , 'url after clicking user' ) . to . equal ( ` /settings/staff/ ${ user2 . slug } ` ) ;
2017-04-24 15:29:48 +03:00
// title is correct
2019-02-22 12:43:35 +03:00
expect ( document . title , 'title after clicking user' ) . to . equal ( 'Staff - User - Test Blog' ) ;
2017-04-24 15:29:48 +03:00
// view title should exist and be linkable and active
2017-05-30 16:23:38 +03:00
expect (
2022-10-04 08:35:29 +03:00
find ( '[data-test-breadcrumb] a[href="/ghost/settings/staff"]' ) . classList . contains ( 'active' ) ,
2019-02-22 12:43:35 +03:00
'has linkable url back to staff main page'
2017-05-30 16:23:38 +03:00
) . to . be . true ;
2017-04-24 15:29:48 +03:00
2022-10-04 08:35:29 +03:00
await click ( '[data-test-breadcrumb] a' ) ;
2017-04-24 15:29:48 +03:00
2019-02-22 12:43:35 +03:00
// url should be /staff again
2021-11-04 11:40:24 +03:00
expect ( currentURL ( ) , 'url after clicking back' ) . to . equal ( '/settings' ) ;
2015-12-07 00:24:06 +03:00
} ) ;
2017-04-24 15:29:48 +03:00
it ( 'can manage invites' , async function ( ) {
2021-11-04 11:40:24 +03:00
await visit ( '/settings/staff' ) ;
2017-04-24 15:29:48 +03:00
// invite user button exists
expect (
2021-02-12 18:55:16 +03:00
find ( '.view-actions .gh-btn-primary' ) ,
2019-02-22 12:43:35 +03:00
'invite people button'
) . to . exist ;
2017-04-24 15:29:48 +03:00
// existing users are listed
expect (
2019-01-02 12:58:55 +03:00
findAll ( '[data-test-user-id]' ) . length ,
2017-04-24 15:29:48 +03:00
'initial number of active users'
) . to . equal ( 2 ) ;
expect (
2019-01-02 12:58:55 +03:00
find ( '[data-test-user-id="1"] [data-test-role-name]' ) . textContent . trim ( ) ,
2017-04-24 15:29:48 +03:00
'active user\'s role label'
) . to . equal ( 'Administrator' ) ;
// existing invites are shown
expect (
2019-01-02 12:58:55 +03:00
findAll ( '[data-test-invite-id]' ) . length ,
2017-04-24 15:29:48 +03:00
'initial number of invited users'
) . to . equal ( 1 ) ;
expect (
2019-01-02 12:58:55 +03:00
find ( '[data-test-invite-id="1"] [data-test-invite-description]' ) . textContent ,
2017-04-24 15:29:48 +03:00
'expired invite description'
) . to . match ( /expired/ ) ;
2017-02-27 16:11:39 +03:00
// remove expired invite
2017-08-11 18:28:05 +03:00
await click ( '[data-test-invite-id="1"] [data-test-revoke-button]' ) ;
2017-02-27 16:11:39 +03:00
2017-04-24 15:29:48 +03:00
expect (
2019-01-02 12:58:55 +03:00
findAll ( '[data-test-invite-id]' ) . length ,
2017-04-24 15:29:48 +03:00
'initial number of invited users'
) . to . equal ( 0 ) ;
2016-09-26 19:03:53 +03:00
// click the invite people button
2021-04-07 17:20:30 +03:00
await click ( '[data-test-button="invite-staff-user"]' ) ;
2015-12-07 00:24:06 +03:00
2017-04-24 15:29:48 +03:00
// modal is displayed
expect (
2021-04-07 17:20:30 +03:00
find ( '[data-test-modal="invite-staff-user"]' ) ,
2017-04-24 15:29:48 +03:00
'correct modal is displayed'
2021-04-07 17:20:30 +03:00
) . to . exist ;
2015-12-07 00:24:06 +03:00
2017-04-24 15:29:48 +03:00
// number of roles is correct
expect (
2021-04-07 17:20:30 +03:00
findAll ( '[data-test-option]' ) . length ,
2017-04-24 15:29:48 +03:00
'number of selectable roles'
2021-04-07 17:20:30 +03:00
) . to . equal ( 4 ) ;
2016-09-26 19:03:53 +03:00
2021-04-07 17:20:30 +03:00
expect (
find ( '[data-test-option="Contributor"]' ) ,
'contributor role is selected initially'
) . to . have . class ( 'active' ) ;
2015-12-07 00:24:06 +03:00
2016-09-26 19:03:53 +03:00
// submit valid invite form
2017-04-24 15:29:48 +03:00
await fillIn ( '.fullscreen-modal input[name="email"]' , 'invite1@example.com' ) ;
2021-03-05 15:16:43 +03:00
await click ( '[data-test-button="send-user-invite"]' ) ;
2017-04-24 15:29:48 +03:00
// modal closes
expect (
2019-01-02 12:58:55 +03:00
findAll ( '[data-test-modal]' ) . length ,
2017-04-24 15:29:48 +03:00
'number of modals after sending invite'
) . to . equal ( 0 ) ;
// invite is displayed, has correct e-mail + role
expect (
2019-01-02 12:58:55 +03:00
findAll ( '[data-test-invite-id]' ) . length ,
2017-04-24 15:29:48 +03:00
'number of invites after first invite'
) . to . equal ( 1 ) ;
expect (
2019-01-02 12:58:55 +03:00
find ( '[data-test-invite-id="2"] [data-test-email]' ) . textContent . trim ( ) ,
2017-04-24 15:29:48 +03:00
'displayed email of first invite'
) . to . equal ( 'invite1@example.com' ) ;
expect (
2019-01-02 12:58:55 +03:00
find ( '[data-test-invite-id="2"] [data-test-role-name]' ) . textContent . trim ( ) ,
2017-04-24 15:29:48 +03:00
'displayed role of first invite'
2021-04-07 17:20:30 +03:00
) . to . equal ( 'Contributor' ) ;
2017-04-24 15:29:48 +03:00
expect (
2019-01-02 12:58:55 +03:00
find ( '[data-test-invite-id="2"] [data-test-invite-description]' ) . textContent ,
2017-04-24 15:29:48 +03:00
'new invite description'
) . to . match ( /expires/ ) ;
// number of users is unchanged
expect (
2019-01-02 12:58:55 +03:00
findAll ( '[data-test-user-id]' ) . length ,
2017-04-24 15:29:48 +03:00
'number of active users after first invite'
) . to . equal ( 2 ) ;
2015-12-07 00:24:06 +03:00
2016-09-26 19:03:53 +03:00
// submit new invite with different role
2021-02-12 18:55:16 +03:00
await click ( '.view-actions .gh-btn-primary' ) ;
2017-04-24 15:29:48 +03:00
await fillIn ( '.fullscreen-modal input[name="email"]' , 'invite2@example.com' ) ;
2021-04-07 17:20:30 +03:00
await click ( '[data-test-option="Editor"]' ) ;
2021-03-05 15:16:43 +03:00
await click ( '[data-test-button="send-user-invite"]' ) ;
2017-04-24 15:29:48 +03:00
// number of invites increases
expect (
2019-01-02 12:58:55 +03:00
findAll ( '[data-test-invite-id]' ) . length ,
2017-04-24 15:29:48 +03:00
'number of invites after second invite'
) . to . equal ( 2 ) ;
// invite has correct e-mail + role
expect (
2019-01-02 12:58:55 +03:00
find ( '[data-test-invite-id="3"] [data-test-email]' ) . textContent . trim ( ) ,
2017-04-24 15:29:48 +03:00
'displayed email of second invite'
) . to . equal ( 'invite2@example.com' ) ;
expect (
2019-01-02 12:58:55 +03:00
find ( '[data-test-invite-id="3"] [data-test-role-name]' ) . textContent . trim ( ) ,
2017-04-24 15:29:48 +03:00
'displayed role of second invite'
) . to . equal ( 'Editor' ) ;
2015-12-07 00:24:06 +03:00
2016-09-26 19:03:53 +03:00
// submit invite form with existing user
2021-02-12 18:55:16 +03:00
await click ( '.view-actions .gh-btn-primary' ) ;
2017-04-24 15:29:48 +03:00
await fillIn ( '.fullscreen-modal input[name="email"]' , 'admin@example.com' ) ;
2021-03-05 15:16:43 +03:00
await click ( '[data-test-button="send-user-invite"]' ) ;
2015-12-07 00:24:06 +03:00
2017-04-24 15:29:48 +03:00
// validation message is displayed
expect (
2019-01-02 12:58:55 +03:00
find ( '.fullscreen-modal .error .response' ) . textContent . trim ( ) ,
2017-04-24 15:29:48 +03:00
'inviting existing user error'
) . to . equal ( 'A user with that email address already exists.' ) ;
2015-12-07 00:24:06 +03:00
2016-09-26 19:03:53 +03:00
// submit invite form with existing invite
2017-04-24 15:29:48 +03:00
await fillIn ( '.fullscreen-modal input[name="email"]' , 'invite1@example.com' ) ;
2021-03-05 15:16:43 +03:00
await click ( '[data-test-button="send-user-invite"]' ) ;
2015-12-07 00:24:06 +03:00
2017-04-24 15:29:48 +03:00
// validation message is displayed
expect (
2019-01-02 12:58:55 +03:00
find ( '.fullscreen-modal .error .response' ) . textContent . trim ( ) ,
2017-04-24 15:29:48 +03:00
'inviting invited user error'
) . to . equal ( 'A user with that email address was already invited.' ) ;
2015-11-18 13:50:48 +03:00
2016-09-26 19:03:53 +03:00
// submit invite form with an invalid email
2017-04-24 15:29:48 +03:00
await fillIn ( '.fullscreen-modal input[name="email"]' , 'test' ) ;
2021-03-05 15:16:43 +03:00
await click ( '[data-test-button="send-user-invite"]' ) ;
2015-12-07 00:24:06 +03:00
2017-04-24 15:29:48 +03:00
// validation message is displayed
expect (
2019-01-02 12:58:55 +03:00
find ( '.fullscreen-modal .error .response' ) . textContent . trim ( ) ,
2017-04-24 15:29:48 +03:00
'inviting invalid email error'
) . to . equal ( 'Invalid Email.' ) ;
2015-12-07 00:24:06 +03:00
2017-04-24 15:29:48 +03:00
await click ( '.fullscreen-modal a.close' ) ;
2016-09-26 19:03:53 +03:00
// revoke latest invite
2017-08-11 18:28:05 +03:00
await click ( '[data-test-invite-id="3"] [data-test-revoke-button]' ) ;
2017-04-24 15:29:48 +03:00
// number of invites decreases
expect (
2019-01-02 12:58:55 +03:00
findAll ( '[data-test-invite-id]' ) . length ,
2017-04-24 15:29:48 +03:00
'number of invites after revoke'
) . to . equal ( 1 ) ;
// notification is displayed
expect (
2020-02-27 12:19:29 +03:00
find ( '.gh-notification:last-of-type' ) . textContent . trim ( ) ,
2017-04-24 15:29:48 +03:00
'notifications contain revoke'
2020-02-27 12:19:29 +03:00
) . to . match ( /Invitation revoked\s+invite2@example\.com/ ) ;
2017-04-24 15:29:48 +03:00
// correct invite is removed
expect (
2019-01-02 12:58:55 +03:00
find ( '[data-test-invite-id] [data-test-email]' ) . textContent . trim ( ) ,
2017-04-24 15:29:48 +03:00
'displayed email of remaining invite'
) . to . equal ( 'invite1@example.com' ) ;
2016-09-26 19:03:53 +03:00
// add another invite to test ordering on resend
2021-02-12 18:55:16 +03:00
await click ( '.view-actions .gh-btn-primary' ) ;
2017-04-24 15:29:48 +03:00
await fillIn ( '.fullscreen-modal input[name="email"]' , 'invite3@example.com' ) ;
2021-03-05 15:16:43 +03:00
await click ( '[data-test-button="send-user-invite"]' ) ;
2016-09-26 19:03:53 +03:00
2017-04-24 15:29:48 +03:00
// new invite should be last in the list
expect (
2019-01-02 12:58:55 +03:00
find ( '[data-test-invite-id]:last-of-type [data-test-email]' ) . textContent . trim ( ) ,
2017-04-24 15:29:48 +03:00
'last invite email in list'
) . to . equal ( 'invite3@example.com' ) ;
2016-09-26 19:03:53 +03:00
// resend first invite
2017-08-11 18:28:05 +03:00
await click ( '[data-test-invite-id="2"] [data-test-resend-button]' ) ;
2016-09-26 19:03:53 +03:00
2017-04-24 15:29:48 +03:00
// notification is displayed
expect (
2020-02-27 12:19:29 +03:00
find ( '.gh-notification:last-of-type' ) . textContent . trim ( ) ,
2017-04-24 15:29:48 +03:00
'notifications contain resend'
) . to . match ( /Invitation resent! \(invite1@example\.com\)/ ) ;
2016-09-26 19:03:53 +03:00
2017-04-24 15:29:48 +03:00
// first invite is still at the top
expect (
2019-01-02 12:58:55 +03:00
find ( '[data-test-invite-id]:first-of-type [data-test-email]' ) . textContent . trim ( ) ,
2017-04-24 15:29:48 +03:00
'first invite email in list'
) . to . equal ( 'invite1@example.com' ) ;
2016-09-26 19:03:53 +03:00
// regression test: can revoke a resent invite
2017-08-11 18:28:05 +03:00
await click ( '[data-test-invite-id]:first-of-type [data-test-resend-button]' ) ;
await click ( '[data-test-invite-id]:first-of-type [data-test-revoke-button]' ) ;
2017-04-24 15:29:48 +03:00
// number of invites decreases
expect (
2019-01-02 12:58:55 +03:00
findAll ( '[data-test-invite-id]' ) . length ,
2017-04-24 15:29:48 +03:00
'number of invites after resend/revoke'
) . to . equal ( 1 ) ;
// notification is displayed
expect (
2020-02-27 12:19:29 +03:00
find ( '.gh-notification:last-of-type' ) . textContent . trim ( ) ,
2017-04-24 15:29:48 +03:00
'notifications contain revoke after resend/revoke'
2020-02-27 12:19:29 +03:00
) . to . match ( /Invitation revoked\s+invite1@example\.com/ ) ;
2015-12-07 00:24:06 +03:00
} ) ;
2017-04-24 15:29:48 +03:00
it ( 'can manage suspended users' , async function ( ) {
2021-11-04 11:40:24 +03:00
await visit ( '/settings/staff' ) ;
2017-08-11 18:28:05 +03:00
await click ( ` [data-test-user-id=" ${ suspendedUser . id } "] ` ) ;
2017-03-08 21:21:35 +03:00
2018-01-11 01:57:43 +03:00
expect ( find ( '[data-test-suspended-badge]' ) ) . to . exist ;
2017-03-08 21:21:35 +03:00
2017-08-11 18:28:05 +03:00
await click ( '[data-test-user-actions]' ) ;
await click ( '[data-test-unsuspend-button]' ) ;
await click ( '[data-test-modal-confirm]' ) ;
2017-03-08 21:21:35 +03:00
// NOTE: there seems to be a timing issue with this test - pausing
// here confirms that the badge is removed but the andThen is firing
// before the page is updated
// andThen(() => {
2017-08-11 18:28:05 +03:00
// expect('[data-test-suspended-badge]').to.not.exist;
2017-03-08 21:21:35 +03:00
// });
2019-02-22 12:43:35 +03:00
await click ( '[data-test-staff-link]' ) ;
2017-04-24 15:29:48 +03:00
// suspendedUser is now in active list
expect (
2017-08-11 18:28:05 +03:00
find ( ` [data-test-active-users] [data-test-user-id=" ${ suspendedUser . id } "] ` )
2017-04-24 15:29:48 +03:00
) . to . exist ;
2017-03-08 21:21:35 +03:00
2017-04-24 15:29:48 +03:00
// no suspended users
expect (
2019-01-02 12:58:55 +03:00
findAll ( '[data-test-suspended-users] [data-test-user-id]' ) . length
2017-04-24 15:29:48 +03:00
) . to . equal ( 0 ) ;
2017-03-08 21:21:35 +03:00
2017-08-11 18:28:05 +03:00
await click ( ` [data-test-user-id=" ${ suspendedUser . id } "] ` ) ;
2017-03-08 21:21:35 +03:00
2017-08-11 18:28:05 +03:00
await click ( '[data-test-user-actions]' ) ;
await click ( '[data-test-suspend-button]' ) ;
await click ( '[data-test-modal-confirm]' ) ;
2018-01-11 01:57:43 +03:00
expect ( find ( '[data-test-suspended-badge]' ) ) . to . exist ;
2017-03-08 21:21:35 +03:00
} ) ;
2017-04-24 15:29:48 +03:00
it ( 'can delete users' , async function ( ) {
2019-01-02 12:58:55 +03:00
let user1 = this . server . create ( 'user' ) ;
let user2 = this . server . create ( 'user' ) ;
let post = this . server . create ( 'post' , { authors : [ user2 ] } ) ;
2018-03-13 14:17:29 +03:00
// we don't have a full many-to-many relationship in mirage so we
// need to add the inverse manually
user2 . posts = [ post ] ;
user2 . save ( ) ;
2016-08-24 16:26:29 +03:00
2021-11-04 11:40:24 +03:00
await visit ( '/settings/staff' ) ;
2017-08-11 18:28:05 +03:00
await click ( ` [data-test-user-id=" ${ user1 . id } "] ` ) ;
2016-08-24 16:26:29 +03:00
// user deletion displays modal
2017-04-24 15:29:48 +03:00
await click ( 'button.delete' ) ;
expect (
2019-01-02 12:58:55 +03:00
findAll ( '[data-test-modal="delete-user"]' ) . length ,
2017-04-24 15:29:48 +03:00
'user deletion modal displayed after button click'
) . to . equal ( 1 ) ;
// user has no posts so no warning about post deletion
expect (
2019-01-02 12:58:55 +03:00
findAll ( '[data-test-text="user-post-count"]' ) . length ,
2017-04-24 15:29:48 +03:00
'deleting user with no posts has no post count'
) . to . equal ( 0 ) ;
2016-08-24 16:26:29 +03:00
// cancelling user deletion closes modal
2019-01-02 12:58:55 +03:00
await click ( '[data-test-button="cancel-delete-user"]' ) ;
2017-04-24 15:29:48 +03:00
expect (
2019-01-02 12:58:55 +03:00
findAll ( '[data-test-modal]' ) . length === 0 ,
2017-04-24 15:29:48 +03:00
'delete user modal is closed when cancelling'
) . to . be . true ;
2016-08-24 16:26:29 +03:00
// deleting a user with posts
2021-11-04 11:40:24 +03:00
await visit ( '/settings/staff' ) ;
2017-08-11 18:28:05 +03:00
await click ( ` [data-test-user-id=" ${ user2 . id } "] ` ) ;
2017-04-24 15:29:48 +03:00
await click ( 'button.delete' ) ;
// user has posts so should warn about post deletion
expect (
2019-01-02 12:58:55 +03:00
find ( '[data-test-text="user-post-count"]' ) . textContent ,
2017-04-24 15:29:48 +03:00
'deleting user with posts has post count'
2019-01-02 12:58:55 +03:00
) . to . have . string ( '1 post' ) ;
2017-04-24 15:29:48 +03:00
2019-01-02 12:58:55 +03:00
await click ( '[data-test-button="confirm-delete-user"]' ) ;
2019-02-22 12:43:35 +03:00
// redirected to staff page
2021-11-04 11:40:24 +03:00
expect ( currentURL ( ) ) . to . equal ( '/settings/staff' ) ;
2017-04-24 15:29:48 +03:00
// deleted user is not in list
expect (
2019-01-02 12:58:55 +03:00
findAll ( ` [data-test-user-id=" ${ user2 . id } "] ` ) . length ,
2017-04-24 15:29:48 +03:00
'deleted user is not in user list after deletion'
) . to . equal ( 0 ) ;
2016-08-24 16:26:29 +03:00
} ) ;
2015-12-07 00:24:06 +03:00
describe ( 'existing user' , function ( ) {
2022-10-05 14:05:31 +03:00
let user , originalReplaceState ;
let newLocation ; // eslint-disable-line
2015-12-07 00:24:06 +03:00
beforeEach ( function ( ) {
2019-01-02 12:58:55 +03:00
user = this . server . create ( 'user' , {
2016-05-17 21:14:14 +03:00
slug : 'test-1' ,
name : 'Test User' ,
facebook : 'test' ,
twitter : '@test'
} ) ;
2017-11-10 17:19:20 +03:00
originalReplaceState = windowProxy . replaceState ;
windowProxy . replaceState = function ( params , title , url ) {
newLocation = url ;
} ;
newLocation = undefined ;
} ) ;
afterEach ( function ( ) {
windowProxy . replaceState = originalReplaceState ;
2015-12-07 00:24:06 +03:00
} ) ;
2018-04-24 00:57:26 +03:00
it ( 'input fields reset and validate correctly' , async function ( ) {
2015-12-07 00:24:06 +03:00
// test user name
2021-11-04 11:40:24 +03:00
await visit ( '/settings/staff/test-1' ) ;
2015-12-07 00:24:06 +03:00
2021-11-04 11:40:24 +03:00
expect ( currentURL ( ) , 'currentURL' ) . to . equal ( '/settings/staff/test-1' ) ;
2019-01-02 12:58:55 +03:00
expect ( find ( '[data-test-name-input]' ) . value , 'current user name' ) . to . equal ( 'Test User' ) ;
2015-12-07 00:24:06 +03:00
2019-01-02 12:58:55 +03:00
expect ( find ( '[data-test-save-button]' ) . textContent . trim ( ) , 'save button text' ) . to . equal ( 'Save' ) ;
2017-05-18 13:48:37 +03:00
2015-12-07 00:24:06 +03:00
// test empty user name
2017-10-31 18:27:25 +03:00
await fillIn ( '[data-test-name-input]' , '' ) ;
2019-01-02 12:58:55 +03:00
await blur ( '[data-test-name-input]' ) ;
2015-12-07 00:24:06 +03:00
2019-01-02 12:58:55 +03:00
expect ( find ( '.user-details-bottom .first-form-group' ) . classList . contains ( 'error' ) , 'username input is in error state with blank input' ) . to . be . true ;
2015-12-07 00:24:06 +03:00
// test too long user name
2017-11-09 17:31:25 +03:00
await fillIn ( '[data-test-name-input]' , new Array ( 195 ) . join ( 'a' ) ) ;
2019-01-02 12:58:55 +03:00
await blur ( '[data-test-name-input]' ) ;
2015-12-07 00:24:06 +03:00
2019-01-02 12:58:55 +03:00
expect ( find ( '.user-details-bottom .first-form-group' ) . classList . contains ( 'error' ) , 'username input is in error state with too long input' ) . to . be . true ;
2015-12-07 00:24:06 +03:00
// reset name field
2017-10-31 18:27:25 +03:00
await fillIn ( '[data-test-name-input]' , 'Test User' ) ;
2015-12-07 00:24:06 +03:00
2019-01-02 12:58:55 +03:00
expect ( find ( '[data-test-slug-input]' ) . value , 'slug value is default' ) . to . equal ( 'test-1' ) ;
2015-12-07 00:24:06 +03:00
2017-10-31 18:27:25 +03:00
await fillIn ( '[data-test-slug-input]' , '' ) ;
2019-01-02 12:58:55 +03:00
await blur ( '[data-test-slug-input]' ) ;
2015-12-07 00:24:06 +03:00
2019-01-02 12:58:55 +03:00
expect ( find ( '[data-test-slug-input]' ) . value , 'slug value is reset to original upon empty string' ) . to . equal ( 'test-1' ) ;
2015-12-07 00:24:06 +03:00
2017-05-18 13:48:37 +03:00
// Save changes
2017-08-11 18:28:05 +03:00
await click ( '[data-test-save-button]' ) ;
2017-05-18 13:48:37 +03:00
2022-10-05 14:05:31 +03:00
// Since we reset save button's status there's no on-screen indication
2020-06-04 09:00:30 +03:00
// that we've had a save, check the request was fired instead
let [ lastRequest ] = this . server . pretender . handledRequests . slice ( - 1 ) ;
let params = JSON . parse ( lastRequest . requestBody ) ;
expect ( params . users [ 0 ] . name ) . to . equal ( 'Test User' ) ;
2017-05-18 13:48:37 +03:00
// CMD-S shortcut works
2022-10-05 14:05:31 +03:00
await fillIn ( '[data-test-name-input]' , 'New Name' ) ;
2022-10-04 19:55:20 +03:00
await keyDown ( 'cmd+s' ) ;
2017-05-18 13:48:37 +03:00
2022-10-05 14:05:31 +03:00
// Since we reset save button's status there's no on-screen indication
2020-06-04 09:00:30 +03:00
// that we've had a save, check the request was fired instead
[ lastRequest ] = this . server . pretender . handledRequests . slice ( - 1 ) ;
params = JSON . parse ( lastRequest . requestBody ) ;
2017-05-18 13:48:37 +03:00
2022-10-05 14:05:31 +03:00
// name should have been correctly set before save (we set on blur)
expect ( params . users [ 0 ] . name , 'saved name' ) . to . equal ( 'New Name' ) ;
2017-11-10 17:19:20 +03:00
2017-10-31 18:27:25 +03:00
await fillIn ( '[data-test-slug-input]' , 'white space' ) ;
2019-01-02 12:58:55 +03:00
await blur ( '[data-test-slug-input]' ) ;
2015-12-07 00:24:06 +03:00
2019-01-02 12:58:55 +03:00
expect ( find ( '[data-test-slug-input]' ) . value , 'slug value is correctly dasherized' ) . to . equal ( 'white-space' ) ;
2015-12-07 00:24:06 +03:00
2017-10-31 18:27:25 +03:00
await fillIn ( '[data-test-email-input]' , 'thisisnotanemail' ) ;
2019-01-02 12:58:55 +03:00
await blur ( '[data-test-email-input]' ) ;
2015-12-07 00:24:06 +03:00
2019-01-02 12:58:55 +03:00
expect ( find ( '.user-details-bottom .form-group:nth-of-type(3)' ) . classList . contains ( 'error' ) , 'email input should be in error state with invalid email' ) . to . be . true ;
2015-12-07 00:24:06 +03:00
2017-10-31 18:27:25 +03:00
await fillIn ( '[data-test-email-input]' , 'test@example.com' ) ;
await fillIn ( '[data-test-location-input]' , new Array ( 160 ) . join ( 'a' ) ) ;
2019-01-02 12:58:55 +03:00
await blur ( '[data-test-location-input]' ) ;
2015-12-07 00:24:06 +03:00
2019-01-02 12:58:55 +03:00
expect (
find ( '[data-test-location-input]' ) . closest ( '.form-group' ) ,
'location input should be in error state'
) . to . have . class ( 'error' ) ;
2015-12-07 00:24:06 +03:00
2017-10-31 18:27:25 +03:00
await fillIn ( '[data-test-location-input]' , '' ) ;
await fillIn ( '[data-test-website-input]' , 'thisisntawebsite' ) ;
2019-01-02 12:58:55 +03:00
await blur ( '[data-test-website-input]' ) ;
2015-12-07 00:24:06 +03:00
2019-01-02 12:58:55 +03:00
expect (
find ( '[data-test-website-input]' ) . closest ( '.form-group' ) ,
'website input should be in error state'
) . to . have . class ( 'error' ) ;
2015-12-07 00:24:06 +03:00
2018-01-05 18:38:23 +03:00
let testSocialInput = async function ( type , input , expectedValue , expectedError = '' ) {
2017-11-10 19:38:30 +03:00
await fillIn ( ` [data-test- ${ type } -input] ` , input ) ;
2019-01-02 12:58:55 +03:00
await blur ( ` [data-test- ${ type } -input] ` ) ;
2017-11-10 19:38:30 +03:00
expect (
2019-01-02 12:58:55 +03:00
find ( ` [data-test- ${ type } -input] ` ) . value ,
2017-11-10 19:38:30 +03:00
` ${ type } value for ${ input } `
) . to . equal ( expectedValue ) ;
expect (
2019-01-02 12:58:55 +03:00
find ( ` [data-test-error="user- ${ type } "] ` ) . textContent . trim ( ) ,
2017-11-10 19:38:30 +03:00
` ${ type } validation response for ${ input } `
) . to . equal ( expectedError ) ;
expect (
2019-01-02 12:58:55 +03:00
find ( ` [data-test-error="user- ${ type } "] ` ) . closest ( '.form-group' ) . classList . contains ( 'error' ) ,
2017-11-10 19:38:30 +03:00
` ${ type } input should be in error state with ' ${ input } ' `
) . to . equal ( ! ! expectedError ) ;
} ;
let testFacebookValidation = async ( ... args ) => testSocialInput ( 'facebook' , ... args ) ;
let testTwitterValidation = async ( ... args ) => testSocialInput ( 'twitter' , ... args ) ;
2016-05-16 21:16:40 +03:00
// Testing Facebook input
2016-05-17 21:14:14 +03:00
2017-04-24 15:29:48 +03:00
// displays initial value
2019-01-02 12:58:55 +03:00
expect ( find ( '[data-test-facebook-input]' ) . value , 'initial facebook value' )
2017-04-24 15:29:48 +03:00
. to . equal ( 'https://www.facebook.com/test' ) ;
2016-05-17 21:14:14 +03:00
2019-01-02 12:58:55 +03:00
await focus ( '[data-test-facebook-input]' ) ;
await blur ( '[data-test-facebook-input]' ) ;
2016-05-17 21:14:14 +03:00
2017-04-24 15:29:48 +03:00
// regression test: we still have a value after the input is
// focused and then blurred without any changes
2019-01-02 12:58:55 +03:00
expect ( find ( '[data-test-facebook-input]' ) . value , 'facebook value after blur with no change' )
2017-04-24 15:29:48 +03:00
. to . equal ( 'https://www.facebook.com/test' ) ;
2016-05-17 21:14:14 +03:00
2017-11-10 19:38:30 +03:00
await testFacebookValidation (
'facebook.com/username' ,
'https://www.facebook.com/username' ) ;
2016-03-03 11:52:27 +03:00
2017-11-10 19:38:30 +03:00
await testFacebookValidation (
'testuser' ,
'https://www.facebook.com/testuser' ) ;
2016-03-03 11:52:27 +03:00
2017-11-10 19:38:30 +03:00
await testFacebookValidation (
'ab99' ,
'https://www.facebook.com/ab99' ) ;
2016-03-03 11:52:27 +03:00
2017-11-10 19:38:30 +03:00
await testFacebookValidation (
'page/ab99' ,
'https://www.facebook.com/page/ab99' ) ;
2016-03-03 11:52:27 +03:00
2017-11-10 19:38:30 +03:00
await testFacebookValidation (
'page/*(&*(%%))' ,
'https://www.facebook.com/page/*(&*(%%))' ) ;
2016-05-16 21:16:40 +03:00
2017-11-10 19:38:30 +03:00
await testFacebookValidation (
'facebook.com/pages/some-facebook-page/857469375913?ref=ts' ,
'https://www.facebook.com/pages/some-facebook-page/857469375913?ref=ts' ) ;
2016-05-16 21:16:40 +03:00
2017-11-10 19:38:30 +03:00
await testFacebookValidation (
'https://www.facebook.com/groups/savethecrowninn' ,
'https://www.facebook.com/groups/savethecrowninn' ) ;
2016-05-16 21:16:40 +03:00
2017-11-10 19:38:30 +03:00
await testFacebookValidation (
'http://github.com/username' ,
'http://github.com/username' ,
'The URL must be in a format like https://www.facebook.com/yourPage' ) ;
2016-03-03 11:52:27 +03:00
2017-11-10 19:38:30 +03:00
await testFacebookValidation (
'http://github.com/pages/username' ,
'http://github.com/pages/username' ,
'The URL must be in a format like https://www.facebook.com/yourPage' ) ;
2016-03-03 11:52:27 +03:00
2016-05-16 21:16:40 +03:00
// Testing Twitter input
2016-05-17 21:14:14 +03:00
2017-04-24 15:29:48 +03:00
// loads fixtures and performs transform
2019-01-02 12:58:55 +03:00
expect ( find ( '[data-test-twitter-input]' ) . value , 'initial twitter value' )
2017-04-24 15:29:48 +03:00
. to . equal ( 'https://twitter.com/test' ) ;
2016-05-17 21:14:14 +03:00
2019-01-02 12:58:55 +03:00
await focus ( '[data-test-twitter-input]' ) ;
await blur ( '[data-test-twitter-input]' ) ;
2016-05-17 21:14:14 +03:00
2017-04-24 15:29:48 +03:00
// regression test: we still have a value after the input is
// focused and then blurred without any changes
2019-01-02 12:58:55 +03:00
expect ( find ( '[data-test-twitter-input]' ) . value , 'twitter value after blur with no change' )
2017-04-24 15:29:48 +03:00
. to . equal ( 'https://twitter.com/test' ) ;
2016-05-17 21:14:14 +03:00
2017-11-10 19:38:30 +03:00
await testTwitterValidation (
'twitter.com/username' ,
'https://twitter.com/username' ) ;
2016-03-03 11:52:27 +03:00
2017-11-10 19:38:30 +03:00
await testTwitterValidation (
'testuser' ,
'https://twitter.com/testuser' ) ;
2016-03-03 11:52:27 +03:00
2017-11-10 19:38:30 +03:00
await testTwitterValidation (
'http://github.com/username' ,
'https://twitter.com/username' ) ;
2016-03-03 11:52:27 +03:00
2017-11-10 19:38:30 +03:00
await testTwitterValidation (
'*(&*(%%))' ,
'*(&*(%%))' ,
'The URL must be in a format like https://twitter.com/yourUsername' ) ;
2016-03-03 11:52:27 +03:00
2017-11-10 19:38:30 +03:00
await testTwitterValidation (
'thisusernamehasmorethan15characters' ,
'thisusernamehasmorethan15characters' ,
'Your Username is not a valid Twitter Username' ) ;
2016-03-03 11:52:27 +03:00
2017-11-10 19:38:30 +03:00
// Testing bio input
2016-03-03 11:52:27 +03:00
2017-10-31 18:27:25 +03:00
await fillIn ( '[data-test-website-input]' , '' ) ;
await fillIn ( '[data-test-bio-input]' , new Array ( 210 ) . join ( 'a' ) ) ;
2019-01-02 12:58:55 +03:00
await blur ( '[data-test-bio-input]' ) ;
2015-12-07 00:24:06 +03:00
2019-01-02 12:58:55 +03:00
expect (
find ( '[data-test-bio-input]' ) . closest ( '.form-group' ) ,
'bio input should be in error state'
) . to . have . class ( 'error' ) ;
2016-06-14 14:46:24 +03:00
// password reset ------
// button triggers validation
2017-10-31 18:27:25 +03:00
await click ( '[data-test-save-pw-button]' ) ;
2017-04-24 15:29:48 +03:00
expect (
2019-01-02 12:58:55 +03:00
find ( '[data-test-new-pass-input]' ) . closest ( '.form-group' ) ,
2017-04-24 15:29:48 +03:00
'new password has error class when blank'
2019-01-02 12:58:55 +03:00
) . to . have . class ( 'error' ) ;
2017-04-24 15:29:48 +03:00
expect (
2019-01-02 12:58:55 +03:00
find ( '[data-test-error="user-new-pass"]' ) . textContent ,
2017-04-24 15:29:48 +03:00
'new password error when blank'
2019-01-02 12:58:55 +03:00
) . to . have . string ( 'can\'t be blank' ) ;
2016-06-14 14:46:24 +03:00
2017-10-18 19:46:25 +03:00
// validates too short password (< 10 characters)
2017-10-31 18:27:25 +03:00
await fillIn ( '[data-test-new-pass-input]' , 'notlong' ) ;
await fillIn ( '[data-test-ne2-pass-input]' , 'notlong' ) ;
2017-10-18 19:46:25 +03:00
// enter key triggers action
2022-10-05 14:05:31 +03:00
await submitForm ( '[data-test-new-pass-input]' ) ;
2017-10-18 19:46:25 +03:00
expect (
2019-01-02 12:58:55 +03:00
find ( '[data-test-new-pass-input]' ) . closest ( '.form-group' ) ,
2017-10-18 19:46:25 +03:00
'new password has error class when password too short'
2019-01-02 12:58:55 +03:00
) . to . have . class ( 'error' ) ;
2017-10-18 19:46:25 +03:00
expect (
2019-01-02 12:58:55 +03:00
find ( '[data-test-error="user-new-pass"]' ) . textContent ,
'new password error when it\'s too short'
) . to . have . string ( 'at least 10 characters long' ) ;
2017-10-18 19:46:25 +03:00
2017-10-26 13:02:17 +03:00
// validates unsafe password
await fillIn ( '#user-password-new' , 'ghostisawesome' ) ;
2019-01-02 12:58:55 +03:00
await fillIn ( '[data-test-ne2-pass-input]' , 'ghostisawesome' ) ;
2017-10-26 13:02:17 +03:00
// enter key triggers action
2022-10-05 14:05:31 +03:00
await submitForm ( '#user-password-new' ) ;
2017-10-26 13:02:17 +03:00
expect (
2019-01-02 12:58:55 +03:00
find ( '#user-password-new' ) . closest ( '.form-group' ) ,
2017-10-26 13:02:17 +03:00
'new password has error class when password is insecure'
2019-01-02 12:58:55 +03:00
) . to . have . class ( 'error' ) ;
2017-10-26 13:02:17 +03:00
expect (
2019-01-02 12:58:55 +03:00
find ( '[data-test-error="user-new-pass"]' ) . textContent ,
'new password error when it\'s insecure'
2017-10-26 13:02:17 +03:00
) . to . match ( /you cannot use an insecure password/ ) ;
2017-10-18 19:46:25 +03:00
// typing in inputs clears validation
2017-10-31 18:27:25 +03:00
await fillIn ( '[data-test-new-pass-input]' , 'thisissupersafe' ) ;
await triggerEvent ( '[data-test-new-pass-input]' , 'input' ) ;
2017-04-24 15:29:48 +03:00
expect (
2019-01-02 12:58:55 +03:00
find ( '[data-test-new-pass-input]' ) . closest ( '.form-group' ) ,
2017-04-24 15:29:48 +03:00
'password validation is visible after typing'
2019-01-02 12:58:55 +03:00
) . to . not . have . class ( 'error' ) ;
2016-06-14 14:46:24 +03:00
// enter key triggers action
2022-10-05 14:05:31 +03:00
await submitForm ( '[data-test-new-pass-input]' ) ;
2017-04-24 15:29:48 +03:00
expect (
2019-01-02 12:58:55 +03:00
find ( '[data-test-ne2-pass-input]' ) . closest ( '.form-group' ) ,
2017-04-24 15:29:48 +03:00
'confirm password has error class when it doesn\'t match'
2019-01-02 12:58:55 +03:00
) . to . have . class ( 'error' ) ;
2017-04-24 15:29:48 +03:00
expect (
2019-01-02 12:58:55 +03:00
find ( '[data-test-error="user-ne2-pass"]' ) . textContent ,
2017-04-24 15:29:48 +03:00
'confirm password error when it doesn\'t match'
2019-01-02 12:58:55 +03:00
) . to . have . string ( 'do not match' ) ;
2016-06-14 14:46:24 +03:00
// submits with correct details
2017-10-31 18:27:25 +03:00
await fillIn ( '[data-test-ne2-pass-input]' , 'thisissupersafe' ) ;
await click ( '[data-test-save-pw-button]' ) ;
2017-04-24 15:29:48 +03:00
// hits the endpoint
2019-01-02 12:58:55 +03:00
let [ newRequest ] = this . server . pretender . handledRequests . slice ( - 1 ) ;
2017-05-18 13:48:37 +03:00
params = JSON . parse ( newRequest . requestBody ) ;
2017-04-24 15:29:48 +03:00
2017-05-18 13:48:37 +03:00
expect ( newRequest . url , 'password request URL' )
2017-04-24 15:29:48 +03:00
. to . match ( /\/users\/password/ ) ;
// eslint-disable-next-line camelcase
expect ( params . password [ 0 ] . user _id ) . to . equal ( user . id . toString ( ) ) ;
2017-10-26 13:02:17 +03:00
expect ( params . password [ 0 ] . newPassword ) . to . equal ( 'thisissupersafe' ) ;
expect ( params . password [ 0 ] . ne2Password ) . to . equal ( 'thisissupersafe' ) ;
2017-04-24 15:29:48 +03:00
// clears the fields
expect (
2019-01-02 12:58:55 +03:00
find ( '[data-test-new-pass-input]' ) . value ,
2017-04-24 15:29:48 +03:00
'password field after submit'
2018-03-26 13:41:45 +03:00
) . to . be . empty ;
2017-04-24 15:29:48 +03:00
expect (
2019-01-02 12:58:55 +03:00
find ( '[data-test-ne2-pass-input]' ) . value ,
2017-04-24 15:29:48 +03:00
'password verification field after submit'
2018-03-26 13:41:45 +03:00
) . to . be . empty ;
2017-04-24 15:29:48 +03:00
// displays a notification
expect (
2019-01-02 12:58:55 +03:00
findAll ( '.gh-notifications .gh-notification' ) . length ,
2017-04-24 15:29:48 +03:00
'password saved notification is displayed'
) . to . equal ( 1 ) ;
2016-06-14 14:46:24 +03:00
} ) ;
2017-10-31 18:27:25 +03:00
it ( 'warns when leaving without saving' , async function ( ) {
2021-11-04 11:40:24 +03:00
await visit ( '/settings/staff/test-1' ) ;
2017-10-31 18:27:25 +03:00
2021-11-04 11:40:24 +03:00
expect ( currentURL ( ) , 'currentURL' ) . to . equal ( '/settings/staff/test-1' ) ;
2017-10-31 18:27:25 +03:00
await fillIn ( '[data-test-slug-input]' , 'another slug' ) ;
2019-01-02 12:58:55 +03:00
await blur ( '[data-test-slug-input]' ) ;
2017-10-31 18:27:25 +03:00
2019-01-02 12:58:55 +03:00
expect ( find ( '[data-test-slug-input]' ) . value ) . to . be . equal ( 'another-slug' ) ;
2017-10-31 18:27:25 +03:00
await fillIn ( '[data-test-facebook-input]' , 'testuser' ) ;
2019-01-02 12:58:55 +03:00
await blur ( '[data-test-facebook-input]' ) ;
2017-10-31 18:27:25 +03:00
2019-01-02 12:58:55 +03:00
expect ( find ( '[data-test-facebook-input]' ) . value ) . to . be . equal ( 'https://www.facebook.com/testuser' ) ;
2017-10-31 18:27:25 +03:00
2019-02-22 12:43:35 +03:00
await visit ( '/settings/staff' ) ;
2017-10-31 18:27:25 +03:00
2019-01-02 12:58:55 +03:00
expect ( findAll ( '[data-test-modal]' ) . length , 'modal exists' ) . to . equal ( 1 ) ;
2017-10-31 18:27:25 +03:00
// Leave without saving
2022-09-09 19:33:57 +03:00
await click ( '[data-test-modal="unsaved-settings"] [data-test-leave-button]' ) ;
2017-10-31 18:27:25 +03:00
2019-02-22 12:43:35 +03:00
expect ( currentURL ( ) , 'currentURL' ) . to . equal ( '/settings/staff' ) ;
2017-10-31 18:27:25 +03:00
2021-11-04 11:40:24 +03:00
await visit ( '/settings/staff/test-1' ) ;
2017-10-31 18:27:25 +03:00
2021-11-04 11:40:24 +03:00
expect ( currentURL ( ) , 'currentURL' ) . to . equal ( '/settings/staff/test-1' ) ;
2017-10-31 18:27:25 +03:00
// settings were not saved
2019-01-02 12:58:55 +03:00
expect ( find ( '[data-test-slug-input]' ) . value ) . to . be . equal ( 'test-1' ) ;
expect ( find ( '[data-test-facebook-input]' ) . value ) . to . be . equal ( 'https://www.facebook.com/test' ) ;
2017-10-31 18:27:25 +03:00
} ) ;
2022-08-25 13:17:14 +03:00
it ( 'cannot see email alerts for other user' , async function ( ) {
await visit ( '/settings/staff/test-1' ) ;
expect ( find ( '[data-test-checkbox="free-signup-notifications"]' ) , 'free signup alert' ) . to . not . exist ;
expect ( find ( '[data-test-checkbox="paid-started-notifications"]' ) , 'paid start alert' ) . to . not . exist ;
expect ( find ( '[data-test-checkbox="paid-canceled-notifications"]' ) , 'paid cancel alert' ) . to . not . exist ;
} ) ;
2016-06-14 14:46:24 +03:00
} ) ;
describe ( 'own user' , function ( ) {
2017-04-24 15:29:48 +03:00
it ( 'requires current password when changing password' , async function ( ) {
2021-11-04 11:40:24 +03:00
await visit ( ` /settings/staff/ ${ admin . slug } ` ) ;
2016-06-14 14:46:24 +03:00
// test the "old password" field is validated
2017-10-31 18:27:25 +03:00
await click ( '[data-test-save-pw-button]' ) ;
2017-04-24 15:29:48 +03:00
// old password has error
expect (
2019-01-02 12:58:55 +03:00
find ( '[data-test-old-pass-input]' ) . closest ( '.form-group' ) ,
2017-04-24 15:29:48 +03:00
'old password has error class when blank'
2019-01-02 12:58:55 +03:00
) . to . have . class ( 'error' ) ;
2017-04-24 15:29:48 +03:00
expect (
2019-01-02 12:58:55 +03:00
find ( '[data-test-error="user-old-pass"]' ) . textContent ,
2017-04-24 15:29:48 +03:00
'old password error when blank'
2019-01-02 12:58:55 +03:00
) . to . have . string ( 'is required' ) ;
2017-04-24 15:29:48 +03:00
// new password has error
expect (
2019-01-02 12:58:55 +03:00
find ( '[data-test-new-pass-input]' ) . closest ( '.form-group' ) ,
2017-04-24 15:29:48 +03:00
'new password has error class when blank'
2019-01-02 12:58:55 +03:00
) . to . have . class ( 'error' ) ;
2017-04-24 15:29:48 +03:00
expect (
2019-01-02 12:58:55 +03:00
find ( '[data-test-error="user-new-pass"]' ) . textContent ,
2017-04-24 15:29:48 +03:00
'new password error when blank'
2019-01-02 12:58:55 +03:00
) . to . have . string ( 'can\'t be blank' ) ;
2016-06-14 14:46:24 +03:00
// validation is cleared when typing
2017-10-31 18:27:25 +03:00
await fillIn ( '[data-test-old-pass-input]' , 'password' ) ;
await triggerEvent ( '[data-test-old-pass-input]' , 'input' ) ;
2017-04-24 15:29:48 +03:00
expect (
2019-01-02 12:58:55 +03:00
find ( '[data-test-old-pass-input]' ) . closest ( '.form-group' ) ,
2017-04-24 15:29:48 +03:00
'old password validation is in error state after typing'
2019-01-02 12:58:55 +03:00
) . to . not . have . class ( 'error' ) ;
2015-12-07 00:24:06 +03:00
} ) ;
2022-08-25 13:17:14 +03:00
it ( 'can toggle email alerts for own user' , async function ( ) {
await visit ( ` /settings/staff/ ${ admin . slug } ` ) ;
expect ( find ( '[data-test-checkbox="free-signup-notifications"]' ) ) . to . not . be . checked ;
expect ( find ( '[data-test-checkbox="paid-started-notifications"]' ) ) . to . not . be . checked ;
expect ( find ( '[data-test-checkbox="paid-canceled-notifications"]' ) ) . to . not . be . checked ;
await click ( '[data-test-label="free-signup-notifications"]' ) ;
await click ( '[data-test-label="paid-started-notifications"]' ) ;
await click ( '[data-test-label="paid-canceled-notifications"]' ) ;
await click ( '[data-test-save-button]' ) ;
await visit ( ` /settings/staff/ ${ admin . slug } ` ) ;
expect ( find ( '[data-test-checkbox="free-signup-notifications"]' ) ) . to . be . checked ;
expect ( find ( '[data-test-checkbox="paid-started-notifications"]' ) ) . to . be . checked ;
expect ( find ( '[data-test-checkbox="paid-canceled-notifications"]' ) ) . to . be . checked ;
} ) ;
2015-12-07 00:24:06 +03:00
} ) ;
2017-04-24 15:29:48 +03:00
it ( 'redirects to 404 when user does not exist' , async function ( ) {
2019-01-02 12:58:55 +03:00
this . server . get ( '/users/slug/unknown/' , function ( ) {
2019-03-25 14:29:14 +03:00
return new Response ( 404 , { 'Content-Type' : 'application/json' } , { errors : [ { message : 'User not found.' , type : 'NotFoundError' } ] } ) ;
2015-12-07 00:24:06 +03:00
} ) ;
2021-11-04 11:40:24 +03:00
await visit ( '/settings/staff/unknown' ) ;
2015-12-07 00:24:06 +03:00
2019-01-02 12:58:55 +03:00
expect ( currentRouteName ( ) ) . to . equal ( 'error404' ) ;
2021-11-04 11:40:24 +03:00
expect ( currentURL ( ) ) . to . equal ( '/settings/staff/unknown' ) ;
2015-12-07 00:24:06 +03:00
} ) ;
} ) ;
2016-09-26 19:03:53 +03:00
2022-08-26 12:54:03 +03:00
describe ( 'when logged in as owner' , function ( ) {
2022-08-26 12:59:06 +03:00
let admin , adminRole , ownerRole ;
2022-08-26 12:54:03 +03:00
beforeEach ( async function ( ) {
this . server . loadFixtures ( 'roles' ) ;
this . server . loadFixtures ( 'settings' ) ;
adminRole = this . server . schema . roles . find ( 1 ) ;
enableMembers ( this . server ) ;
enableStripe ( this . server ) ;
enableLabsFlag ( this . server , 'emailAlerts' ) ;
ownerRole = this . server . create ( 'role' , { name : 'Owner' } ) ;
admin = this . server . create ( 'user' , { email : 'admin@example.com' , roles : [ ownerRole ] } ) ;
// add an expired invite
this . server . create ( 'invite' , { expires : moment . utc ( ) . subtract ( 1 , 'day' ) . valueOf ( ) , role : adminRole } ) ;
return await authenticateSession ( ) ;
} ) ;
describe ( 'existing user' , function ( ) {
beforeEach ( function ( ) {
this . server . create ( 'user' , {
slug : 'test-1' ,
name : 'Test User' ,
facebook : 'test' ,
twitter : '@test'
} ) ;
} ) ;
it ( 'cannot see email alerts for other user' , async function ( ) {
await visit ( '/settings/staff/test-1' ) ;
expect ( find ( '[data-test-checkbox="free-signup-notifications"]' ) , 'free signup alert' ) . to . not . exist ;
expect ( find ( '[data-test-checkbox="paid-started-notifications"]' ) , 'paid start alert' ) . to . not . exist ;
expect ( find ( '[data-test-checkbox="paid-canceled-notifications"]' ) , 'paid cancel alert' ) . to . not . exist ;
} ) ;
} ) ;
describe ( 'own user' , function ( ) {
it ( 'can toggle email alerts for own user' , async function ( ) {
await visit ( ` /settings/staff/ ${ admin . slug } ` ) ;
expect ( find ( '[data-test-checkbox="free-signup-notifications"]' ) ) . to . not . be . checked ;
expect ( find ( '[data-test-checkbox="paid-started-notifications"]' ) ) . to . not . be . checked ;
expect ( find ( '[data-test-checkbox="paid-canceled-notifications"]' ) ) . to . not . be . checked ;
await click ( '[data-test-label="free-signup-notifications"]' ) ;
await click ( '[data-test-label="paid-started-notifications"]' ) ;
await click ( '[data-test-label="paid-canceled-notifications"]' ) ;
await click ( '[data-test-save-button]' ) ;
await visit ( ` /settings/staff/ ${ admin . slug } ` ) ;
expect ( find ( '[data-test-checkbox="free-signup-notifications"]' ) ) . to . be . checked ;
expect ( find ( '[data-test-checkbox="paid-started-notifications"]' ) ) . to . be . checked ;
expect ( find ( '[data-test-checkbox="paid-canceled-notifications"]' ) ) . to . be . checked ;
} ) ;
} ) ;
} ) ;
2016-09-26 19:03:53 +03:00
describe ( 'when logged in as author' , function ( ) {
2016-11-14 16:16:51 +03:00
let adminRole , authorRole ;
2016-09-26 19:03:53 +03:00
2019-01-02 12:58:55 +03:00
beforeEach ( async function ( ) {
adminRole = this . server . create ( 'role' , { name : 'Administrator' } ) ;
authorRole = this . server . create ( 'role' , { name : 'Author' } ) ;
this . server . create ( 'user' , { roles : [ authorRole ] } ) ;
2016-09-26 19:03:53 +03:00
2019-01-02 12:58:55 +03:00
this . server . get ( '/invites/' , function ( ) {
2017-01-02 21:50:36 +03:00
return new Response ( 403 , { } , {
2016-09-26 19:03:53 +03:00
errors : [ {
2019-03-25 14:29:14 +03:00
type : 'NoPermissionError' ,
2016-09-26 19:03:53 +03:00
message : 'You do not have permission to perform this action'
} ]
} ) ;
} ) ;
2019-01-02 12:58:55 +03:00
return await authenticateSession ( ) ;
2016-09-26 19:03:53 +03:00
} ) ;
2022-01-26 17:49:50 +03:00
it ( 'is redirected to user profile page' , async function ( ) {
2019-01-02 12:58:55 +03:00
this . server . create ( 'user' , { roles : [ adminRole ] } ) ;
this . server . create ( 'invite' , { role : authorRole } ) ;
2016-09-26 19:03:53 +03:00
2021-11-04 11:40:24 +03:00
await visit ( '/settings/staff' ) ;
2016-09-26 19:03:53 +03:00
2022-01-26 17:49:50 +03:00
expect ( currentRouteName ( ) ) . to . equal ( 'settings.staff.user' ) ;
2019-01-02 12:58:55 +03:00
expect ( findAll ( '.gh-alert' ) . length ) . to . equal ( 0 ) ;
2016-09-26 19:03:53 +03:00
} ) ;
} ) ;
2015-12-07 00:24:06 +03:00
} ) ;