@@ -8,7 +8,7 @@ var Test = new function(){
8
8
this . importedPages = [ ] ;
9
9
this . unsavedChanges = false ;
10
10
11
- this . initialize = function ( file , importedPages , setupSteps , teardownSteps , testFunctions ) {
11
+ this . initialize = function ( file , importedPages , testHooks , testFunctions ) {
12
12
13
13
this . file = file ;
14
14
@@ -18,15 +18,12 @@ var Test = new function(){
18
18
} ) ;
19
19
Test . getAllProjectPages ( ) ;
20
20
Test . getGolemActions ( ) ;
21
- Test . renderSectionSteps ( Test . Utils . stepSection ( 'setup' ) , setupSteps ) ;
22
- Test . renderSectionSteps ( Test . Utils . stepSection ( 'teardown' ) , teardownSteps ) ;
21
+ Test . addTestHooks ( testHooks ) ;
23
22
Test . addTestFunctions ( testFunctions ) ;
24
23
Test . refreshActionInputsAutocomplete ( ) ;
25
24
Test . refreshValueInputsAutocomplete ( ) ;
26
- $ ( '#pageModal' ) . on ( 'hidden.bs.modal' , function ( ) {
27
- Test . importedPages . forEach ( function ( page ) {
28
- Test . getPageContents ( page . name )
29
- } )
25
+ $ ( '#pageModal' ) . on ( 'hidden.bs.modal' , function ( ) {
26
+ Test . importedPages . forEach ( ( page ) => Test . getPageContents ( page . name ) )
30
27
} ) ;
31
28
Test . Utils . watchForUnsavedChanges ( ) ;
32
29
Test . Utils . startSortableSteps ( ) ;
@@ -47,38 +44,60 @@ var Test = new function(){
47
44
}
48
45
}
49
46
50
- this . addTestFunction = function ( testName , testSteps ) {
51
- testSteps = testSteps || [ ] ;
52
- let testFunctionContainer = $ ( '#testFunctions' ) ;
47
+ this . addTestFunction = function ( functionName , steps ) {
48
+ this . addXFunction ( functionName , steps , $ ( '#testFunctions' ) , true ) ;
49
+ }
50
+
51
+ this . addTestHooks = function ( testHooks ) {
52
+ let orderedTestHooks = Test . Hooks . orderTestHooks ( testHooks ) ;
53
+
54
+ for ( const testHook in orderedTestHooks ) {
55
+ Test . addTestHook ( testHook , testHooks [ testHook ] ) ;
56
+ }
57
+ }
58
+
59
+ this . addTestHook = function ( hookName , steps ) {
60
+ Test . Hooks . addHook ( hookName , steps ) ;
61
+ }
62
+
63
+ this . addXFunction = function ( functionName , testSteps , container , isTestFunction ) {
64
+ // only test functions have on click to modify test function name
65
+ // test hooks names cannot be modified
66
+ if ( isTestFunction ) {
67
+ functionNameOnClick = 'Test.Utils.startTestFunctionInlineNameEdition(this)' ;
68
+ removeIconOnClick = 'Test.Utils.deleteTestFunction(this)' ;
69
+ } else {
70
+ functionNameOnClick = '' ;
71
+ removeIconOnClick = 'Test.Hooks.deleteHook(this)' ;
72
+ }
73
+
53
74
let testFunctionTemplate = $ ( `
54
75
<div class='test-function function'>
55
76
<div class='testFunctionNameContainer'>
56
77
<h4 class="testFunctionNameContainer">
57
- <span class="test-function-name" onclick="Test.Utils.startTestFunctionInlineNameEdition(this) ">${ testName } </span>
78
+ <span class="test-function-name" onclick="${ functionNameOnClick } ">${ functionName } </span>
58
79
<span class="test-function-name-input" style="display: none">
59
80
<input type="text">
60
81
</span>
61
82
</h4>
62
83
<div class="inline-remove-icon">
63
- <a href="javascript:void(0)" onclick="Test.Utils.deleteTestFunction(this) ">
84
+ <a href="javascript:void(0)" onclick="${ removeIconOnClick } ">
64
85
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
65
86
</a>
66
87
</div>
67
88
</div>
68
89
<div class='steps'></div>
69
90
<button class='btn btn-default btn-sm add-step' style='margin-left: 21px;' onclick="Test.addStepInputToThis(this);">
70
91
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span></button>
71
- </div>
72
- <div style='height: 10px'></div>
73
- ` ) ;
92
+ </div>` ) ;
74
93
75
94
let stepContainer = testFunctionTemplate . find ( '.steps' ) ;
76
95
if ( testSteps . length ) {
77
96
Test . renderSectionSteps ( stepContainer , testSteps ) ;
78
97
} else {
79
98
Test . addStepInputToThis ( stepContainer ) ;
80
99
}
81
- testFunctionContainer . append ( testFunctionTemplate ) ;
100
+ container . append ( testFunctionTemplate ) ;
82
101
Test . refreshActionInputsAutocomplete ( ) ;
83
102
Test . refreshValueInputsAutocomplete ( ) ;
84
103
}
@@ -133,7 +152,7 @@ var Test = new function(){
133
152
134
153
this . addNewTestFunction = function ( ) {
135
154
let callback = ( testName ) => {
136
- Test . addTestFunction ( testName )
155
+ Test . addTestFunction ( testName , [ ] )
137
156
}
138
157
let validationCallback = ( testName ) => {
139
158
return Test . Utils . validateTestFunctionName ( testName ) ;
@@ -299,7 +318,7 @@ var Test = new function(){
299
318
Main . TestRunner . runTest ( this . file . project , Test . file . fullName ) ;
300
319
}
301
320
302
- this . save = function ( config ) {
321
+ this . save = function ( config ) {
303
322
runAfter = config . runAfter || false ;
304
323
let description = $ ( "#description" ) . val ( ) ;
305
324
let pageObjects = Test . importedPages . map ( x => x . name ) ;
@@ -480,10 +499,38 @@ var Test = new function(){
480
499
return template
481
500
}
482
501
502
+ this . Hooks = new function ( ) {
483
503
484
- this . Utils = new function ( ) {
504
+ this . orderTestHooks = function ( hooks ) {
505
+ ordered = { }
506
+ orderList = [ 'before_test' , 'setup' , 'before_each' , 'after_each' , 'after_test' , 'teardown' ]
507
+ for ( hookName of orderList ) {
508
+ if ( hookName in hooks ) {
509
+ ordered [ hookName ] = hooks [ hookName ]
510
+ }
511
+ }
512
+ return ordered
513
+ }
485
514
486
- this . getNotImportedPages = function ( ) {
515
+ this . addHook = function ( name , steps ) {
516
+ steps = steps || [ ] ;
517
+ Test . addXFunction ( name , steps , $ ( '#testHooks' ) , false ) ;
518
+ $ ( `#hookSelector a[hook-name='${ name } ']` ) . hide ( ) ;
519
+ }
520
+
521
+ this . deleteHook = function ( elem ) {
522
+ let hookName = $ ( elem ) . closest ( '.test-function' ) . find ( 'h4 span' ) . html ( ) ;
523
+ Main . Utils . displayConfirmModal ( 'Delete Test Hook?' , '' , ( ) => {
524
+ $ ( elem ) . closest ( '.test-function' ) . remove ( ) ;
525
+ Test . unsavedChanges = true ;
526
+ $ ( `#hookSelector a[hook-name='${ hookName } ']` ) . show ( ) ;
527
+ } ) ;
528
+ }
529
+ }
530
+
531
+ this . Utils = new function ( ) {
532
+
533
+ this . getNotImportedPages = function ( ) {
487
534
let notImported = [ ] ;
488
535
let importedPagesNames = Test . importedPages . map ( x => x . name ) ;
489
536
Test . allPages . forEach ( function ( page ) {
@@ -593,10 +640,13 @@ var Test = new function(){
593
640
594
641
this . getSteps = function ( ) {
595
642
let steps = {
596
- setup : Test . Utils . parseSteps ( $ ( "#setupSteps .step" ) ) ,
643
+ hooks : { } ,
597
644
tests : { } ,
598
- teardown : Test . Utils . parseSteps ( $ ( "#teardownSteps .step" ) )
599
645
}
646
+ $ ( '#testHooks > .test-function' ) . each ( function ( ) {
647
+ let hookName = $ ( this ) . find ( 'span.test-function-name' ) . html ( ) . trim ( ) ;
648
+ steps . hooks [ hookName ] = Test . Utils . parseSteps ( $ ( this ) . find ( '.step' ) )
649
+ } )
600
650
$ ( '#testFunctions > .test-function' ) . each ( function ( ) {
601
651
let testName = $ ( this ) . find ( 'span.test-function-name' ) . html ( ) . trim ( ) ;
602
652
steps . tests [ testName ] = Test . Utils . parseSteps ( $ ( this ) . find ( '.step' ) )
@@ -659,7 +709,7 @@ var Test = new function(){
659
709
}
660
710
661
711
this . deleteTestFunction = function ( elem ) {
662
- Main . Utils . displayConfirmModal ( 'Delete Test' , 'Delete test? ' , ( ) => {
712
+ Main . Utils . displayConfirmModal ( 'Delete Test? ' , '' , ( ) => {
663
713
$ ( elem ) . closest ( '.test-function' ) . remove ( ) ;
664
714
Test . unsavedChanges = true ;
665
715
} ) ;
0 commit comments