@@ -114,7 +114,7 @@ describe('EditFilesOptions', () => {
114114 cy . findByText ( 'Close' ) . click ( )
115115 } )
116116
117- it ( 'does not show the No Selected Files message when files are selected and one option is clicked' , ( ) => {
117+ it . only ( 'does not show the No Selected Files message when files are selected and one option is clicked' , ( ) => {
118118 cy . customMount (
119119 < EditFilesOptions
120120 files = { files }
@@ -163,8 +163,10 @@ describe('EditFilesOptions for a single file', () => {
163163 )
164164
165165 cy . findByRole ( 'button' , { name : 'Restrict' } ) . should ( 'exist' ) . click ( )
166+ cy . findByRole ( 'dialog' ) . should ( 'exist' )
166167 cy . findByRole ( 'button' , { name : 'Save Changes' } ) . should ( 'exist' )
167168 cy . findByText ( 'Cancel' ) . click ( )
169+ cy . findByRole ( 'dialog' ) . should ( 'not.exist' )
168170 } )
169171
170172 it ( 'renders the unrestrict option if file is restricted' , ( ) => {
@@ -179,12 +181,14 @@ describe('EditFilesOptions for a single file', () => {
179181 )
180182
181183 cy . findByRole ( 'button' , { name : 'Unrestrict' } ) . should ( 'exist' ) . click ( )
184+ cy . findByRole ( 'dialog' ) . should ( 'exist' )
182185 cy . findByText ( 'The file will be unrestricted.' ) . should ( 'exist' )
183186 cy . findByRole ( 'button' , { name : 'Save Changes' } ) . should ( 'exist' )
184187 cy . findByText ( 'Cancel' ) . click ( )
188+ cy . findByRole ( 'dialog' ) . should ( 'not.exist' )
185189 } )
186190
187- it ( 'renders delete' , ( ) => {
191+ it ( 'renders delete modal ' , ( ) => {
188192 const fileUnrestricted = FilePreviewMother . createDefault ( )
189193 cy . customMount (
190194 < EditFilesOptions
@@ -196,7 +200,66 @@ describe('EditFilesOptions for a single file', () => {
196200 )
197201
198202 cy . findByRole ( 'button' , { name : 'Delete' } ) . should ( 'exist' ) . click ( )
203+ cy . findByRole ( 'dialog' ) . should ( 'exist' )
199204 cy . findByText ( 'The file will be deleted after you click on the Delete button.' ) . should ( 'exist' )
200205 cy . findByText ( 'Cancel' ) . click ( )
206+ cy . findByRole ( 'dialog' ) . should ( 'not.exist' )
207+ } )
208+
209+ it ( 'should delete file if delete button clicked' , ( ) => {
210+ fileRepository . delete = cy . stub ( ) . resolves ( )
211+ cy . customMount (
212+ < EditFilesOptions
213+ file = { FilePreviewMother . createDefault ( ) }
214+ fileRepository = { fileRepository }
215+ datasetInfo = { datasetInfo }
216+ isHeader = { false }
217+ />
218+ )
219+
220+ cy . findByRole ( 'button' , { name : 'Delete' } ) . click ( )
221+ cy . findByRole ( 'dialog' ) . should ( 'exist' )
222+ cy . findByTestId ( 'deleteButton' ) . click ( )
223+ cy . findByRole ( 'dialog' ) . should ( 'not.exist' )
224+ cy . findByText ( / T h e f i l e h a s b e e n d e l e t e d ./ ) . should ( 'exist' )
225+ } )
226+
227+ it ( 'should restrict file if restrict button clicked' , ( ) => {
228+ fileRepository . restrict = cy . stub ( ) . resolves ( )
229+ cy . customMount (
230+ < EditFilesOptions
231+ file = { FilePreviewMother . createDefault ( ) }
232+ fileRepository = { fileRepository }
233+ datasetInfo = { datasetInfo }
234+ isHeader = { false }
235+ />
236+ )
237+
238+ cy . findByRole ( 'button' , { name : 'Restrict' } ) . click ( )
239+ cy . findByRole ( 'dialog' ) . should ( 'exist' )
240+ cy . findByRole ( 'button' , { name : / S a v e C h a n g e s / i } ) . click ( )
241+ cy . findByRole ( 'dialog' ) . should ( 'not.exist' )
242+ cy . findByText ( / T h e f i l e h a s b e e n r e s t r i c t e d ./ ) . should ( 'exist' )
243+ } )
244+
245+ it ( 'should unrestrict file if restrict button clicked' , ( ) => {
246+ fileRepository . restrict = cy . stub ( ) . resolves ( )
247+ const fileRestricted = FilePreviewMother . createRestricted ( )
248+
249+ cy . customMount (
250+ < EditFilesOptions
251+ file = { fileRestricted }
252+ fileRepository = { fileRepository }
253+ datasetInfo = { datasetInfo }
254+ isHeader = { false }
255+ />
256+ )
257+
258+ cy . findByRole ( 'button' , { name : 'Unrestrict' } ) . click ( )
259+ cy . findByRole ( 'dialog' ) . should ( 'exist' )
260+ cy . findByText ( 'The file will be unrestricted.' ) . should ( 'exist' )
261+ cy . findByRole ( 'button' , { name : / S a v e C h a n g e s / i } ) . click ( )
262+ cy . findByRole ( 'dialog' ) . should ( 'not.exist' )
263+ cy . findByText ( / T h e f i l e h a s b e e n u n r e s t r i c t e d ./ ) . should ( 'exist' )
201264 } )
202265} )
0 commit comments