1
- import { currentURL } from '@ember/test-helpers' ;
2
1
import { module , test } from 'qunit' ;
3
2
import { setupApplicationTest } from 'ember-qunit' ;
4
- import moment from 'moment' ;
5
3
6
4
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage' ;
7
5
import Response from 'ember-cli-mirage/response' ;
8
6
9
- import { formatBytes } from 'nomad-ui/helpers/format-bytes' ;
10
- import { filesForPath } from 'nomad-ui/mirage/config' ;
11
-
12
7
import browseFilesystem from './behaviors/fs' ;
13
8
14
9
import FS from 'nomad-ui/tests/pages/allocations/task/fs' ;
15
10
16
11
let allocation ;
17
- let allocationShortId ;
18
12
let files ;
19
13
20
- const fileSort = ( prop , files ) => {
21
- let dir = [ ] ;
22
- let file = [ ] ;
23
- files . forEach ( f => {
24
- if ( f . isDir ) {
25
- dir . push ( f ) ;
26
- } else {
27
- file . push ( f ) ;
28
- }
29
- } ) ;
30
-
31
- return dir . sortBy ( prop ) . concat ( file . sortBy ( prop ) ) ;
32
- } ;
33
-
34
14
module ( 'Acceptance | allocation fs' , function ( hooks ) {
35
15
setupApplicationTest ( hooks ) ;
36
16
setupMirage ( hooks ) ;
@@ -41,7 +21,6 @@ module('Acceptance | allocation fs', function(hooks) {
41
21
const job = server . create ( 'job' , { createAllocations : false } ) ;
42
22
43
23
allocation = server . create ( 'allocation' , { jobId : job . id , clientStatus : 'running' } ) ;
44
- allocationShortId = allocation . id . split ( '-' ) [ 0 ] ;
45
24
46
25
this . allocation = allocation ;
47
26
@@ -65,11 +44,7 @@ module('Acceptance | allocation fs', function(hooks) {
65
44
66
45
this . files = files ;
67
46
this . directory = files [ 0 ] ;
68
- } ) ;
69
-
70
- test ( 'visiting /allocations/:allocation_id/fs' , async function ( assert ) {
71
- await FS . visitAllocation ( { id : allocation . id } ) ;
72
- assert . equal ( currentURL ( ) , `/allocations/${ allocation . id } /fs` , 'No redirect' ) ;
47
+ this . nestedDirectory = files [ 1 ] ;
73
48
} ) ;
74
49
75
50
test ( 'when the allocation is not running, an empty state is shown' , async function ( assert ) {
@@ -96,76 +71,7 @@ module('Acceptance | allocation fs', function(hooks) {
96
71
getTitleComponent : ( { allocation } ) => `Allocation ${ allocation . id . split ( '-' ) [ 0 ] } filesystem` ,
97
72
getBreadcrumbComponent : ( { allocation } ) => allocation . id . split ( '-' ) [ 0 ] ,
98
73
getFilesystemRoot : ( ) => '' ,
74
+ pageObjectVisitFunctionName : 'visitAllocation' ,
99
75
pageObjectVisitPathFunctionName : 'visitAllocationPath' ,
100
76
} ) ;
101
-
102
- test ( 'navigating allocation filesystem' , async function ( assert ) {
103
- await FS . visitAllocationPath ( { id : allocation . id , path : '/' } ) ;
104
-
105
- const sortedFiles = fileSort ( 'name' , filesForPath ( this . server . schema . allocFiles , '' ) . models ) ;
106
-
107
- assert . ok ( FS . fileViewer . isHidden ) ;
108
-
109
- assert . equal ( FS . directoryEntries . length , 4 ) ;
110
-
111
- assert . equal ( FS . breadcrumbsText , allocationShortId ) ;
112
-
113
- assert . equal ( FS . breadcrumbs . length , 1 ) ;
114
- assert . ok ( FS . breadcrumbs [ 0 ] . isActive ) ;
115
- assert . equal ( FS . breadcrumbs [ 0 ] . text , allocationShortId ) ;
116
-
117
- FS . directoryEntries [ 0 ] . as ( directory => {
118
- const fileRecord = sortedFiles [ 0 ] ;
119
- assert . equal ( directory . name , fileRecord . name , 'directories should come first' ) ;
120
- assert . ok ( directory . isDirectory ) ;
121
- assert . equal ( directory . size , '' , 'directory sizes are hidden' ) ;
122
- assert . equal ( directory . lastModified , moment ( fileRecord . modTime ) . fromNow ( ) ) ;
123
- assert . notOk ( directory . path . includes ( '//' ) , 'paths shouldn’t have redundant separators' ) ;
124
- } ) ;
125
-
126
- FS . directoryEntries [ 2 ] . as ( file => {
127
- const fileRecord = sortedFiles [ 2 ] ;
128
- assert . equal ( file . name , fileRecord . name ) ;
129
- assert . ok ( file . isFile ) ;
130
- assert . equal ( file . size , formatBytes ( [ fileRecord . size ] ) ) ;
131
- assert . equal ( file . lastModified , moment ( fileRecord . modTime ) . fromNow ( ) ) ;
132
- } ) ;
133
-
134
- await FS . directoryEntries [ 0 ] . visit ( ) ;
135
-
136
- assert . equal ( FS . directoryEntries . length , 1 ) ;
137
-
138
- assert . equal ( FS . breadcrumbs . length , 2 ) ;
139
- assert . equal ( FS . breadcrumbsText , `${ allocationShortId } ${ files [ 0 ] . name } ` ) ;
140
-
141
- assert . notOk ( FS . breadcrumbs [ 0 ] . isActive ) ;
142
-
143
- assert . equal ( FS . breadcrumbs [ 1 ] . text , files [ 0 ] . name ) ;
144
- assert . ok ( FS . breadcrumbs [ 1 ] . isActive ) ;
145
-
146
- await FS . directoryEntries [ 0 ] . visit ( ) ;
147
-
148
- assert . equal ( FS . directoryEntries . length , 1 ) ;
149
- assert . notOk (
150
- FS . directoryEntries [ 0 ] . path . includes ( '//' ) ,
151
- 'paths shouldn’t have redundant separators'
152
- ) ;
153
-
154
- assert . equal ( FS . breadcrumbs . length , 3 ) ;
155
- assert . equal ( FS . breadcrumbsText , `${ allocationShortId } ${ files [ 0 ] . name } ${ files [ 1 ] . name } ` ) ;
156
- assert . equal ( FS . breadcrumbs [ 2 ] . text , files [ 1 ] . name ) ;
157
-
158
- assert . notOk (
159
- FS . breadcrumbs [ 0 ] . path . includes ( '//' ) ,
160
- 'paths shouldn’t have redundant separators'
161
- ) ;
162
- assert . notOk (
163
- FS . breadcrumbs [ 1 ] . path . includes ( '//' ) ,
164
- 'paths shouldn’t have redundant separators'
165
- ) ;
166
-
167
- await FS . breadcrumbs [ 1 ] . visit ( ) ;
168
- assert . equal ( FS . breadcrumbsText , `${ allocationShortId } ${ files [ 0 ] . name } ` ) ;
169
- assert . equal ( FS . breadcrumbs . length , 2 ) ;
170
- } ) ;
171
77
} ) ;
0 commit comments