@@ -14,6 +14,28 @@ jest.mock("app");
14
14
15
15
const { server, http } = useServerMock ( ) ;
16
16
17
+ async function init ( wrapper , data ) {
18
+ // the file dialog modal should exist
19
+ const filesDialogComponent = wrapper . findComponent ( FilesDialog ) ;
20
+ expect ( filesDialogComponent . exists ( ) ) . toBe ( true ) ;
21
+ filesDialogComponent . vm . callback ( { url : data . url } ) ;
22
+ // HACK to avoid https://github.com/facebook/jest/issues/2549 (URL implementation is not the same as global node)
23
+ wrapper . vm . pathChunks = data . pathChunks ;
24
+ await flushPromises ( ) ;
25
+ await validateLatestEmittedPath ( wrapper , data . url ) ;
26
+ }
27
+
28
+ async function validateLatestEmittedPath ( wrapper , expectedPath ) {
29
+ const latestEmitIndex = wrapper . emitted ( ) [ "input" ] . length - 1 ;
30
+ const latestPath = wrapper . emitted ( ) [ "input" ] [ latestEmitIndex ] [ 0 ] ;
31
+ expect ( latestPath ) . toBe ( expectedPath ) ;
32
+
33
+ // also manually change prop value to be able to test the value being displayed
34
+ await wrapper . setProps ( { value : latestPath } ) ;
35
+ const fullPathDisplayed = wrapper . find ( "[data-description='directory full path']" ) ;
36
+ expect ( fullPathDisplayed . text ( ) ) . toBe ( `Directory Path: ${ expectedPath } ` ) ;
37
+ }
38
+
17
39
describe ( "DirectoryPathEditableBreadcrumb" , ( ) => {
18
40
let wrapper ;
19
41
let spyOnUrlSet ;
@@ -29,6 +51,11 @@ describe("DirectoryPathEditableBreadcrumb", () => {
29
51
const validPath = "validpath" ;
30
52
const invalidPath = "./];" ;
31
53
54
+ const testingDataWithSpecialChars = {
55
+ url : "gxfiles://directory/sub directory/with%20percent" ,
56
+ pathChunks : [ { pathChunk : "directory" } , { pathChunk : "sub%20directory" } , { pathChunk : "with%2520percent" } ] ,
57
+ } ;
58
+
32
59
const saveNewChunk = async ( path ) => {
33
60
// enter a new path chunk
34
61
const input = wrapper . find ( "#path-input-breadcrumb" ) ;
@@ -38,15 +65,6 @@ describe("DirectoryPathEditableBreadcrumb", () => {
38
65
input . trigger ( "keyup.enter" ) ;
39
66
return input ;
40
67
} ;
41
- const init = async ( ) => {
42
- // the file dialog modal should exist
43
- const filesDialogComponent = wrapper . findComponent ( FilesDialog ) ;
44
- expect ( filesDialogComponent . exists ( ) ) . toBe ( true ) ;
45
- filesDialogComponent . vm . callback ( { url : testingData . url } ) ;
46
- // HACK to avoid https://github.com/facebook/jest/issues/2549 (URL implementation is not the same as global node)
47
- wrapper . vm . pathChunks = testingData . pathChunks ;
48
- await flushPromises ( ) ;
49
- } ;
50
68
51
69
beforeEach ( async ( ) => {
52
70
spyOnUrlSet = jest . spyOn ( FormDirectory . methods , "setUrl" ) ;
@@ -67,13 +85,12 @@ describe("DirectoryPathEditableBreadcrumb", () => {
67
85
68
86
wrapper = mount ( FormDirectory , {
69
87
propsData : {
70
- callback : ( ) => { } ,
88
+ value : null ,
71
89
} ,
72
90
localVue : localVue ,
73
91
pinia,
74
92
} ) ;
75
93
await flushPromises ( ) ;
76
- await init ( ) ;
77
94
} ) ;
78
95
afterEach ( async ( ) => {
79
96
if ( wrapper ) {
@@ -83,6 +100,7 @@ describe("DirectoryPathEditableBreadcrumb", () => {
83
100
} ) ;
84
101
85
102
it ( "should render Breadcrumb" , async ( ) => {
103
+ await init ( wrapper , testingData ) ;
86
104
// after initial folder is chosen, setUrl() should be called and modal disappear
87
105
expect ( spyOnUrlSet ) . toHaveBeenCalled ( ) ;
88
106
expect ( wrapper . findComponent ( FilesDialog ) . exists ( ) ) . toBe ( false ) ;
@@ -107,6 +125,7 @@ describe("DirectoryPathEditableBreadcrumb", () => {
107
125
} ) ;
108
126
109
127
it ( "should prevent invalid Paths" , async ( ) => {
128
+ await init ( wrapper , testingData ) ;
110
129
// enter a new path chunk
111
130
const input = await saveNewChunk ( invalidPath ) ;
112
131
await flushPromises ( ) ;
@@ -117,6 +136,7 @@ describe("DirectoryPathEditableBreadcrumb", () => {
117
136
} ) ;
118
137
119
138
it ( "should save and remove new Paths" , async ( ) => {
139
+ await init ( wrapper , testingData ) ;
120
140
// enter a new path chunk
121
141
const input = await saveNewChunk ( validPath ) ;
122
142
@@ -129,19 +149,31 @@ describe("DirectoryPathEditableBreadcrumb", () => {
129
149
expect ( wrapper . findAll ( "li.breadcrumb-item" ) . length ) . toBe ( testingData . expectedNumberOfPaths + 1 ) ;
130
150
// find newly added chunk
131
151
const addedChunk = wrapper . findAll ( "li.breadcrumb-item button" ) . wrappers . find ( ( e ) => e . text ( ) === validPath ) ;
152
+
153
+ await validateLatestEmittedPath ( wrapper , `${ testingData . url } /${ validPath } ` ) ;
154
+
132
155
// remove chunk from the path
133
156
await addedChunk . trigger ( "click" ) ;
134
157
await flushPromises ( ) ;
135
158
// number of elements should be the same again
136
159
expect ( wrapper . findAll ( "li.breadcrumb-item" ) . length ) . toBe ( testingData . expectedNumberOfPaths ) ;
160
+
161
+ await validateLatestEmittedPath ( wrapper , testingData . url ) ;
137
162
} ) ;
138
163
139
164
it ( "should update new path" , async ( ) => {
165
+ await init ( wrapper , testingData ) ;
140
166
// enter a new path chunk
141
167
expect ( spyOnUpdateURL ) . toHaveBeenCalled ( ) ;
142
168
await saveNewChunk ( validPath ) ;
143
169
await flushPromises ( ) ;
144
170
145
171
expect ( spyOnUpdateURL ) . toHaveBeenCalled ( ) ;
146
172
} ) ;
173
+
174
+ it ( "should retain special characters in path" , async ( ) => {
175
+ // the init function itself validates that the emits and path display
176
+ // retain special characters in the url
177
+ await init ( wrapper , testingDataWithSpecialChars ) ;
178
+ } ) ;
147
179
} ) ;
0 commit comments