Added model browser tests.
This commit is contained in:
parent
1a7eec2927
commit
3bc37e029d
4 changed files with 77 additions and 7 deletions
|
@ -64,17 +64,47 @@ class App.Model extends Spine.Model
|
|||
return '???'
|
||||
|
||||
@validate: ( data = {} ) ->
|
||||
return if !data['model'].configure_attributes
|
||||
attributes = _.clone( data['model'].configure_attributes )
|
||||
return if !attributes
|
||||
|
||||
# check params of screen if screen is requested
|
||||
if data['screen']
|
||||
for attribute in attributes
|
||||
if attribute.screen
|
||||
if attribute && attribute.screen && attribute.screen[ data['screen'] ] && !_.isEmpty(attribute.screen[ data['screen'] ])
|
||||
for item, value of attribute.screen[ data['screen'] ]
|
||||
attribute[item] = value
|
||||
|
||||
# check required_if attributes
|
||||
for attribute in attributes
|
||||
if attribute['required_if']
|
||||
|
||||
for key, values of attribute['required_if']
|
||||
|
||||
localValues = data['params'][key]
|
||||
if !_.isArray( localValues )
|
||||
localValues = [ localValues ]
|
||||
|
||||
match = false
|
||||
for value in values
|
||||
if localValues
|
||||
for localValue in localValues
|
||||
if value && localValue && value.toString() is localValue.toString()
|
||||
match = true
|
||||
if match is true
|
||||
attribute['null'] = false
|
||||
else
|
||||
attribute['null'] = true
|
||||
|
||||
# check attributes/each attribute of object
|
||||
errors = {}
|
||||
for attribute in data['model'].configure_attributes
|
||||
for attribute in attributes
|
||||
|
||||
# only if attribute is not read only
|
||||
if !attribute.readonly
|
||||
|
||||
# check required // if null is defined && null is false
|
||||
if 'null' of attribute && !attribute[null]
|
||||
if 'null' of attribute && !attribute['null']
|
||||
|
||||
# check :: fields
|
||||
parts = attribute.name.split '::'
|
||||
|
@ -103,16 +133,17 @@ class App.Model extends Spine.Model
|
|||
|
||||
# return error object
|
||||
if !_.isEmpty(errors)
|
||||
console.log 'error', 'validation vailed', errors
|
||||
console.log 'error', 'validation failed', errors
|
||||
return errors
|
||||
|
||||
# return no errors
|
||||
return
|
||||
|
||||
validate: ->
|
||||
validate: (params = {}) ->
|
||||
App.Model.validate(
|
||||
model: @constructor,
|
||||
params: @,
|
||||
model: @constructor
|
||||
params: @
|
||||
screen: params.screen
|
||||
)
|
||||
|
||||
isOnline: ->
|
||||
|
|
16
app/views/tests/model.html.erb
Normal file
16
app/views/tests/model.html.erb
Normal file
|
@ -0,0 +1,16 @@
|
|||
|
||||
<link rel="stylesheet" href="/assets/tests/qunit-1.10.0.css">
|
||||
<script src="/assets/tests/qunit-1.10.0.js"></script>
|
||||
<script src="/assets/tests/model.js"></script>
|
||||
|
||||
<style type="text/css">
|
||||
body {
|
||||
padding-top: 0px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script type="text/javascript">
|
||||
</script>
|
||||
|
||||
<div id="qunit"></div>
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
Zammad::Application.routes.draw do
|
||||
|
||||
match '/tests-core', :to => 'tests#core', :via => :get
|
||||
match '/tests-model', :to => 'tests#model', :via => :get
|
||||
match '/tests-form', :to => 'tests#form', :via => :get
|
||||
match '/tests-table', :to => 'tests#table', :via => :get
|
||||
match '/tests/wait/:sec', :to => 'tests#wait', :via => :get
|
||||
|
|
|
@ -24,6 +24,28 @@ class AAbUnitTest < TestCase
|
|||
]
|
||||
browser_single_test(tests)
|
||||
end
|
||||
def test_model
|
||||
tests = [
|
||||
{
|
||||
:name => 'start',
|
||||
:instance => browser_instance,
|
||||
:url => browser_url + '/tests-model',
|
||||
:action => [
|
||||
{
|
||||
:execute => 'wait',
|
||||
:value => 8,
|
||||
},
|
||||
{
|
||||
:execute => 'match',
|
||||
:css => '.result .failed',
|
||||
:value => '0',
|
||||
:match_result => true,
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
browser_single_test(tests)
|
||||
end
|
||||
def test_form
|
||||
tests = [
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue