2021-06-02 17:25:04 +02:00
package form
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewMarker ( t * testing . T ) {
t . Run ( "success" , func ( t * testing . T ) {
var m = struct {
2021-09-17 14:26:12 +02:00
SubjSrc string
2021-08-24 14:27:34 +02:00
MarkerName string
2021-09-17 14:26:12 +02:00
MarkerReview bool
2021-08-16 01:52:02 +02:00
MarkerInvalid bool
2021-06-02 17:25:04 +02:00
} {
2021-09-17 14:26:12 +02:00
SubjSrc : "manual" ,
2021-08-16 01:52:02 +02:00
MarkerName : "Foo" ,
2021-09-17 14:26:12 +02:00
MarkerReview : true ,
2021-08-16 01:52:02 +02:00
MarkerInvalid : true ,
2021-06-02 17:25:04 +02:00
}
f , err := NewMarker ( m )
if err != nil {
t . Fatal ( err )
}
2021-09-17 14:26:12 +02:00
assert . Equal ( t , "manual" , f . SubjSrc )
2021-08-16 00:29:36 +02:00
assert . Equal ( t , "Foo" , f . MarkerName )
2021-09-17 14:26:12 +02:00
assert . Equal ( t , true , f . MarkerReview )
2021-08-16 01:52:02 +02:00
assert . Equal ( t , true , f . MarkerInvalid )
2021-06-02 17:25:04 +02:00
} )
}
2023-07-27 19:13:00 +02:00
func TestMarker_Validate ( t * testing . T ) {
t . Run ( "Empty" , func ( t * testing . T ) {
frm := Marker { }
assert . Error ( t , frm . Validate ( ) )
} )
t . Run ( "False" , func ( t * testing . T ) {
frm := Marker {
FileUID : "frygcme3hc9re8nc" ,
MarkerType : "face" ,
X : 0.303519 ,
Y : 0.260742 ,
W : 0.548387 ,
H : 0.365234 ,
SubjSrc : "manual" ,
MarkerName : "Jens Mander" ,
MarkerReview : false ,
MarkerInvalid : false ,
}
assert . Nil ( t , frm . Validate ( ) )
} )
t . Run ( "FileUID" , func ( t * testing . T ) {
frm := Marker {
FileUID : "rygcme3hc9re8nc" ,
MarkerType : "face" ,
X : 0.303519 ,
Y : 0.260742 ,
W : 0.548387 ,
H : 0.365234 ,
SubjSrc : "manual" ,
MarkerName : "Jens Mander" ,
MarkerReview : false ,
MarkerInvalid : false ,
}
assert . Error ( t , frm . Validate ( ) )
} )
t . Run ( "Area" , func ( t * testing . T ) {
frm := Marker {
FileUID : "frygcme3hc9re8nc" ,
MarkerType : "face" ,
X : 0.303519 ,
Y : 1.260742 ,
W : 0.548387 ,
H : 0.365234 ,
SubjSrc : "manual" ,
MarkerName : "Jens Mander" ,
MarkerReview : false ,
MarkerInvalid : false ,
}
assert . Error ( t , frm . Validate ( ) )
} )
t . Run ( "Name" , func ( t * testing . T ) {
frm := Marker {
FileUID : "frygcme3hc9re8nc" ,
MarkerType : "face" ,
X : 0.303519 ,
Y : 0.260742 ,
W : 0.548387 ,
H : 0.365234 ,
SubjSrc : "manual" ,
MarkerName : "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer..." ,
MarkerReview : false ,
MarkerInvalid : false ,
}
assert . Error ( t , frm . Validate ( ) )
} )
}