Added new browser tests.

This commit is contained in:
Martin Edenhofer 2013-04-22 01:03:19 +02:00
parent ef739b138f
commit c039e0028e
5 changed files with 223 additions and 25 deletions

View file

@ -1,6 +1,4 @@
$ = jQuery.sub()
class Index extends App.Controller
class Index extends App.ControllerContent
className: 'container getstarted'
events:
@ -120,7 +118,7 @@ class Index extends App.Controller
App.Event.trigger 'notify', {
type: 'success'
msg: App.i18n.translateContent( 'Invitation sent!' )
timeout: 2500
timeout: 3500
}
# rerender page

View file

@ -116,13 +116,15 @@ curl http://localhost/api/users.json -v -u #{login}:#{password} -H "Content-Type
def create
user = User.new( User.param_cleanup(params) )
user.updated_by_id = (current_user && current_user.id) || 1
user.created_by_id = (current_user && current_user.id) || 1
begin
# check if it's first user
count = User.all.count()
# if it's a signup, add user to customer role
if user.created_by_id == 1
if !current_user
user.updated_by_id = 1
user.created_by_id = 1
# check if feature is enabled
if !Setting.get('user_create_account')
@ -130,12 +132,9 @@ curl http://localhost/api/users.json -v -u #{login}:#{password} -H "Content-Type
return
end
# check if it's first user
count = User.all.count()
# add first user as admin/agent and to all groups
group_ids = []
role_ids = []
# add first user as admin/agent and to all groups
if count <= 2
Role.where( :name => [ 'Admin', 'Agent'] ).each { |role|
role_ids.push role.id
@ -263,20 +262,34 @@ curl http://localhost/api/users/2.json -v -u #{login}:#{password} -H "Content-Ty
=end
def update
return if is_not_role('Admin')
user = User.find(params[:id])
# allow user to update him self
if is_role('Customer') && !is_role('Admin') && !is_role('Agent')
return if params[:id] != current_user.id
end
user = User.find( params[:id] )
begin
user.update_attributes( User.param_cleanup(params) )
if params[:role_ids]
# only allow Admin's and Agent's
if is_role('Admin') && is_role('Agent') && params[:role_ids]
user.role_ids = params[:role_ids]
end
if params[:group_ids]
# only allow Admin's
if is_role('Admin') && params[:group_ids]
user.group_ids = params[:group_ids]
end
if params[:organization_ids]
# only allow Admin's and Agent's
if is_role('Admin') && is_role('Agent') && params[:organization_ids]
user.organization_ids = params[:organization_ids]
end
# get new data
user_new = User.user_data_full( params[:id] )
render :json => user_new, :status => :ok
rescue Exception => e
@ -286,6 +299,7 @@ curl http://localhost/api/users/2.json -v -u #{login}:#{password} -H "Content-Ty
# DELETE /api/users/1
def destroy
return if !is_role('Admin')
model_destory_render(User, params)
end

View file

@ -7,7 +7,7 @@ class AaaGettingStartedTest < TestCase
{
:name => 'start',
:instance => browser_instance,
:url => browser_url + '/#getting_started',
:url => browser_url + '/',
:action => [
{
:execute => 'wait',
@ -21,32 +21,31 @@ class AaaGettingStartedTest < TestCase
],
},
{
:name => 'getting started',
:name => 'getting started - master agent',
:action => [
{
:execute => 'set',
:css => 'input[name="firstname"]',
:css => '#form-master input[name="firstname"]',
:value => 'Test Master',
},
{
:execute => 'set',
:css => 'input[name="lastname"]',
:css => '#form-master input[name="lastname"]',
:value => 'Agent',
},
{
:execute => 'set',
:css => 'input[name="email"]',
:css => '#form-master input[name="email"]',
:value => 'master@example.com',
},
{
:execute => 'set',
:element => :text_field,
:css => 'input[name="password"]',
:css => '#form-master input[name="password"]',
:value => 'test1234äöüß',
},
{
:execute => 'set',
:css => 'input[name="password_confirm"]',
:css => '#form-master input[name="password_confirm"]',
:value => 'test1234äöüß',
},
{
@ -67,14 +66,76 @@ class AaaGettingStartedTest < TestCase
:element => :url,
:result => '#getting_started',
},
],
},
# create agent1
{
:name => 'getting started - agent 1',
:action => [
# check action
{
:execute => 'match',
:css => 'body',
:value => 'Invite Agents',
:match_result => true,
},
{
:execute => 'wait',
:value => 4,
},
{
:execute => 'set',
:css => '#form-agent input[name="firstname"]',
:value => 'Agent 1',
},
{
:execute => 'set',
:css => '#form-agent input[name="lastname"]',
:value => 'Test',
},
{
:execute => 'set',
:css => '#form-agent input[name="email"]',
:value => 'agent1@example.com',
},
{
:execute => 'click',
:css => '#form-agent input[name="group_ids"][value="1"]',
},
{
:execute => 'click',
:css => '#form-agent button[type="submit"]',
},
{
:execute => 'wait',
:value => 2,
},
{
:execute => 'check',
:css => '#login',
:result => false,
},
{
:execute => 'check',
:element => :url,
:result => '#getting_started',
},
# check action
{
:execute => 'match',
:css => 'body',
:value => 'Invitation sent',
:match_result => true,
},
{
:execute => 'match',
:css => 'body',
:value => 'Invite Agents',
:match_result => true,
},
],
},
]

View file

@ -0,0 +1,123 @@
# encoding: utf-8
require 'browser_test_helper'
class AgentTicketCreateTest < TestCase
def test_customer_ticket_create
tests = [
{
:name => 'agent ticket create',
:action => [
{
:execute => 'click',
:css => 'a[href="#new"]',
},
{
:execute => 'click',
:css => 'a[href="#ticket_create/call_inbound"]',
},
{
:execute => 'wait',
:value => 5,
},
{
:execute => 'check',
:css => '.ticket_create',
:result => true,
},
{
:execute => 'wait',
:value => 1,
},
{
:execute => 'set',
:css => '.ticket_create input[name="customer_id_autocompletion"]',
:value => 'ma',
},
{
:execute => 'wait',
:value => 4,
},
{
:execute => 'sendkey',
:css => '.ticket_create input[name="customer_id_autocompletion"]',
:value => :arrow_down,
},
{
:execute => 'sendkey',
:css => '.ticket_create input[name="customer_id_autocompletion"]',
:value => :tab,
},
{
:execute => 'select',
:css => '.ticket_create select[name="group_id"]',
:value => 'Users',
},
{
:execute => 'set',
:css => '.ticket_create input[name="subject"]',
:value => 'some subject 123äöü',
},
{
:execute => 'set',
:css => '.ticket_create textarea[name="body"]',
:value => 'some body 123äöü',
},
{
:execute => 'click',
:css => '.form-actions button[type="submit"]',
},
{
:execute => 'wait',
:value => 5,
},
{
:execute => 'check',
:css => '#login',
:result => false,
},
{
:execute => 'check',
:element => :url,
:result => '#ticket/zoom/',
},
# check ticket
{
:execute => 'match',
:css => 'div.article',
:value => 'some body 123äöü',
:match_result => true,
},
# update ticket
{
:execute => 'check',
:css => 'textarea[name="body"]',
:result => true,
},
{
:execute => 'set',
:css => 'textarea[name="body"]',
:value => 'some body 1234 äöüß',
},
{
:execute => 'click',
:css => 'button',
:type => 'submit',
},
{
:execute => 'wait',
:value => 4,
},
{
:execute => 'match',
:css => 'body',
:value => 'some body 1234 äöüß',
:match_result => true,
},
],
},
]
browser_signle_test_with_login(tests, { :username => 'agent1@example.com' })
end
end

View file

@ -184,6 +184,8 @@ class TestCase < Test::Unit::TestCase
if action[:execute] == 'set'
element.clear
element.send_keys( action[:value] )
elsif action[:execute] == 'sendkey'
element.send_keys( action[:value] )
elsif action[:execute] == 'select'
dropdown = Selenium::WebDriver::Support::Select.new(element)
dropdown.select_by(:text, action[:value])