1- import createTaskJob from '../../../fixtures/job/task/create-task-job.json' ;
2- import task from '../../../fixtures/job/task/task.json' ;
3- import pendingTask from '../../../fixtures/job/task/pending-task.json' ;
4- import taskIDByTask from '../../../fixtures/job/task/task-id-by-task.json' ;
5- import noTask from '../../../fixtures/job/task/no-task.json' ;
1+ import createTaskJob from '../../../fixtures/resource/task/create-task-job.json' ;
2+ import task from '../../../fixtures/resource/task/task.json' ;
3+ import pendingTask from '../../../fixtures/resource/task/pending-task.json' ;
4+ import taskIDByTask from '../../../fixtures/resource/task/task-id-by-task.json' ;
5+ import noTask from '../../../fixtures/resource/task/no-task.json' ;
6+ import ImageManifest from '../../../fixtures/resource/task/image-manifest-url-task.json' ;
67import _ from 'lodash' ;
78
89describe ( 'Clear' , ( ) => {
@@ -13,56 +14,95 @@ describe('Clear', () => {
1314 cy . viewport ( 1440 , 1080 ) ;
1415 } ) ;
1516
16- it ( 'when no data is loaded' , ( ) => {
17- cy . get ( '#no-task' ) . should ( 'not.exist' ) ;
18-
19- cy . get ( '#light' ) . should ( 'exist' ) ;
20- cy . get ( '#no-task-image' ) . should ( 'not.exist' ) ;
21-
22- // Click the Toggle Light button.
23- cy . get ( '#light' ) . click ( ) ;
24- cy . get ( '#light' ) . should ( 'have.class' , 'Mui-selected' ) ;
25-
26- // Check if it is switched to light mode.
27- cy . get ( '#main' ) . should ( 'have.css' , 'background-color' , 'rgb(244, 246, 248)' ) ;
28-
29- cy . get ( '#no-task-image' ) . should ( 'exist' ) ;
30-
31- cy . get ( '#dark-no-task-image' ) . should ( 'not.exist' ) ;
32-
33- cy . intercept (
34- {
35- method : 'post' ,
36- url : '/api/v1/jobs' ,
37- } ,
38- ( req ) => {
39- req . reply ( {
40- statusCode : 200 ,
41- body : createTaskJob ,
42- } ) ;
43- } ,
44- ) ;
45- cy . intercept (
46- {
47- method : 'GET' ,
48- url : '/api/v1/jobs/1' ,
49- } ,
50- ( req ) => {
51- req . reply ( {
52- statusCode : 200 ,
53- body : noTask ,
54- } ) ;
55- } ,
56- ) ;
57-
58- cy . get ( '#url' ) . click ( ) ;
59-
60- // Add url.
61- cy . get ( '#url' ) . type ( 'https://example.com/path/to/file' ) ;
62-
63- cy . get ( '#searchByURL' ) . click ( ) ;
64-
65- cy . get ( '#no-task' ) . should ( 'exist' ) ;
17+ describe ( 'when no data is loaded' , ( ) => {
18+ it ( 'when search by url has no data to load' , ( ) => {
19+ cy . get ( '#no-task' ) . should ( 'not.exist' ) ;
20+
21+ cy . get ( '#light' ) . should ( 'exist' ) ;
22+ cy . get ( '#no-task-image' ) . should ( 'not.exist' ) ;
23+
24+ // Click the Toggle Light button.
25+ cy . get ( '#light' ) . click ( ) ;
26+ cy . get ( '#light' ) . should ( 'have.class' , 'Mui-selected' ) ;
27+
28+ // Check if it is switched to light mode.
29+ cy . get ( '#main' ) . should ( 'have.css' , 'background-color' , 'rgb(244, 246, 248)' ) ;
30+
31+ cy . get ( '#no-task-image' ) . should ( 'exist' ) ;
32+
33+ cy . get ( '#dark-no-task-image' ) . should ( 'not.exist' ) ;
34+
35+ cy . intercept (
36+ {
37+ method : 'post' ,
38+ url : '/api/v1/jobs' ,
39+ } ,
40+ ( req ) => {
41+ req . reply ( {
42+ statusCode : 200 ,
43+ body : createTaskJob ,
44+ } ) ;
45+ } ,
46+ ) ;
47+ cy . intercept (
48+ {
49+ method : 'GET' ,
50+ url : '/api/v1/jobs/1' ,
51+ } ,
52+ ( req ) => {
53+ req . reply ( {
54+ statusCode : 200 ,
55+ body : noTask ,
56+ } ) ;
57+ } ,
58+ ) ;
59+
60+ cy . get ( '#url' ) . click ( ) ;
61+
62+ // Add url.
63+ cy . get ( '#url' ) . type ( 'https://example.com/path/to/file' ) ;
64+
65+ cy . get ( '#searchByURL' ) . click ( ) ;
66+
67+ cy . get ( '#no-task' ) . should ( 'exist' ) ;
68+ } ) ;
69+
70+ it ( 'when search by image manifest url has no data to load' , ( ) => {
71+ cy . get ( '#no-task' ) . should ( 'not.exist' ) ;
72+
73+ cy . get ( '#serach-image-manifest-url' ) . click ( ) ;
74+
75+ cy . intercept (
76+ {
77+ method : 'post' ,
78+ url : '/api/v1/jobs' ,
79+ } ,
80+ async ( req ) => {
81+ await new Promise ( ( resolve ) => setTimeout ( resolve , 200 ) ) ;
82+ req . reply ( {
83+ statusCode : 200 ,
84+ body : {
85+ image : {
86+ layers : [
87+ {
88+ url : 'https://ghcr.io/v2/dragonflyoss/scheduler/blobs/sha256:c7c72808bf776cd122bdaf4630a4a35ea319603d6a3b6cbffddd4c7fd6d2d269' ,
89+ } ,
90+ {
91+ url : 'https://ghcr.io/v2/dragonflyoss/scheduler/blobs/sha256:9986a736f7d3d24bb01b0a560fa0f19c4b57e56c646e1f998941529d28710e6b' ,
92+ } ,
93+ ] ,
94+ } ,
95+ peers : [ ] ,
96+ } ,
97+ } ) ;
98+ } ,
99+ ) ;
100+
101+ cy . get ( '#image-manifest-url' ) . type ( 'https://example.com/path/to/file{enter}' ) ;
102+
103+ // Shou You don't find any results!
104+ cy . get ( '#no-image-manifest-URL-task' ) . should ( 'exist' ) . and ( 'contain' , `You don't find any results!` ) ;
105+ } ) ;
66106 } ) ;
67107
68108 describe ( 'when data is loaded' , ( ) => {
@@ -283,6 +323,42 @@ describe('Clear', () => {
283323 // Pagination should not be displayed.
284324 cy . get ( '#pagination-1' ) . should ( 'exist' ) ;
285325 } ) ;
326+
327+ it ( 'can search by image manifest url' , ( ) => {
328+ cy . get ( '#no-task' ) . should ( 'not.exist' ) ;
329+
330+ cy . get ( '#serach-image-manifest-url' ) . click ( ) ;
331+
332+ cy . intercept (
333+ {
334+ method : 'post' ,
335+ url : '/api/v1/jobs' ,
336+ } ,
337+ async ( req ) => {
338+ await new Promise ( ( resolve ) => setTimeout ( resolve , 200 ) ) ;
339+ req . reply ( {
340+ statusCode : 200 ,
341+ body : ImageManifest ,
342+ } ) ;
343+ } ,
344+ ) ;
345+
346+ cy . get ( '#image-manifest-url' ) . type ( 'https://example.com/path/to/file{enter}' ) ;
347+
348+ // Show is loading.
349+ cy . get ( '#isLoading' ) . should ( 'exist' ) ;
350+
351+ // Display cache information.
352+ cy . get ( '#blobs' ) . should ( 'have.text' , 'Total: 5' ) ;
353+ cy . get ( '#scheduler-id-0' ) . should ( 'exist' , 'ID : 1' ) ;
354+ cy . get ( '#isLoading' ) . should ( 'not.exist' ) ;
355+ cy . get ( '#scheduler-1-hostname-0' ) . should ( 'have.text' , 'kind-worker1' ) ;
356+ cy . get ( '#scheduler-1-ip-0' ) . should ( 'have.text' , '172.18.0.4' ) ;
357+ cy . get ( '#scheduler-1-proportion-0' ) . should ( 'contain' , '60.00%' ) ;
358+
359+ // Should display URL.
360+ cy . get ( '#scheduler-1-url-0' ) . click ( ) ;
361+ } ) ;
286362 } ) ;
287363
288364 describe ( 'should handle API error response' , ( ) => {
@@ -395,7 +471,7 @@ describe('Clear', () => {
395471 cy . wait ( 60000 ) ;
396472 } ) ;
397473
398- it ( 'Delete cache API error response' , ( ) => {
474+ it ( 'delete cache API error response' , ( ) => {
399475 // Search by task id.
400476 cy . get ( '#serach-task-id' ) . click ( ) ;
401477 cy . intercept (
@@ -434,6 +510,27 @@ describe('Clear', () => {
434510 cy . get ( '.MuiAlert-action > .MuiButtonBase-root' ) . click ( ) ;
435511 cy . get ( '.MuiAlert-message' ) . should ( 'not.exist' ) ;
436512 } ) ;
513+
514+ it ( 'search by image manifest url API error response' , ( ) => {
515+ cy . get ( '#no-task' ) . should ( 'not.exist' ) ;
516+ cy . get ( '#serach-image-manifest-url' ) . click ( ) ;
517+ cy . intercept (
518+ {
519+ method : 'post' ,
520+ url : '/api/v1/jobs' ,
521+ } ,
522+ async ( req ) => {
523+ await new Promise ( ( resolve ) => setTimeout ( resolve , 200 ) ) ;
524+ req . reply ( {
525+ forceNetworkError : true ,
526+ } ) ;
527+ } ,
528+ ) ;
529+ cy . get ( '#image-manifest-url' ) . type ( 'https://example.com/path/to/file{enter}' ) ;
530+
531+ // Show error message.
532+ cy . get ( '.MuiAlert-message' ) . should ( 'be.visible' ) . and ( 'contain' , 'Failed to fetch' ) ;
533+ } ) ;
437534 } ) ;
438535
439536 describe ( 'delete' , ( ) => {
@@ -625,10 +722,7 @@ describe('Clear', () => {
625722
626723 cy . get ( '#searchByURL' ) . click ( ) ;
627724
628- cy . get ( ':nth-child(2) > .MuiPaper-root > .css-whqzh4 > .css-70qvj9 > .css-1y3f2j > #schedulerTotal' ) . should (
629- 'contain' ,
630- '2' ,
631- ) ;
725+ cy . get ( '#scheduler-id-1' ) . should ( 'contain' , '2' ) ;
632726
633727 cy . get ( ':nth-child(2) > .MuiPaper-root > .css-whqzh4 > .MuiButtonBase-root' ) . click ( ) ;
634728
@@ -698,10 +792,7 @@ describe('Clear', () => {
698792 'fe0c4a611d35e338efd342c346a2c671c358c5187c483a5fc7cd66c6685ce916{enter}' ,
699793 ) ;
700794
701- cy . get ( ':nth-child(2) > .MuiPaper-root > .css-whqzh4 > .css-70qvj9 > .css-1y3f2j > #schedulerTotal' ) . should (
702- 'contain' ,
703- '2' ,
704- ) ;
795+ cy . get ( '#scheduler-id-1' ) . should ( 'contain' , '2' ) ;
705796
706797 cy . get ( ':nth-child(2) > .MuiPaper-root > .css-whqzh4 > .MuiButtonBase-root' ) . click ( ) ;
707798
@@ -819,7 +910,7 @@ describe('Clear', () => {
819910 . and ( 'have.text' , 'Fill in the characters, the length is 0-1000.' ) ;
820911 } ) ;
821912
822- it ( 'try to verify url ' , ( ) => {
913+ it ( 'try to verify content for calculating task id ' , ( ) => {
823914 const characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' ;
824915 const contentForCalculatingTaskID = _ . times ( 1001 , ( ) => _ . sample ( characters ) ) . join ( '' ) ;
825916
@@ -831,5 +922,26 @@ describe('Clear', () => {
831922 . should ( 'be.visible' )
832923 . and ( 'have.text' , 'Fill in the characters, the length is 0-1000.' ) ;
833924 } ) ;
925+
926+ it ( 'try to verify image manifest url' , ( ) => {
927+ const characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' ;
928+ const url = _ . times ( 1001 , ( ) => _ . sample ( characters ) ) . join ( '' ) ;
929+
930+ cy . get ( '#serach-image-manifest-url' ) . click ( ) ;
931+
932+ cy . get ( '#image-manifest-url' ) . click ( ) ;
933+
934+ // Should display message url the validation error.
935+ cy . get ( '#image-manifest-url' ) . type ( `https://docs${ url } ` ) ;
936+
937+ cy . get ( '#image-manifest-url-helper-text' )
938+ . should ( 'be.visible' )
939+ . and ( 'have.text' , 'Fill in the characters, the length is 1-1000.' ) ;
940+
941+ cy . get ( '#image-manifest-url' ) . clear ( ) ;
942+ cy . get ( '#image-manifest-url' ) . type ( 'https://docs' ) ;
943+
944+ cy . get ( '#image-manifest-url-helper-text' ) . should ( 'not.exist' ) ;
945+ } ) ;
834946 } ) ;
835947} ) ;
0 commit comments