2018-01-16 11:34:37 +01:00
flectra . define ( 'web.special_fields_tests' , function ( require ) {
2018-01-16 06:58:15 +01:00
"use strict" ;
var FormView = require ( 'web.FormView' ) ;
var ListView = require ( 'web.ListView' ) ;
var testUtils = require ( 'web.test_utils' ) ;
var createView = testUtils . createView ;
QUnit . module ( 'fields' , { } , function ( ) {
QUnit . module ( 'special_fields' , {
beforeEach : function ( ) {
this . data = {
partner : {
fields : {
display _name : { string : "Displayed name" , type : "char" } ,
foo : { string : "Foo" , type : "char" , default : "My little Foo Value" } ,
bar : { string : "Bar" , type : "boolean" , default : true } ,
int _field : { string : "int_field" , type : "integer" , sortable : true } ,
qux : { string : "Qux" , type : "float" , digits : [ 16 , 1 ] } ,
p : { string : "one2many field" , type : "one2many" , relation : 'partner' , relation _field : 'trululu' } ,
turtles : { string : "one2many turtle field" , type : "one2many" , relation : 'turtle' } ,
trululu : { string : "Trululu" , type : "many2one" , relation : 'partner' } ,
timmy : { string : "pokemon" , type : "many2many" , relation : 'partner_type' } ,
product _id : { string : "Product" , type : "many2one" , relation : 'product' } ,
color : {
type : "selection" ,
selection : [ [ 'red' , "Red" ] , [ 'black' , "Black" ] ] ,
default : 'red' ,
} ,
date : { string : "Some Date" , type : "date" } ,
datetime : { string : "Datetime Field" , type : 'datetime' } ,
user _id : { string : "User" , type : 'many2one' , relation : 'user' } ,
} ,
records : [ {
id : 1 ,
display _name : "first record" ,
bar : true ,
foo : "yop" ,
int _field : 10 ,
qux : 0.44 ,
p : [ ] ,
turtles : [ 2 ] ,
timmy : [ ] ,
trululu : 4 ,
user _id : 17 ,
} , {
id : 2 ,
display _name : "second record" ,
bar : true ,
foo : "blip" ,
int _field : 9 ,
qux : 13 ,
p : [ ] ,
timmy : [ ] ,
trululu : 1 ,
product _id : 37 ,
date : "2017-01-25" ,
datetime : "2016-12-12 10:55:05" ,
user _id : 17 ,
} , {
id : 4 ,
display _name : "aaa" ,
bar : false ,
} ] ,
onchanges : { } ,
} ,
product : {
fields : {
name : { string : "Product Name" , type : "char" }
} ,
records : [ {
id : 37 ,
display _name : "xphone" ,
} , {
id : 41 ,
display _name : "xpad" ,
} ]
} ,
partner _type : {
fields : {
name : { string : "Partner Type" , type : "char" } ,
color : { string : "Color index" , type : "integer" } ,
} ,
records : [
{ id : 12 , display _name : "gold" , color : 2 } ,
{ id : 14 , display _name : "silver" , color : 5 } ,
]
} ,
turtle : {
fields : {
display _name : { string : "Displayed name" , type : "char" } ,
turtle _foo : { string : "Foo" , type : "char" , default : "My little Foo Value" } ,
turtle _bar : { string : "Bar" , type : "boolean" , default : true } ,
turtle _int : { string : "int" , type : "integer" , sortable : true } ,
turtle _qux : { string : "Qux" , type : "float" , digits : [ 16 , 1 ] , required : true , default : 1.5 } ,
turtle _description : { string : "Description" , type : "text" } ,
turtle _trululu : { string : "Trululu" , type : "many2one" , relation : 'partner' } ,
product _id : { string : "Product" , type : "many2one" , relation : 'product' , required : true } ,
partner _ids : { string : "Partner" , type : "many2many" , relation : 'partner' } ,
} ,
records : [ {
id : 1 ,
display _name : "leonardo" ,
turtle _bar : true ,
turtle _foo : "yop" ,
partner _ids : [ ] ,
} , {
id : 2 ,
display _name : "donatello" ,
turtle _bar : true ,
turtle _foo : "blip" ,
turtle _int : 9 ,
partner _ids : [ 2 , 4 ] ,
} , {
id : 3 ,
display _name : "raphael" ,
turtle _bar : false ,
turtle _foo : "kawa" ,
turtle _int : 21 ,
turtle _qux : 9.8 ,
partner _ids : [ ] ,
} ] ,
} ,
user : {
fields : {
name : { string : "Name" , type : "char" }
} ,
records : [ {
id : 17 ,
name : "Aline" ,
} , {
id : 19 ,
name : "Christine" ,
} ]
} ,
} ;
}
} , function ( ) {
QUnit . module ( 'FieldTimezoneMismatch' ) ;
QUnit . test ( 'widget timezone_mismatch in a list view' , function ( assert ) {
assert . expect ( 5 ) ;
this . data . partner . fields . tz _offset = {
string : "tz_offset" ,
type : "char"
} ;
this . data . partner . records . forEach ( function ( r ) {
r . color = 'red' ;
r . tz _offset = 0 ;
} ) ;
this . data . partner . onchanges = {
color : function ( r ) {
r . tz _offset = '+4800' ; // make sur we have a mismatch
}
} ;
var list = createView ( {
View : ListView ,
model : 'partner' ,
data : this . data ,
arch : '<tree string="Colors" editable="top">' +
'<field name="tz_offset" invisible="True"/>' +
'<field name="color" widget="timezone_mismatch"/>' +
'</tree>' ,
} ) ;
assert . strictEqual ( list . $ ( 'td:contains(Red)' ) . length , 3 ,
"should have 3 rows with correct value" ) ;
list . $ ( 'td:contains(Red):first' ) . click ( ) ;
var $td = list . $ ( 'tbody tr.o_selected_row td:not(.o_list_record_selector)' ) ;
assert . strictEqual ( $td . find ( 'select' ) . length , 1 , "td should have a child 'select'" ) ;
assert . strictEqual ( $td . contents ( ) . length , 1 , "select tag should be only child of td" ) ;
$td . find ( 'select' ) . val ( '"black"' ) . trigger ( 'change' ) ;
assert . strictEqual ( $td . find ( '.o_tz_warning' ) . length , 1 , "Should display icon alert" ) ;
assert . ok ( $td . find ( 'select option:selected' ) . text ( ) . match ( /Black\s+\([0-9]+\/[0-9]+\/[0-9]+ [0-9]+:[0-9]+:[0-9]+\)/ ) , "Should display the datetime in the selected timezone" ) ;
list . destroy ( ) ;
} ) ;
QUnit . test ( 'widget timezone_mismatch in a form view' , function ( assert ) {
assert . expect ( 1 ) ;
this . data . partner . fields . tz _offset = {
string : "tz_offset" ,
type : "char"
} ;
this . data . partner . fields . tz = {
type : "selection" ,
selection : [ [ 'Europe/Brussels' , "Europe/Brussels" ] , [ 'America/Los_Angeles' , "America/Los_Angeles" ] ] ,
} ;
this . data . partner . records [ 0 ] . tz = false ;
this . data . partner . records [ 0 ] . tz _offset = '+4800' ;
var form = createView ( {
View : FormView ,
model : 'partner' ,
res _id : 1 ,
data : this . data ,
arch : '<form>' +
'<field name="tz_offset" invisible="True"/>' +
'<field name="tz" widget="timezone_mismatch"/>' +
'</form>' ,
} ) ;
form . $buttons . find ( '.o_form_button_edit' ) . click ( ) ;
assert . strictEqual ( form . $ ( 'select' ) . length , 1 , "should have the select field" ) ;
form . destroy ( ) ;
} ) ;
} ) ;
} ) ;
} ) ;