@@ -29,7 +29,7 @@ describe("1000: DatafilesActionComponent", () => {
29
29
const actionsConfig = [
30
30
{
31
31
id : "eed8efec-4354-11ef-a3b5-d75573a5d37f" ,
32
- order : 4 ,
32
+ order : 0 ,
33
33
label : "Download All" ,
34
34
files : "all" ,
35
35
mat_icon : "download" ,
@@ -40,7 +40,7 @@ describe("1000: DatafilesActionComponent", () => {
40
40
} ,
41
41
{
42
42
id : "3072fafc-4363-11ef-b9f9-ebf568222d26" ,
43
- order : 3 ,
43
+ order : 1 ,
44
44
label : "Download Selected" ,
45
45
files : "selected" ,
46
46
mat_icon : "download" ,
@@ -61,14 +61,54 @@ describe("1000: DatafilesActionComponent", () => {
61
61
} ,
62
62
{
63
63
id : "fa3ce6ee-482d-11ef-95e9-ff2c80dd50bd" ,
64
- order : 1 ,
64
+ order : 3 ,
65
+ label : "Notebook Selected" ,
66
+ files : "selected" ,
67
+ icon : "/assets/icons/jupyter_logo.png" ,
68
+ url : "https://notebook.scicat.org" ,
69
+ target : "_blank" ,
70
+ enabled : "#Selected" ,
71
+ authorization : [ "#datasetAccess" , "#datasetPublic" ] ,
72
+ } ,
73
+ {
74
+ id : "fa3ce6ee-482d-11ef-95e9-ff2c80ddnews" ,
75
+ order : 4 ,
76
+ label : "Notebook Selected" ,
77
+ files : "selected" ,
78
+ type : "json-download" ,
79
+ icon : "/assets/icons/jupyter_logo.png" ,
80
+ url : "https://notebook.scicat.org" ,
81
+ target : "_blank" ,
82
+ enabled : "#Selected" ,
83
+ authorization : [ "#datasetAccess" , "#datasetPublic" ] ,
84
+ filename : "{{ uuid }}.ipynb" ,
85
+ } ,
86
+ {
87
+ id : "test-test-test-test-1" ,
88
+ order : 5 ,
89
+ label : "Notebook Selected" ,
90
+ files : "selected" ,
91
+ type : "json-download" ,
92
+ icon : "/assets/icons/jupyter_logo.png" ,
93
+ url : "https://notebook.scicat.org" ,
94
+ target : "_blank" ,
95
+ enabled : "#Selected" ,
96
+ authorization : [ "#datasetAccess" , "#datasetPublic" ] ,
97
+ payload : "" ,
98
+ filename : "{{ uuid }}.ipynb" ,
99
+ } ,
100
+ {
101
+ id : "test-test-test-test-2" ,
102
+ order : 6 ,
65
103
label : "Notebook Selected" ,
66
104
files : "selected" ,
105
+ type : "json-download" ,
67
106
icon : "/assets/icons/jupyter_logo.png" ,
68
107
url : "https://notebook.scicat.org" ,
69
108
target : "_blank" ,
70
109
enabled : "#Selected" ,
71
110
authorization : [ "#datasetAccess" , "#datasetPublic" ] ,
111
+ filename : "{{ uuid }}.ipynb" ,
72
112
} ,
73
113
] ;
74
114
@@ -121,6 +161,8 @@ describe("1000: DatafilesActionComponent", () => {
121
161
download_selected = 1 ,
122
162
notebook_all = 2 ,
123
163
notebook_selected = 3 ,
164
+ json_download_with_payload = 4 ,
165
+ json_download_without_payload = 5 ,
124
166
}
125
167
126
168
const usersControllerGetUserJWTV3 = ( ) => ( {
@@ -732,4 +774,69 @@ describe("1000: DatafilesActionComponent", () => {
732
774
actionsConfig [ actionSelectorType . notebook_selected ] . label ,
733
775
) ;
734
776
} ) ;
777
+
778
+ it ( "0600: JSON-download action should fetch with customized payload fields when provided" , async ( ) => {
779
+ selectTestCase (
780
+ actionSelectorType . json_download_with_payload ,
781
+ maxSizeType . higher ,
782
+ selectedFilesType . none ,
783
+ ) ;
784
+ actionsConfig [ actionSelectorType . json_download_with_payload ] . payload =
785
+ '{"test_id":"test-id","parameters":{"testField1":"{{ datasetPid }}","testField2":"{{ sourceFolder }}","files": {{ filesPath }},"jwt":"{{ jwt }}","scicat_url":"https://staging.scicat.ess.url","file_server_url":"sftserver2.esss.dk","file_server_port":"22"}}' ;
786
+ component . jwt = "TEST_JWT" ;
787
+ spyOn ( window , "fetch" ) . and . returnValue (
788
+ Promise . resolve (
789
+ new Response ( new Blob ( ) , {
790
+ status : 200 ,
791
+ statusText : "OK" ,
792
+ headers : { "Content-Type" : "application/json" } ,
793
+ } ) ,
794
+ ) ,
795
+ ) ;
796
+ component . perform_action ( ) ;
797
+
798
+ const [ url , opts ] = ( window . fetch as jasmine . Spy ) . calls . mostRecent ( ) . args ;
799
+ expect ( url ) . toBe (
800
+ actionsConfig [ actionSelectorType . json_download_with_payload ] . url ,
801
+ ) ;
802
+ expect ( opts . method ) . toBe ( "POST" ) ;
803
+ expect ( opts . headers [ "Content-Type" ] ) . toBe ( "application/json" ) ;
804
+
805
+ const body = JSON . parse ( opts . body ) ;
806
+ expect ( body . test_id ) . toBe ( "test-id" ) ;
807
+ expect ( body . parameters . jwt ) . toBe ( "TEST_JWT" ) ;
808
+ expect ( body . parameters . testField1 ) . toBe ( actionDataset . pid ) ;
809
+ expect ( body . parameters . testField2 ) . toBe ( actionDataset . sourceFolder ) ;
810
+ } ) ;
811
+
812
+ it ( "0610: JSON-download action should fetch with default fields if payload is not provided" , async ( ) => {
813
+ selectTestCase (
814
+ actionSelectorType . json_download_without_payload ,
815
+ maxSizeType . higher ,
816
+ selectedFilesType . none ,
817
+ ) ;
818
+ component . jwt = "TEST_JWT2" ;
819
+ spyOn ( window , "fetch" ) . and . returnValue (
820
+ Promise . resolve (
821
+ new Response ( new Blob ( ) , {
822
+ status : 200 ,
823
+ statusText : "OK" ,
824
+ headers : { "Content-Type" : "application/json" } ,
825
+ } ) ,
826
+ ) ,
827
+ ) ;
828
+ component . perform_action ( ) ;
829
+
830
+ const [ url , opts ] = ( window . fetch as jasmine . Spy ) . calls . mostRecent ( ) . args ;
831
+ expect ( url ) . toBe (
832
+ actionsConfig [ actionSelectorType . json_download_without_payload ] . url ,
833
+ ) ;
834
+ expect ( opts . method ) . toBe ( "POST" ) ;
835
+ expect ( opts . headers [ "Content-Type" ] ) . toBe ( "application/json" ) ;
836
+
837
+ const body = JSON . parse ( opts . body ) ;
838
+ expect ( body . jwt ) . toBe ( "TEST_JWT2" ) ;
839
+ expect ( body . dataset ) . toBe ( actionDataset . pid ) ;
840
+ expect ( body . directory ) . toBe ( actionDataset . sourceFolder ) ;
841
+ } ) ;
735
842
} ) ;
0 commit comments