1
+ import { makeArrayOfObjects , buildOptionsObj } from '../src/components/helper/processLogHelper.js' ;
2
+ import React from 'react' ;
3
+
4
+ describe ( 'makeArrayOfObjects' , ( ) => {
5
+ it ( 'returns an array' , ( ) => {
6
+ const string = `Hello from Docker!
7
+
8
+ This message shows that your installation appears to be working correctly.
9
+
10
+ ` ;
11
+ const result = makeArrayOfObjects ( string ) ;
12
+ expect ( result ) . toBeInstanceOf ( Array ) ;
13
+ } ) ;
14
+
15
+ it ( 'each element in returned array is of type object' , ( ) => {
16
+ const processLog = 'this is the timestamp\nthis is the log message\nthis is the second timestamp\nthis is the second log message' ;
17
+ const result = makeArrayOfObjects ( processLog ) ;
18
+
19
+ let output = false ;
20
+
21
+ if ( result . every ( ( element ) => typeof element === 'object' ) ) {
22
+ output = true ;
23
+ }
24
+
25
+ expect ( output ) . toEqual ( true ) ;
26
+ } ) ;
27
+
28
+ it ( 'each object in returned array has timeStamp and logMsg properties' , ( ) => {
29
+ const processLog = 'this_is_the_first_timestampZ this is the first log message\nthere is no second time stamp but there is a second log message' ;
30
+ const result = makeArrayOfObjects ( processLog ) ;
31
+
32
+ let output = false ;
33
+
34
+ if ( result . every ( ( element ) =>
35
+ element . timeStamp && element . logMsg
36
+ ) ) {
37
+ output = true ;
38
+ }
39
+
40
+ expect ( output ) . toEqual ( true ) ;
41
+ } ) ;
42
+
43
+ it ( 'log lines without timestamp will have "----" as value of timestamp property, otherwise the value will be timestamp' , ( ) => {
44
+ const processLog = 'this_is_the_first_timestampZ this is the first log message\nthere is no second time stamp but there is a second log message\n \n ' ;
45
+ const result = makeArrayOfObjects ( processLog ) ;
46
+
47
+ expect ( result [ 0 ] . timeStamp ) . toEqual ( 'this_is_the_first_timestampZ' ) ;
48
+ expect ( result [ 0 ] . logMsg ) . toEqual ( 'this is the first log message' ) ;
49
+ expect ( result [ 1 ] . timeStamp ) . toEqual ( '----' ) ;
50
+ expect ( result [ 1 ] . logMsg ) . toEqual ( 'there is no second time stamp but there is a second log message' ) ;
51
+ } ) ;
52
+
53
+ it ( 'when passed empty string, should return {timeStamp: \'\', logMsg: \'\'}' , ( ) => {
54
+
55
+ const result = makeArrayOfObjects ( '' ) ;
56
+
57
+ expect ( result [ 0 ] . timeStamp ) . toEqual ( '' ) ;
58
+ expect ( result [ 0 ] . logMsg ) . toEqual ( '' ) ;
59
+ } ) ;
60
+ } ) ;
0 commit comments