1
+ /// <reference types="Cypress" />
2
+ import {
3
+ ContentBuilder ,
4
+ DocumentTypeBuilder
5
+ } from 'umbraco-cypress-testhelpers' ;
6
+
7
+ context ( 'Packages' , ( ) => {
8
+ const packageName = "TestPackage" ;
9
+ const rootDocTypeName = "Test document type" ;
10
+ const nodeName = "1) Home" ;
11
+
12
+ beforeEach ( ( ) => {
13
+ cy . umbracoLogin ( Cypress . env ( 'username' ) , Cypress . env ( 'password' ) , false ) ;
14
+ } ) ;
15
+
16
+ function CreatePackage ( contentId ) {
17
+ const newPackage = {
18
+ id : 0 ,
19
+ packageGuid : "00000000-0000-0000-0000-000000000000" ,
20
+ name : "TestPackage" ,
21
+ packagePath : "" ,
22
+ contentLoadChildNodes : false ,
23
+ contentNodeId : contentId ,
24
+ macros : [ ] ,
25
+ languages : [ ] ,
26
+ dictionaryItems : [ ] ,
27
+ templates : [ ] ,
28
+ partialViews : [ ] ,
29
+ documentTypes : [ ] ,
30
+ mediaTypes : [ ] ,
31
+ stylesheets : [ ] ,
32
+ scripts : [ ] ,
33
+ dataTypes : [ ] ,
34
+ mediaUdis : [ ] ,
35
+ mediaLoadChildNodes : false
36
+ }
37
+ const url = "https://localhost:44331/umbraco/backoffice/umbracoapi/package/PostSavePackage" ;
38
+ cy . umbracoApiRequest ( url , 'POST' , newPackage ) ;
39
+ }
40
+
41
+ function CreateSimplePackage ( ) {
42
+
43
+ const rootDocType = new DocumentTypeBuilder ( )
44
+ . withName ( rootDocTypeName )
45
+ . withAllowAsRoot ( true )
46
+ . build ( ) ;
47
+
48
+ cy . saveDocumentType ( rootDocType ) . then ( ( generatedRootDocType ) => {
49
+ const rootDocTypeAlias = generatedRootDocType [ "alias" ] ;
50
+
51
+ const rootContentNode = new ContentBuilder ( )
52
+ . withContentTypeAlias ( rootDocTypeAlias )
53
+ . withAction ( "saveNew" )
54
+ . addVariant ( )
55
+ . withName ( nodeName )
56
+ . withSave ( true )
57
+ . done ( )
58
+ . build ( ) ;
59
+ cy . saveContent ( rootContentNode ) . then ( ( generatedContent ) => {
60
+ CreatePackage ( generatedContent . Id ) ;
61
+ } ) ;
62
+ } ) ;
63
+ }
64
+
65
+ it ( 'Creates a simple package' , ( ) => {
66
+
67
+ cy . umbracoEnsurePackageNameNotExists ( packageName ) ;
68
+ cy . deleteAllContent ( ) ;
69
+ cy . umbracoEnsureDocumentTypeNameNotExists ( rootDocTypeName ) ;
70
+
71
+ const rootDocType = new DocumentTypeBuilder ( )
72
+ . withName ( rootDocTypeName )
73
+ . withAllowAsRoot ( true )
74
+ . build ( ) ;
75
+
76
+ cy . saveDocumentType ( rootDocType ) . then ( ( generatedRootDocType ) => {
77
+ const rootDocTypeAlias = generatedRootDocType [ "alias" ] ;
78
+
79
+ const rootContentNode = new ContentBuilder ( )
80
+ . withContentTypeAlias ( rootDocTypeAlias )
81
+ . withAction ( "saveNew" )
82
+ . addVariant ( )
83
+ . withName ( nodeName )
84
+ . withSave ( true )
85
+ . done ( )
86
+ . build ( ) ;
87
+ cy . saveContent ( rootContentNode ) ;
88
+ } ) ;
89
+
90
+ // Navigate to create package section
91
+ cy . umbracoSection ( 'packages' ) ;
92
+ cy . contains ( 'Created' ) . click ( ) ;
93
+ cy . contains ( 'Create package' ) . click ( ) ;
94
+
95
+ // Fill out package creation form
96
+ cy . get ( '#headerName' ) . should ( 'be.visible' ) ;
97
+ cy . wait ( 1000 ) ;
98
+ cy . get ( '#headerName' ) . type ( packageName ) ;
99
+ cy . get ( '.controls > .umb-node-preview-add' ) . click ( ) ;
100
+ cy . get ( '.umb-tree-item__label' ) . first ( ) . click ( ) ;
101
+ cy . contains ( 'Create' ) . click ( ) ;
102
+
103
+ // Navigate pack to packages and Assert the file is created
104
+ cy . umbracoSection ( 'packages' ) ;
105
+ cy . contains ( 'Created' ) . click ( ) ;
106
+ cy . contains ( packageName ) . should ( 'be.visible' ) ;
107
+
108
+ // Cleanup
109
+ cy . umbracoEnsurePackageNameNotExists ( packageName ) ;
110
+ cy . deleteAllContent ( ) ;
111
+ cy . umbracoEnsureDocumentTypeNameNotExists ( rootDocTypeName ) ;
112
+ } ) ;
113
+
114
+ it ( 'Delete package' , ( ) => {
115
+
116
+ // Ensure cleanup before test
117
+ cy . deleteAllContent ( ) ;
118
+ cy . umbracoEnsureDocumentTypeNameNotExists ( rootDocTypeName ) ;
119
+ cy . umbracoEnsurePackageNameNotExists ( packageName ) ;
120
+
121
+ CreateSimplePackage ( ) ;
122
+
123
+ // Navigate to create package section
124
+ cy . umbracoSection ( 'packages' ) ;
125
+ cy . contains ( 'Created' ) . click ( ) ;
126
+ cy . contains ( 'Delete' ) . click ( ) ;
127
+ cy . contains ( 'Yes, delete' ) . click ( ) ;
128
+
129
+ // Assert
130
+ cy . contains ( 'TestPackage' ) . should ( 'not.exist' ) ;
131
+
132
+ // Cleanup
133
+ cy . deleteAllContent ( ) ;
134
+ cy . umbracoEnsureDocumentTypeNameNotExists ( rootDocTypeName ) ;
135
+ cy . umbracoEnsurePackageNameNotExists ( packageName ) ;
136
+ } ) ;
137
+
138
+ it ( 'Download package' , ( ) => {
139
+
140
+ // Ensure cleanup before test
141
+ cy . deleteAllContent ( ) ;
142
+ cy . umbracoEnsureDocumentTypeNameNotExists ( rootDocTypeName ) ;
143
+ cy . umbracoEnsurePackageNameNotExists ( packageName ) ;
144
+
145
+ CreateSimplePackage ( ) ;
146
+
147
+ // Navigate to package and download
148
+ cy . umbracoSection ( 'packages' ) ;
149
+ cy . contains ( 'Created' ) . click ( ) ;
150
+ cy . contains ( 'TestPackage' ) . click ( ) ;
151
+ cy . contains ( 'Download' ) . click ( ) ;
152
+
153
+ // Assert
154
+ cy . verifyDownload ( 'package.xml' ) ;
155
+
156
+ // Cleanup
157
+ cy . deleteAllContent ( ) ;
158
+ cy . umbracoEnsureDocumentTypeNameNotExists ( rootDocTypeName ) ;
159
+ cy . umbracoEnsurePackageNameNotExists ( packageName ) ;
160
+ } ) ;
161
+ } ) ;
0 commit comments