@@ -6,13 +6,16 @@ describe('media metadata editor', () => {
66 beforeEach ( window . module ( 'superdesk.apps.vocabularies' ) ) ;
77 beforeEach ( window . module ( 'superdesk.apps.authoring.media' ) ) ;
88 beforeEach ( window . module ( 'superdesk.apps.authoring.metadata' ) ) ;
9+ beforeEach ( window . module ( 'superdesk.apps.workspace.content' ) ) ;
910
10- beforeEach ( inject ( ( $q , metadata , vocabularies , api ) => {
11+ beforeEach ( inject ( ( $q , metadata , vocabularies ) => {
1112 spyOn ( metadata , 'initialize' ) . and . returnValue ( $q . when ( { } ) ) ;
1213 spyOn ( vocabularies , 'getAllActiveVocabularies' ) . and . returnValue ( $q . when ( [ ] ) ) ;
1314 } ) ) ;
1415
15- it ( 'displays all fields' , inject ( ( $controller , $rootScope ) => {
16+ it ( 'displays all fields' , inject ( ( $controller , $rootScope , $q , content ) => {
17+ spyOn ( content , 'getType' ) . and . returnValue ( $q . when ( null ) ) ;
18+
1619 const testConfig : Partial < ISuperdeskGlobalConfig > = {
1720 editor : {
1821 picture : {
@@ -56,7 +59,103 @@ describe('media metadata editor', () => {
5659 expect ( ctrl . fields . map ( ( f ) => f . field ) ) . toEqual ( [ 'slugline' , 'headline' , 'category' , 'genre' ] ) ;
5760 } ) ) ;
5861
59- it ( 'displays fields with dislayOnMediaEditor set' , inject ( ( $rootScope , $controller ) => {
62+ it ( 'uses appConfig when picture profile exists' , inject ( ( $controller , $rootScope , $q , content ) => {
63+ const pictureProfile = {
64+ editor : {
65+ byline : {
66+ order : 1 ,
67+ required : true ,
68+ displayOnMediaEditor : true ,
69+ } ,
70+ alt_text : {
71+ order : 2 ,
72+ required : false ,
73+ displayOnMediaEditor : true ,
74+ } ,
75+ } ,
76+ schema : {
77+ byline : { type : 'string' } ,
78+ alt_text : { type : 'string' } ,
79+ } ,
80+ } ;
81+
82+ spyOn ( content , 'getType' ) . and . returnValue ( $q . when ( pictureProfile ) ) ;
83+
84+ const testConfig : Partial < ISuperdeskGlobalConfig > = {
85+ editor : {
86+ picture : {
87+ slugline : {
88+ order : 1 ,
89+ required : true ,
90+ } ,
91+ headline : {
92+ order : 2 ,
93+ required : true ,
94+ } ,
95+ } ,
96+ } ,
97+ schema : {
98+ picture : {
99+ slugline : { type : 'string' } ,
100+ headline : { type : 'string' } ,
101+ } ,
102+ } ,
103+ validator_media_metadata : { } ,
104+ } ;
105+
106+ Object . assign ( appConfig , testConfig ) ;
107+
108+ const ctrl = $controller ( 'MediaFieldsController' ) ;
109+
110+ $rootScope . $apply ( ) ;
111+
112+ expect ( content . getType ) . toHaveBeenCalledWith ( 'picture' ) ;
113+ expect ( ctrl . fields . length ) . toBe ( 2 ) ;
114+ expect ( ctrl . fields . map ( ( f ) => f . field ) ) . toEqual ( [ 'slugline' , 'headline' ] ) ;
115+ } ) ) ;
116+
117+ it ( 'falls back to picture profile when appConfig is missing' , inject ( ( $controller , $rootScope , $q , content ) => {
118+ const pictureProfile = {
119+ editor : {
120+ byline : {
121+ order : 1 ,
122+ required : true ,
123+ displayOnMediaEditor : true ,
124+ } ,
125+ alt_text : {
126+ order : 2 ,
127+ required : false ,
128+ displayOnMediaEditor : true ,
129+ } ,
130+ } ,
131+ schema : {
132+ byline : { type : 'string' } ,
133+ alt_text : { type : 'string' } ,
134+ } ,
135+ } ;
136+
137+ spyOn ( content , 'getType' ) . and . returnValue ( $q . when ( pictureProfile ) ) ;
138+
139+ const testConfig : Partial < ISuperdeskGlobalConfig > = {
140+ editor : { } ,
141+ schema : { } ,
142+ validator_media_metadata : { } ,
143+ } ;
144+
145+ Object . assign ( appConfig , testConfig ) ;
146+
147+ const ctrl = $controller ( 'MediaFieldsController' ) ;
148+
149+ $rootScope . $apply ( ) ;
150+
151+ expect ( content . getType ) . toHaveBeenCalledWith ( 'picture' ) ;
152+ expect ( ctrl . fields . length ) . toBe ( 2 ) ;
153+ expect ( ctrl . fields . map ( ( f ) => f . field ) ) . toEqual ( [ 'byline' , 'alt_text' ] ) ;
154+ } ) ) ;
155+
156+ it ( 'displays fields with displayOnMediaEditor set' , inject ( ( $rootScope , $controller , $q , content ) => {
157+ spyOn ( content , 'getType' ) . and . returnValue ( $q . when ( null ) ) ;
158+
60159 const testConfig : Partial < ISuperdeskGlobalConfig > = {
61160 schema : {
62161 picture : {
0 commit comments