@@ -25,8 +25,12 @@ describe("Entry", () => {
2525 } ;
2626
2727 jest . spyOn ( emitter , "on" ) ;
28+
29+ const changedData = JSON . parse ( JSON . stringify ( testData ) ) ;
30+ changedData . entry . title = "changed title" ;
31+
2832 // @ts -ignore
29- entry = new Entry ( { data : testData } , connection , emitter ) ;
33+ entry = new Entry ( { data : testData , changedData } , connection , emitter ) ;
3034 } ) ;
3135
3236 it ( "init" , ( done ) => {
@@ -50,69 +54,99 @@ describe("Entry", () => {
5054 expect ( testData . entry ) . toEqual ( entry . getData ( ) ) ;
5155 } ) ;
5256
53- it ( "getField undefined" , function ( ) {
54- const uid = "group1.group" ;
55- const schema = entry . content_type . schema [ 5 ] . schema [ 0 ] ;
56- const field = entry . getField ( uid ) ;
57-
58- expect ( field . uid ) . toEqual ( uid ) ;
59- expect ( field . data_type ) . toEqual ( schema . data_type ) ;
60- expect ( field . schema ) . toEqual ( schema ) ;
61- } ) ;
62-
63- it ( "getField modular blocks, get complete block" , function ( ) {
64- const uid = "modular_blocks.0" ;
65- const schema = entry . content_type . schema [ 6 ] . blocks [ 2 ] ;
66- const field = entry . getField ( uid ) ;
67- expect ( field . uid ) . toEqual ( uid ) ;
68- expect ( field . data_type ) . toEqual ( schema . data_type ) ;
69- expect ( field . schema ) . toEqual ( schema ) ;
70- } ) ;
71-
72- it ( "getField modular blocks, get single block" , function ( ) {
73- const uid = "modular_blocks.0.banner" ;
74- const schema = entry . content_type . schema [ 6 ] . blocks [ 2 ] . schema ;
75- const field = entry . getField ( uid ) ;
76- expect ( field . uid ) . toEqual ( uid ) ;
77- expect ( field . data_type ) . toEqual ( schema . data_type ) ;
78- expect ( field . schema ) . toEqual ( schema ) ;
79- } ) ;
80-
81- it ( "getField modular blocks, get block field" , function ( ) {
82- const uid = "modular_blocks.0.banner.banner_image" ;
83- const schema = entry . content_type . schema [ 6 ] . blocks [ 2 ] . schema [ 0 ] ;
84- const field = entry . getField ( uid ) ;
85- expect ( field . uid ) . toEqual ( uid ) ;
86- expect ( field . data_type ) . toEqual ( schema . data_type ) ;
87- expect ( field . schema ) . toEqual ( schema ) ;
88- } ) ;
89-
90- it ( "getField global field" , function ( ) {
91- const uid = "global_field.single_line" ;
92- const schema = entry . content_type . schema [ 7 ] . schema [ 0 ] ;
93- const field = entry . getField ( uid ) ;
94- expect ( field . uid ) . toEqual ( uid ) ;
95- expect ( field . data_type ) . toEqual ( schema . data_type ) ;
96- expect ( field . schema ) . toEqual ( schema ) ;
97- } ) ;
57+ describe ( "getField" , ( ) => {
58+ it ( "getField undefined" , function ( ) {
59+ const uid = "group1.group" ;
60+ const schema = entry . content_type . schema [ 5 ] . schema [ 0 ] ;
61+ const field = entry . getField ( uid ) ;
62+
63+ expect ( field . uid ) . toEqual ( uid ) ;
64+ expect ( field . data_type ) . toEqual ( schema . data_type ) ;
65+ expect ( field . schema ) . toEqual ( schema ) ;
66+ } ) ;
67+
68+ it ( "getField modular blocks, get complete block" , function ( ) {
69+ const uid = "modular_blocks.0" ;
70+ const schema = entry . content_type . schema [ 6 ] . blocks [ 2 ] ;
71+ const field = entry . getField ( uid ) ;
72+ expect ( field . uid ) . toEqual ( uid ) ;
73+ expect ( field . data_type ) . toEqual ( schema . data_type ) ;
74+ expect ( field . schema ) . toEqual ( schema ) ;
75+ } ) ;
76+
77+ it ( "getField modular blocks, get single block" , function ( ) {
78+ const uid = "modular_blocks.0.banner" ;
79+ const schema = entry . content_type . schema [ 6 ] . blocks [ 2 ] . schema ;
80+ const field = entry . getField ( uid ) ;
81+ expect ( field . uid ) . toEqual ( uid ) ;
82+ expect ( field . data_type ) . toEqual ( schema . data_type ) ;
83+ expect ( field . schema ) . toEqual ( schema ) ;
84+ } ) ;
85+
86+ it ( "getField modular blocks, get block field" , function ( ) {
87+ const uid = "modular_blocks.0.banner.banner_image" ;
88+ const schema = entry . content_type . schema [ 6 ] . blocks [ 2 ] . schema [ 0 ] ;
89+ const field = entry . getField ( uid ) ;
90+ expect ( field . uid ) . toEqual ( uid ) ;
91+ expect ( field . data_type ) . toEqual ( schema . data_type ) ;
92+ expect ( field . schema ) . toEqual ( schema ) ;
93+ } ) ;
94+
95+ it ( "getField global field" , function ( ) {
96+ const uid = "global_field.single_line" ;
97+ const schema = entry . content_type . schema [ 7 ] . schema [ 0 ] ;
98+ const field = entry . getField ( uid ) ;
99+ expect ( field . uid ) . toEqual ( uid ) ;
100+ expect ( field . data_type ) . toEqual ( schema . data_type ) ;
101+ expect ( field . schema ) . toEqual ( schema ) ;
102+ } ) ;
103+
104+ it ( "getField multiple group" , function ( ) {
105+ const uid = "group.group.group.0.single_line" ;
106+ const schema =
107+ entry . content_type . schema [ 4 ] . schema [ 0 ] . schema [ 0 ] . schema [ 0 ] ;
108+ const field = entry . getField ( uid ) ;
109+ expect ( field . uid ) . toEqual ( uid ) ;
110+ expect ( field . data_type ) . toEqual ( schema . data_type ) ;
111+ expect ( field . schema ) . toEqual ( schema ) ;
112+ } ) ;
113+
114+ it ( "getField group" , function ( ) {
115+ const uid = "group.group.group" ;
116+ const schema = entry . content_type . schema [ 4 ] . schema [ 0 ] . schema [ 0 ] ;
117+ const field = entry . getField ( uid ) ;
118+ expect ( field . uid ) . toEqual ( uid ) ;
119+ expect ( field . data_type ) . toEqual ( schema . data_type ) ;
120+ expect ( field . schema ) . toEqual ( schema ) ;
121+ } ) ;
122+
123+ it ( "should use unsaved schema if user set options.useUnsavedSchema = true" , ( ) => {
124+ const uid = "title" ;
125+ const field = entry . getField ( uid , { useUnsavedSchema : true } ) ;
126+ const schema = entry . content_type . schema [ 0 ] ;
127+ expect ( field . uid ) . toBe ( uid ) ;
128+ expect ( field . schema ) . toEqual ( schema ) ;
129+ expect ( field . data_type ) . toEqual ( schema . data_type ) ;
130+
131+ } ) ;
132+ it ( "should use custom Field instance if internal flag is set" , ( ) => {
133+ const fieldInstance = jest . fn ( ) ;
134+ entry = new Entry (
135+ // @ts -ignore
136+ { data : testData } ,
137+ connection ,
138+ emitter ,
139+ {
140+ _internalFlags : {
141+ FieldInstance : fieldInstance ,
142+ } ,
143+ }
144+ ) ;
98145
99- it ( "getField multiple group" , function ( ) {
100- const uid = "group.group.group.0.single_line" ;
101- const schema =
102- entry . content_type . schema [ 4 ] . schema [ 0 ] . schema [ 0 ] . schema [ 0 ] ;
103- const field = entry . getField ( uid ) ;
104- expect ( field . uid ) . toEqual ( uid ) ;
105- expect ( field . data_type ) . toEqual ( schema . data_type ) ;
106- expect ( field . schema ) . toEqual ( schema ) ;
107- } ) ;
146+ entry . getField ( "title" ) ;
108147
109- it ( "getField group" , function ( ) {
110- const uid = "group.group.group" ;
111- const schema = entry . content_type . schema [ 4 ] . schema [ 0 ] . schema [ 0 ] ;
112- const field = entry . getField ( uid ) ;
113- expect ( field . uid ) . toEqual ( uid ) ;
114- expect ( field . data_type ) . toEqual ( schema . data_type ) ;
115- expect ( field . schema ) . toEqual ( schema ) ;
148+ expect ( fieldInstance ) . toHaveBeenCalled ( ) ;
149+ } ) ;
116150 } ) ;
117151
118152 it ( "set field data restriction" , async ( ) => {
0 commit comments