2015-12-07 00:24:06 +03:00
/* jshint expr:true */
2017-05-29 21:50:03 +03:00
import ctrlOrCmd from 'ghost-admin/utils/ctrl-or-cmd' ;
2015-12-07 00:24:06 +03:00
import destroyApp from '../helpers/destroy-app' ;
2017-04-05 20:45:35 +03:00
import moment from 'moment' ;
2017-05-29 21:50:03 +03:00
import startApp from '../helpers/start-app' ;
2017-11-10 17:19:20 +03:00
import windowProxy from 'ghost-admin/utils/window-proxy' ;
2017-05-29 21:50:03 +03:00
import { Response } from 'ember-cli-mirage' ;
import { afterEach , beforeEach , describe , it } from 'mocha' ;
import { authenticateSession , invalidateSession } from '../helpers/ember-simple-auth' ;
import { errorOverride , errorReset } from '../helpers/adapter-error' ;
import { expect } from 'chai' ;
2015-12-07 00:24:06 +03:00
describe ( 'Acceptance: Team' , function ( ) {
let application ;
beforeEach ( function ( ) {
application = startApp ( ) ;
} ) ;
afterEach ( function ( ) {
destroyApp ( application ) ;
} ) ;
2017-04-24 15:29:48 +03:00
it ( 'redirects to signin when not authenticated' , async function ( ) {
2015-12-07 00:24:06 +03:00
invalidateSession ( application ) ;
2017-04-24 15:29:48 +03:00
await visit ( '/team' ) ;
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
} ) ;
2017-04-24 15:29:48 +03:00
it ( 'redirects correctly when authenticated as author' , async function ( ) {
2016-04-08 18:00:16 +03:00
let role = server . create ( 'role' , { name : 'Author' } ) ;
2016-11-14 16:16:51 +03:00
server . create ( 'user' , { roles : [ role ] , slug : 'test-user' } ) ;
2015-12-07 00:24:06 +03:00
server . create ( 'user' , { slug : 'no-access' } ) ;
authenticateSession ( application ) ;
2017-04-24 15:29:48 +03:00
await visit ( '/team/no-access' ) ;
2015-12-07 00:24:06 +03:00
2017-04-24 15:29:48 +03:00
expect ( currentURL ( ) , 'currentURL' ) . to . equal ( '/team/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 ( ) {
2016-04-08 18:00:16 +03:00
let role = server . create ( 'role' , { name : 'Editor' } ) ;
2016-11-14 16:16:51 +03:00
server . create ( 'user' , { roles : [ role ] , slug : 'test-user' } ) ;
2015-12-07 00:24:06 +03:00
server . create ( 'user' , { slug : 'no-access' } ) ;
authenticateSession ( application ) ;
2017-04-24 15:29:48 +03:00
await visit ( '/team/no-access' ) ;
2015-12-07 00:24:06 +03:00
2017-04-24 15:29:48 +03:00
expect ( currentURL ( ) , 'currentURL' ) . to . equal ( '/team' ) ;
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
2015-12-07 00:24:06 +03:00
beforeEach ( function ( ) {
2017-01-02 21:50:36 +03:00
server . loadFixtures ( 'roles' ) ;
adminRole = server . schema . roles . find ( 1 ) ;
2015-12-07 00:24:06 +03:00
2017-01-02 21:50:36 +03:00
admin = 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
server . create ( 'invite' , { expires : moment . utc ( ) . subtract ( 1 , 'day' ) . valueOf ( ) } ) ;
2017-03-08 21:21:35 +03:00
// add a suspended user
suspendedUser = server . create ( 'user' , { email : 'suspended@example.com' , roles : [ adminRole ] , status : 'inactive' } ) ;
2015-12-07 00:24:06 +03:00
return authenticateSession ( application ) ;
} ) ;
2017-04-24 15:29:48 +03:00
it ( 'it renders and navigates correctly' , async function ( ) {
2017-03-08 21:21:35 +03:00
let user1 = server . create ( 'user' ) ;
2016-04-08 18:00:16 +03:00
let user2 = server . create ( 'user' ) ;
2015-12-07 00:24:06 +03:00
2017-04-24 15:29:48 +03:00
await visit ( '/team' ) ;
2015-12-07 00:24:06 +03:00
2017-04-24 15:29:48 +03:00
// doesn't do any redirecting
expect ( currentURL ( ) , 'currentURL' ) . to . equal ( '/team' ) ;
2015-12-07 00:24:06 +03:00
2017-04-24 15:29:48 +03:00
// it has correct page title
expect ( document . title , 'page title' ) . to . equal ( 'Team - Test Blog' ) ;
// it shows active users in active section
expect (
2017-08-11 18:28:05 +03:00
find ( '[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 (
2017-08-11 18:28:05 +03:00
find ( '[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
expect ( currentURL ( ) , 'url after clicking user' ) . to . equal ( ` /team/ ${ user2 . slug } ` ) ;
// title is correct
expect ( document . title , 'title after clicking user' ) . to . equal ( 'Team - User - Test Blog' ) ;
// view title should exist and be linkable and active
2017-05-30 16:23:38 +03:00
expect (
2017-08-11 18:28:05 +03:00
find ( '[data-test-screen-title] a[href="/ghost/team"]' ) . hasClass ( 'active' ) ,
2017-05-30 16:23:38 +03:00
'has linkable url back to team main page'
) . to . be . true ;
2017-04-24 15:29:48 +03:00
2017-08-11 18:28:05 +03:00
await click ( '[data-test-screen-title] a' ) ;
2017-04-24 15:29:48 +03:00
// url should be /team again
expect ( currentURL ( ) , 'url after clicking back' ) . to . equal ( '/team' ) ;
2015-12-07 00:24:06 +03:00
} ) ;
2017-04-24 15:29:48 +03:00
it ( 'can manage invites' , async function ( ) {
await visit ( '/team' ) ;
// invite user button exists
expect (
find ( '.view-actions .gh-btn-green' ) . text ( ) . trim ( ) ,
'invite people button text'
) . to . equal ( 'Invite People' ) ;
// existing users are listed
expect (
2017-08-11 18:28:05 +03:00
find ( '[data-test-user-id]' ) . length ,
2017-04-24 15:29:48 +03:00
'initial number of active users'
) . to . equal ( 2 ) ;
expect (
2017-08-11 18:28:05 +03:00
find ( '[data-test-user-id="1"] [data-test-role-name]' ) . text ( ) . trim ( ) ,
2017-04-24 15:29:48 +03:00
'active user\'s role label'
) . to . equal ( 'Administrator' ) ;
// existing invites are shown
expect (
2017-08-11 18:28:05 +03:00
find ( '[data-test-invite-id]' ) . length ,
2017-04-24 15:29:48 +03:00
'initial number of invited users'
) . to . equal ( 1 ) ;
expect (
2017-08-11 18:28:05 +03:00
find ( '[data-test-invite-id="1"] [data-test-invite-description]' ) . text ( ) ,
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 (
2017-08-11 18:28:05 +03:00
find ( '[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
2017-04-24 15:29:48 +03:00
await click ( '.view-actions .gh-btn-green' ) ;
2015-12-07 00:24:06 +03:00
2017-04-24 15:29:48 +03:00
let roleOptions = find ( '.fullscreen-modal select[name="role"] option' ) ;
2016-09-26 19:03:53 +03:00
2017-04-24 15:29:48 +03:00
function checkOwnerExists ( ) {
for ( let i in roleOptions ) {
if ( roleOptions [ i ] . tagName === 'option' && roleOptions [ i ] . text === 'Owner' ) {
return true ;
2015-12-07 00:24:06 +03:00
}
2016-09-26 19:03:53 +03:00
}
2017-04-24 15:29:48 +03:00
return false ;
}
2015-12-07 00:24:06 +03:00
2017-04-24 15:29:48 +03:00
function checkSelectedIsAuthor ( ) {
for ( let i in roleOptions ) {
if ( roleOptions [ i ] . selected ) {
return roleOptions [ i ] . text === 'Author' ;
2015-12-07 00:24:06 +03:00
}
2016-09-26 19:03:53 +03:00
}
2017-04-24 15:29:48 +03:00
return false ;
}
2015-12-07 00:24:06 +03:00
2017-04-24 15:29:48 +03:00
// modal is displayed
expect (
find ( '.fullscreen-modal h1' ) . text ( ) . trim ( ) ,
'correct modal is displayed'
) . to . equal ( 'Invite a New User' ) ;
2015-12-07 00:24:06 +03:00
2017-04-24 15:29:48 +03:00
// number of roles is correct
expect (
find ( '.fullscreen-modal select[name="role"] option' ) . length ,
'number of selectable roles'
) . to . equal ( 3 ) ;
2016-09-26 19:03:53 +03:00
2017-04-24 15:29:48 +03:00
expect ( checkOwnerExists ( ) , 'owner role isn\'t available' ) . to . be . false ;
expect ( checkSelectedIsAuthor ( ) , 'author role is selected initially' ) . to . be . true ;
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' ) ;
await click ( '.fullscreen-modal .gh-btn-green' ) ;
// modal closes
expect (
find ( '.fullscreen-modal' ) . length ,
'number of modals after sending invite'
) . to . equal ( 0 ) ;
// invite is displayed, has correct e-mail + role
expect (
2017-08-11 18:28:05 +03:00
find ( '[data-test-invite-id]' ) . length ,
2017-04-24 15:29:48 +03:00
'number of invites after first invite'
) . to . equal ( 1 ) ;
expect (
2017-08-11 18:28:05 +03:00
find ( '[data-test-invite-id="2"] [data-test-email]' ) . text ( ) . trim ( ) ,
2017-04-24 15:29:48 +03:00
'displayed email of first invite'
) . to . equal ( 'invite1@example.com' ) ;
expect (
2017-08-11 18:28:05 +03:00
find ( '[data-test-invite-id="2"] [data-test-role-name]' ) . text ( ) . trim ( ) ,
2017-04-24 15:29:48 +03:00
'displayed role of first invite'
) . to . equal ( 'Author' ) ;
expect (
2017-08-11 18:28:05 +03:00
find ( '[data-test-invite-id="2"] [data-test-invite-description]' ) . text ( ) ,
2017-04-24 15:29:48 +03:00
'new invite description'
) . to . match ( /expires/ ) ;
// number of users is unchanged
expect (
2017-08-11 18:28:05 +03:00
find ( '[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
2017-04-24 15:29:48 +03:00
await click ( '.view-actions .gh-btn-green' ) ;
await fillIn ( '.fullscreen-modal input[name="email"]' , 'invite2@example.com' ) ;
await fillIn ( '.fullscreen-modal select[name="role"]' , '2' ) ;
await click ( '.fullscreen-modal .gh-btn-green' ) ;
// number of invites increases
expect (
2017-08-11 18:28:05 +03:00
find ( '[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 (
2017-08-11 18:28:05 +03:00
find ( '[data-test-invite-id="3"] [data-test-email]' ) . text ( ) . trim ( ) ,
2017-04-24 15:29:48 +03:00
'displayed email of second invite'
) . to . equal ( 'invite2@example.com' ) ;
expect (
2017-08-11 18:28:05 +03:00
find ( '[data-test-invite-id="3"] [data-test-role-name]' ) . text ( ) . 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
2017-04-24 15:29:48 +03:00
await click ( '.view-actions .gh-btn-green' ) ;
await fillIn ( '.fullscreen-modal input[name="email"]' , 'admin@example.com' ) ;
await click ( '.fullscreen-modal .gh-btn-green' ) ;
2015-12-07 00:24:06 +03:00
2017-04-24 15:29:48 +03:00
// validation message is displayed
expect (
find ( '.fullscreen-modal .error .response' ) . text ( ) . trim ( ) ,
'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' ) ;
await click ( '.fullscreen-modal .gh-btn-green' ) ;
2015-12-07 00:24:06 +03:00
2017-04-24 15:29:48 +03:00
// validation message is displayed
expect (
find ( '.fullscreen-modal .error .response' ) . text ( ) . trim ( ) ,
'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' ) ;
await click ( '.fullscreen-modal .gh-btn-green' ) ;
2015-12-07 00:24:06 +03:00
2017-04-24 15:29:48 +03:00
// validation message is displayed
expect (
find ( '.fullscreen-modal .error .response' ) . text ( ) . trim ( ) ,
'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 (
2017-08-11 18:28:05 +03:00
find ( '[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 (
find ( '.gh-notification' ) . text ( ) . trim ( ) ,
'notifications contain revoke'
) . to . match ( /Invitation revoked\. \(invite2@example\.com\)/ ) ;
// correct invite is removed
expect (
2017-08-11 18:28:05 +03:00
find ( '[data-test-invite-id] [data-test-email]' ) . text ( ) . 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
2017-04-24 15:29:48 +03:00
await click ( '.view-actions .gh-btn-green' ) ;
await fillIn ( '.fullscreen-modal input[name="email"]' , 'invite3@example.com' ) ;
await click ( '.fullscreen-modal .gh-btn-green' ) ;
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 (
2017-08-11 18:28:05 +03:00
find ( '[data-test-invite-id]:last [data-test-email]' ) . text ( ) . 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 (
find ( '.gh-notification' ) . text ( ) . trim ( ) ,
'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 (
2017-08-11 18:28:05 +03:00
find ( '[data-test-invite-id]:first-of-type [data-test-email]' ) . text ( ) . 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 (
2017-08-11 18:28:05 +03:00
find ( '[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 (
find ( '.gh-notification' ) . text ( ) . trim ( ) ,
'notifications contain revoke after resend/revoke'
) . to . match ( /Invitation revoked\. \(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 ( ) {
await visit ( '/team' ) ;
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
expect ( '[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
// });
2017-08-11 18:28:05 +03:00
await click ( '[data-test-team-link]' ) ;
2017-03-08 21:21:35 +03:00
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 (
2017-08-11 18:28:05 +03:00
find ( '[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]' ) ;
2017-03-08 21:21:35 +03:00
2017-08-11 18:28:05 +03:00
expect ( '[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 ( ) {
2016-08-24 16:26:29 +03:00
let user1 = server . create ( 'user' ) ;
let user2 = server . create ( 'user' ) ;
2017-01-02 21:50:36 +03:00
let post = server . create ( 'post' ) ;
user2 . posts = [ post ] ;
2016-08-24 16:26:29 +03:00
2017-04-24 15:29:48 +03:00
await visit ( '/team' ) ;
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 (
find ( '.fullscreen-modal .modal-content:contains("delete this user")' ) . length ,
'user deletion modal displayed after button click'
) . to . equal ( 1 ) ;
// user has no posts so no warning about post deletion
expect (
find ( '.fullscreen-modal .modal-content:contains("is the author of")' ) . length ,
'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
2017-04-24 15:29:48 +03:00
await click ( '.fullscreen-modal button:contains("Cancel")' ) ;
expect (
find ( '.fullscreen-modal' ) . length === 0 ,
'delete user modal is closed when cancelling'
) . to . be . true ;
2016-08-24 16:26:29 +03:00
// deleting a user with posts
2017-04-24 15:29:48 +03:00
await visit ( '/team' ) ;
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 (
find ( '.fullscreen-modal .modal-content:contains("is the author of 1 post")' ) . length ,
'deleting user with posts has post count'
) . to . equal ( 1 ) ;
await click ( '.fullscreen-modal button:contains("Delete")' ) ;
// redirected to team page
expect ( currentURL ( ) ) . to . equal ( '/team' ) ;
// deleted user is not in list
expect (
2017-08-11 18:28:05 +03:00
find ( ` [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 ( ) {
2017-11-10 17:19:20 +03:00
let user , newLocation , originalReplaceState ;
2015-12-07 00:24:06 +03:00
beforeEach ( function ( ) {
2016-06-14 14:46:24 +03:00
user = 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
} ) ;
2017-04-24 15:29:48 +03:00
it ( 'input fields reset and validate correctly' , async function ( ) {
2015-12-07 00:24:06 +03:00
// test user name
2017-04-24 15:29:48 +03:00
await visit ( '/team/test-1' ) ;
2015-12-07 00:24:06 +03:00
2017-04-24 15:29:48 +03:00
expect ( currentURL ( ) , 'currentURL' ) . to . equal ( '/team/test-1' ) ;
2017-10-31 18:27:25 +03:00
expect ( find ( '[data-test-name-input]' ) . val ( ) , 'current user name' ) . to . equal ( 'Test User' ) ;
2015-12-07 00:24:06 +03:00
2017-08-11 18:28:05 +03:00
expect ( find ( '[data-test-save-button]' ) . text ( ) . 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]' , '' ) ;
await triggerEvent ( '[data-test-name-input]' , 'blur' ) ;
2015-12-07 00:24:06 +03:00
2017-05-17 15:24:31 +03:00
expect ( find ( '.user-details-bottom .first-form-group' ) . hasClass ( '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' ) ) ;
2017-10-31 18:27:25 +03:00
await triggerEvent ( '[data-test-name-input]' , 'blur' ) ;
2015-12-07 00:24:06 +03:00
2017-05-17 15:24:31 +03:00
expect ( find ( '.user-details-bottom .first-form-group' ) . hasClass ( '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
2017-10-31 18:27:25 +03:00
expect ( find ( '[data-test-slug-input]' ) . val ( ) , '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]' , '' ) ;
await triggerEvent ( '[data-test-slug-input]' , 'blur' ) ;
2015-12-07 00:24:06 +03:00
2017-10-31 18:27:25 +03:00
expect ( find ( '[data-test-slug-input]' ) . val ( ) , '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
2017-08-11 18:28:05 +03:00
expect ( find ( '[data-test-save-button]' ) . text ( ) . trim ( ) , 'save button text' ) . to . equal ( 'Saved' ) ;
2017-05-18 13:48:37 +03:00
// CMD-S shortcut works
2017-10-31 18:27:25 +03:00
await fillIn ( '[data-test-slug-input]' , 'Test User' ) ;
2017-05-18 13:48:37 +03:00
await triggerEvent ( '.gh-app' , 'keydown' , {
keyCode : 83 , // s
metaKey : ctrlOrCmd === 'command' ,
ctrlKey : ctrlOrCmd === 'ctrl'
} ) ;
// we've already saved in this test so there's no on-screen indication
// that we've had another save, check the request was fired instead
let [ lastRequest ] = server . pretender . handledRequests . slice ( - 1 ) ;
let params = JSON . parse ( lastRequest . requestBody ) ;
expect ( params . users [ 0 ] . name ) . to . equal ( 'Test User' ) ;
2017-11-10 17:19:20 +03:00
// check that the history state has been updated
expect ( newLocation ) . to . equal ( 'Test User' ) ;
2017-10-31 18:27:25 +03:00
await fillIn ( '[data-test-slug-input]' , 'white space' ) ;
await triggerEvent ( '[data-test-slug-input]' , 'blur' ) ;
2015-12-07 00:24:06 +03:00
2017-10-31 18:27:25 +03:00
expect ( find ( '[data-test-slug-input]' ) . val ( ) , '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' ) ;
await triggerEvent ( '[data-test-email-input]' , 'blur' ) ;
2015-12-07 00:24:06 +03:00
2017-05-17 15:24:31 +03:00
expect ( find ( '.user-details-bottom .form-group:nth-of-type(3)' ) . hasClass ( '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' ) ) ;
await triggerEvent ( '[data-test-location-input]' , 'blur' ) ;
2015-12-07 00:24:06 +03:00
2017-10-31 18:27:25 +03:00
expect ( find ( '[data-test-location-input]' ) . closest ( '.form-group' ) . hasClass ( 'error' ) , 'location input should be in error state' ) . to . be . true ;
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' ) ;
await triggerEvent ( '[data-test-website-input]' , 'blur' ) ;
2015-12-07 00:24:06 +03:00
2017-10-31 18:27:25 +03:00
expect ( find ( '[data-test-website-input]' ) . closest ( '.form-group' ) . hasClass ( 'error' ) , 'website input should be in error state' ) . to . be . true ;
2015-12-07 00:24:06 +03:00
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
2017-10-31 18:27:25 +03:00
expect ( find ( '[data-test-facebook-input]' ) . val ( ) , '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
2017-10-31 18:27:25 +03:00
await triggerEvent ( '[data-test-facebook-input]' , 'focus' ) ;
await triggerEvent ( '[data-test-facebook-input]' , 'blur' ) ;
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
2017-10-31 18:27:25 +03:00
expect ( find ( '[data-test-facebook-input]' ) . val ( ) , '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-10-31 18:27:25 +03:00
await fillIn ( '[data-test-facebook-input]' , '' ) ;
await fillIn ( '[data-test-facebook-input]' , ')(*&%^%)' ) ;
await triggerEvent ( '[data-test-facebook-input]' , 'blur' ) ;
2016-03-03 11:52:27 +03:00
2017-10-31 18:27:25 +03:00
expect ( find ( '[data-test-facebook-input]' ) . closest ( '.form-group' ) . hasClass ( 'error' ) , 'facebook input should be in error state' ) . to . be . true ;
2016-03-03 11:52:27 +03:00
2017-10-31 18:27:25 +03:00
await fillIn ( '[data-test-facebook-input]' , '' ) ;
await fillIn ( '[data-test-facebook-input]' , 'pages/)(*&%^%)' ) ;
await triggerEvent ( '[data-test-facebook-input]' , 'blur' ) ;
2016-03-03 11:52:27 +03:00
2017-10-31 18:27:25 +03:00
expect ( find ( '[data-test-facebook-input]' ) . val ( ) ) . to . be . equal ( 'https://www.facebook.com/pages/)(*&%^%)' ) ;
expect ( find ( '[data-test-facebook-input]' ) . closest ( '.form-group' ) . hasClass ( 'error' ) , 'facebook input should be in error state' ) . to . be . false ;
2016-03-03 11:52:27 +03:00
2017-10-31 18:27:25 +03:00
await fillIn ( '[data-test-facebook-input]' , '' ) ;
await fillIn ( '[data-test-facebook-input]' , 'testing' ) ;
await triggerEvent ( '[data-test-facebook-input]' , 'blur' ) ;
2016-05-16 21:16:40 +03:00
2017-10-31 18:27:25 +03:00
expect ( find ( '[data-test-facebook-input]' ) . val ( ) ) . to . be . equal ( 'https://www.facebook.com/testing' ) ;
expect ( find ( '[data-test-facebook-input]' ) . closest ( '.form-group' ) . hasClass ( 'error' ) , 'facebook input should be in error state' ) . to . be . false ;
2016-05-16 21:16:40 +03:00
2017-10-31 18:27:25 +03:00
await fillIn ( '[data-test-facebook-input]' , '' ) ;
await fillIn ( '[data-test-facebook-input]' , 'somewebsite.com/pages/some-facebook-page/857469375913?ref=ts' ) ;
await triggerEvent ( '[data-test-facebook-input]' , 'blur' ) ;
2016-05-16 21:16:40 +03:00
2017-10-31 18:27:25 +03:00
expect ( find ( '[data-test-facebook-input]' ) . val ( ) ) . to . be . equal ( 'https://www.facebook.com/pages/some-facebook-page/857469375913?ref=ts' ) ;
expect ( find ( '[data-test-facebook-input]' ) . closest ( '.form-group' ) . hasClass ( 'error' ) , 'facebook input should be in error state' ) . to . be . false ;
2016-05-16 21:16:40 +03:00
2017-10-31 18:27:25 +03:00
await fillIn ( '[data-test-facebook-input]' , '' ) ;
await fillIn ( '[data-test-facebook-input]' , 'test' ) ;
await triggerEvent ( '[data-test-facebook-input]' , 'blur' ) ;
2016-03-03 11:52:27 +03:00
2017-10-31 18:27:25 +03:00
expect ( find ( '[data-test-facebook-input]' ) . val ( ) ) . to . be . equal ( 'https://www.facebook.com/test' ) ;
expect ( find ( '[data-test-facebook-input]' ) . closest ( '.form-group' ) . hasClass ( 'error' ) , 'facebook input should be in error state' ) . to . be . false ;
2016-03-03 11:52:27 +03:00
2017-10-31 18:27:25 +03:00
await fillIn ( '[data-test-facebook-input]' , '' ) ;
await fillIn ( '[data-test-facebook-input]' , 'http://twitter.com/testuser' ) ;
await triggerEvent ( '[data-test-facebook-input]' , 'blur' ) ;
2016-05-16 21:16:40 +03:00
2017-10-31 18:27:25 +03:00
expect ( find ( '[data-test-facebook-input]' ) . val ( ) ) . to . be . equal ( 'https://www.facebook.com/testuser' ) ;
expect ( find ( '[data-test-facebook-input]' ) . closest ( '.form-group' ) . hasClass ( 'error' ) , 'facebook input should be in error state' ) . to . be . false ;
2016-05-16 21:16:40 +03:00
2017-10-31 18:27:25 +03:00
await fillIn ( '[data-test-facebook-input]' , '' ) ;
await fillIn ( '[data-test-facebook-input]' , 'facebook.com/testing' ) ;
await triggerEvent ( '[data-test-facebook-input]' , 'blur' ) ;
2016-03-03 11:52:27 +03:00
2017-10-31 18:27:25 +03:00
expect ( find ( '[data-test-facebook-input]' ) . val ( ) ) . to . be . equal ( 'https://www.facebook.com/testing' ) ;
expect ( find ( '[data-test-facebook-input]' ) . closest ( '.form-group' ) . hasClass ( 'error' ) , 'facebook input should be in error state' ) . to . be . false ;
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
2017-10-31 18:27:25 +03:00
expect ( find ( '[data-test-twitter-input]' ) . val ( ) , '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
2017-10-31 18:27:25 +03:00
await triggerEvent ( '[data-test-twitter-input]' , 'focus' ) ;
await triggerEvent ( '[data-test-twitter-input]' , 'blur' ) ;
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
2017-10-31 18:27:25 +03:00
expect ( find ( '[data-test-twitter-input]' ) . val ( ) , '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-10-31 18:27:25 +03:00
await fillIn ( '[data-test-twitter-input]' , '' ) ;
await fillIn ( '[data-test-twitter-input]' , ')(*&%^%)' ) ;
await triggerEvent ( '[data-test-twitter-input]' , 'blur' ) ;
2016-03-03 11:52:27 +03:00
2017-10-31 18:27:25 +03:00
expect ( find ( '[data-test-twitter-input]' ) . closest ( '.form-group' ) . hasClass ( 'error' ) , 'twitter input should be in error state' ) . to . be . true ;
2016-03-03 11:52:27 +03:00
2017-10-31 18:27:25 +03:00
await fillIn ( '[data-test-twitter-input]' , '' ) ;
await fillIn ( '[data-test-twitter-input]' , 'name' ) ;
await triggerEvent ( '[data-test-twitter-input]' , 'blur' ) ;
2016-03-03 11:52:27 +03:00
2017-10-31 18:27:25 +03:00
expect ( find ( '[data-test-twitter-input]' ) . val ( ) ) . to . be . equal ( 'https://twitter.com/name' ) ;
expect ( find ( '[data-test-twitter-input]' ) . closest ( '.form-group' ) . hasClass ( 'error' ) , 'twitter input should be in error state' ) . to . be . false ;
2016-03-03 11:52:27 +03:00
2017-10-31 18:27:25 +03:00
await fillIn ( '[data-test-twitter-input]' , '' ) ;
await fillIn ( '[data-test-twitter-input]' , 'http://github.com/user' ) ;
await triggerEvent ( '[data-test-twitter-input]' , 'blur' ) ;
2016-03-03 11:52:27 +03:00
2017-10-31 18:27:25 +03:00
expect ( find ( '[data-test-twitter-input]' ) . val ( ) ) . to . be . equal ( 'https://twitter.com/user' ) ;
expect ( find ( '[data-test-twitter-input]' ) . closest ( '.form-group' ) . hasClass ( 'error' ) , 'twitter input should be in error state' ) . to . be . false ;
2016-03-03 11:52:27 +03:00
2017-10-31 18:27:25 +03:00
await fillIn ( '[data-test-twitter-input]' , '' ) ;
await fillIn ( '[data-test-twitter-input]' , 'twitter.com/user' ) ;
await triggerEvent ( '[data-test-twitter-input]' , 'blur' ) ;
2016-03-03 11:52:27 +03:00
2017-10-31 18:27:25 +03:00
expect ( find ( '[data-test-twitter-input]' ) . val ( ) ) . to . be . equal ( 'https://twitter.com/user' ) ;
expect ( find ( '[data-test-twitter-input]' ) . closest ( '.form-group' ) . hasClass ( 'error' ) , 'twitter input should be in error state' ) . to . be . false ;
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' ) ) ;
await triggerEvent ( '[data-test-bio-input]' , 'blur' ) ;
2015-12-07 00:24:06 +03:00
2017-10-31 18:27:25 +03:00
expect ( find ( '[data-test-bio-input]' ) . closest ( '.form-group' ) . hasClass ( 'error' ) , 'bio input should be in error state' ) . to . be . true ;
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 (
2017-10-31 18:27:25 +03:00
find ( '[data-test-new-pass-input]' ) . closest ( '.form-group' ) . hasClass ( 'error' ) ,
2017-04-24 15:29:48 +03:00
'new password has error class when blank'
) . to . be . true ;
expect (
2017-10-31 18:27:25 +03:00
find ( '[data-test-new-pass-input]' ) . siblings ( '.response' ) . text ( ) ,
2017-04-24 15:29:48 +03:00
'new password error when blank'
) . to . match ( /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
2017-10-31 18:27:25 +03:00
await keyEvent ( '[data-test-new-pass-input]' , 'keyup' , 13 ) ;
2017-10-18 19:46:25 +03:00
expect (
2017-10-31 18:27:25 +03:00
find ( '[data-test-new-pass-input]' ) . closest ( '.form-group' ) . hasClass ( 'error' ) ,
2017-10-18 19:46:25 +03:00
'new password has error class when password too short'
) . to . be . true ;
expect (
2017-10-31 18:27:25 +03:00
find ( '[data-test-new-pass-input]' ) . siblings ( '.response' ) . text ( ) ,
2017-10-26 13:02:17 +03:00
'confirm password error when it\'s too short'
2017-10-18 19:46:25 +03:00
) . to . match ( /at least 10 characters long/ ) ;
2017-10-26 13:02:17 +03:00
// validates unsafe password
await fillIn ( '#user-password-new' , 'ghostisawesome' ) ;
await fillIn ( '#user-new-password-verification' , 'ghostisawesome' ) ;
// enter key triggers action
await keyEvent ( '#user-password-new' , 'keyup' , 13 ) ;
expect (
find ( '#user-password-new' ) . closest ( '.form-group' ) . hasClass ( 'error' ) ,
'new password has error class when password is insecure'
) . to . be . true ;
expect (
find ( '#user-password-new' ) . siblings ( '.response' ) . text ( ) ,
'confirm password error when it\'s insecure'
) . 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 (
2017-10-31 18:27:25 +03:00
find ( '[data-test-new-pass-input]' ) . closest ( '.form-group' ) . hasClass ( 'error' ) ,
2017-04-24 15:29:48 +03:00
'password validation is visible after typing'
) . to . be . false ;
2016-06-14 14:46:24 +03:00
// enter key triggers action
2017-10-31 18:27:25 +03:00
await keyEvent ( '[data-test-new-pass-input]' , 'keyup' , 13 ) ;
2017-04-24 15:29:48 +03:00
expect (
2017-10-31 18:27:25 +03:00
find ( '[data-test-ne2-pass-input]' ) . closest ( '.form-group' ) . hasClass ( 'error' ) ,
2017-04-24 15:29:48 +03:00
'confirm password has error class when it doesn\'t match'
) . to . be . true ;
expect (
2017-10-31 18:27:25 +03:00
find ( '[data-test-ne2-pass-input]' ) . siblings ( '.response' ) . text ( ) ,
2017-04-24 15:29:48 +03:00
'confirm password error when it doesn\'t match'
) . to . match ( /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
2017-05-18 13:48:37 +03:00
let [ newRequest ] = server . pretender . handledRequests . slice ( - 1 ) ;
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 (
2017-10-31 18:27:25 +03:00
find ( '[data-test-new-pass-input]' ) . val ( ) ,
2017-04-24 15:29:48 +03:00
'password field after submit'
) . to . be . blank ;
expect (
2017-10-31 18:27:25 +03:00
find ( '[data-test-ne2-pass-input]' ) . val ( ) ,
2017-04-24 15:29:48 +03:00
'password verification field after submit'
) . to . be . blank ;
// displays a notification
expect (
find ( '.gh-notifications .gh-notification' ) . length ,
'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 ( ) {
await visit ( '/team/test-1' ) ;
expect ( currentURL ( ) , 'currentURL' ) . to . equal ( '/team/test-1' ) ;
await fillIn ( '[data-test-slug-input]' , 'another slug' ) ;
await triggerEvent ( '[data-test-slug-input]' , 'blur' ) ;
expect ( find ( '[data-test-slug-input]' ) . val ( ) ) . to . be . equal ( 'another-slug' ) ;
await fillIn ( '[data-test-facebook-input]' , 'testuser' ) ;
await triggerEvent ( '[data-test-facebook-input]' , 'blur' ) ;
expect ( find ( '[data-test-facebook-input]' ) . val ( ) ) . to . be . equal ( 'https://www.facebook.com/testuser' ) ;
await visit ( '/settings/team' ) ;
expect ( find ( '.fullscreen-modal' ) . length , 'modal exists' ) . to . equal ( 1 ) ;
// Leave without saving
await ( click ( '.fullscreen-modal [data-test-leave-button]' ) , 'leave without saving' ) ;
expect ( currentURL ( ) , 'currentURL' ) . to . equal ( '/settings/team' ) ;
await visit ( '/team/test-1' ) ;
expect ( currentURL ( ) , 'currentURL' ) . to . equal ( '/team/test-1' ) ;
// settings were not saved
expect ( find ( '[data-test-slug-input]' ) . val ( ) ) . to . be . equal ( 'test-1' ) ;
expect ( find ( '[data-test-facebook-input]' ) . val ( ) ) . to . be . equal ( 'https://www.facebook.com/test' ) ;
} ) ;
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 ( ) {
await visit ( ` /team/ ${ 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 (
2017-10-31 18:27:25 +03:00
find ( '[data-test-old-pass-input]' ) . closest ( '.form-group' ) . hasClass ( 'error' ) ,
2017-04-24 15:29:48 +03:00
'old password has error class when blank'
) . to . be . true ;
expect (
2017-10-31 18:27:25 +03:00
find ( '[data-test-old-pass-input]' ) . siblings ( '.response' ) . text ( ) ,
2017-04-24 15:29:48 +03:00
'old password error when blank'
) . to . match ( /is required/ ) ;
// new password has error
expect (
2017-10-31 18:27:25 +03:00
find ( '[data-test-new-pass-input]' ) . closest ( '.form-group' ) . hasClass ( 'error' ) ,
2017-04-24 15:29:48 +03:00
'new password has error class when blank'
) . to . be . true ;
expect (
2017-10-31 18:27:25 +03:00
find ( '[data-test-new-pass-input]' ) . siblings ( '.response' ) . text ( ) ,
2017-04-24 15:29:48 +03:00
'new password error when blank'
) . to . match ( /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 (
2017-10-31 18:27:25 +03:00
find ( '[data-test-old-pass-input]' ) . closest ( '.form-group' ) . hasClass ( 'error' ) ,
2017-04-24 15:29:48 +03:00
'old password validation is in error state after typing'
) . to . be . false ;
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 ( ) {
2016-02-05 15:16:29 +03:00
server . get ( '/users/slug/unknown/' , function ( ) {
2017-01-02 21:50:36 +03:00
return new Response ( 404 , { 'Content-Type' : 'application/json' } , { errors : [ { message : 'User not found.' , errorType : 'NotFoundError' } ] } ) ;
2015-12-07 00:24:06 +03:00
} ) ;
2016-02-05 15:16:29 +03:00
errorOverride ( ) ;
2015-12-07 00:24:06 +03:00
2017-04-24 15:29:48 +03:00
await visit ( '/team/unknown' ) ;
2015-12-07 00:24:06 +03:00
2017-04-24 15:29:48 +03:00
errorReset ( ) ;
expect ( currentPath ( ) ) . to . equal ( 'error404' ) ;
expect ( currentURL ( ) ) . to . equal ( '/team/unknown' ) ;
2015-12-07 00:24:06 +03:00
} ) ;
} ) ;
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
beforeEach ( function ( ) {
adminRole = server . create ( 'role' , { name : 'Administrator' } ) ;
authorRole = server . create ( 'role' , { name : 'Author' } ) ;
2016-11-14 16:16:51 +03:00
server . create ( 'user' , { roles : [ authorRole ] } ) ;
2016-09-26 19:03:53 +03:00
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 : [ {
errorType : 'NoPermissionError' ,
message : 'You do not have permission to perform this action'
} ]
} ) ;
} ) ;
return authenticateSession ( application ) ;
} ) ;
2017-04-24 15:29:48 +03:00
it ( 'can access the team page' , async function ( ) {
2016-11-14 16:16:51 +03:00
server . create ( 'user' , { roles : [ adminRole ] } ) ;
server . create ( 'invite' , { roles : [ authorRole ] } ) ;
2016-09-26 19:03:53 +03:00
errorOverride ( ) ;
2017-04-24 15:29:48 +03:00
await visit ( '/team' ) ;
2016-09-26 19:03:53 +03:00
2017-04-24 15:29:48 +03:00
errorReset ( ) ;
expect ( currentPath ( ) ) . to . equal ( 'team.index' ) ;
expect ( find ( '.gh-alert' ) . length ) . to . equal ( 0 ) ;
2016-09-26 19:03:53 +03:00
} ) ;
} ) ;
2015-12-07 00:24:06 +03:00
} ) ;