@@ -12,11 +12,16 @@ import {Component} from '@angular/core';
12
12
import { ComponentFixture , TestBed } from '@angular/core/testing' ;
13
13
import { MatButtonModule } from '@angular/material/button' ;
14
14
import { MatButtonHarness } from '@angular/material/button/testing/button-harness' ;
15
- import { benchmark , getButtonWithText } from './testbed-benchmark-utilities ' ;
16
- import { FIRST_BUTTON , MIDDLE_BUTTON , NUM_BUTTONS , LAST_BUTTON } from './constants ' ;
15
+ import { MIDDLE_BUTTON , NUM_BUTTONS } from './constants ' ;
16
+ import { benchmark } from './testbed-benchmark-utilities ' ;
17
17
18
- describe ( 'performance baseline for the testbed harness' , ( ) => {
18
+ describe ( 'performance for the testbed harness environment ' , ( ) => {
19
19
let fixture : ComponentFixture < ButtonHarnessTest > ;
20
+ let loader : HarnessLoader ;
21
+
22
+ beforeAll ( ( ) => {
23
+ jasmine . DEFAULT_TIMEOUT_INTERVAL = 36000000 ;
24
+ } ) ;
20
25
21
26
beforeEach ( async ( ) => {
22
27
await TestBed . configureTestingModule ( {
@@ -26,99 +31,81 @@ describe('performance baseline for the testbed harness', () => {
26
31
27
32
fixture = TestBed . createComponent ( ButtonHarnessTest ) ;
28
33
fixture . detectChanges ( ) ;
34
+ loader = TestbedHarnessEnvironment . loader ( fixture ) ;
29
35
} ) ;
30
36
31
- it ( '(baseline) should retrieve all of the buttons' , async ( ) => {
32
- await benchmark ( '(baseline) get every button' , async ( ) => {
33
- document . querySelectorAll ( 'button' ) ;
37
+ describe ( '(baseline)' , ( ) => {
38
+ it ( 'should find a button' , async ( ) => {
39
+ await benchmark ( '(baseline) find a button' , async ( ) => {
40
+ document . querySelector ( 'button' ) ;
41
+ } ) ;
34
42
} ) ;
35
- } ) ;
36
43
37
- it ( '(baseline) should click the first button ' , async ( ) => {
38
- await benchmark ( '(baseline) click first button ' , async ( ) => {
39
- const button = getButtonWithText ( FIRST_BUTTON ) ;
40
- button . click ( ) ;
44
+ it ( 'should find all buttons ' , async ( ) => {
45
+ await benchmark ( '(baseline) find all buttons ' , async ( ) => {
46
+ document . querySelectorAll ( 'button' ) ;
47
+ } ) ;
41
48
} ) ;
42
- } ) ;
43
49
44
- it ( '(baseline) should click the middle button' , async ( ) => {
45
- await benchmark ( '(baseline) click middle button' , async ( ) => {
46
- const button = getButtonWithText ( MIDDLE_BUTTON ) ;
47
- await button . click ( ) ;
50
+ it ( 'should find a button via text filter' , async ( ) => {
51
+ await benchmark ( '(baseline) find a button via text filter' , async ( ) => {
52
+ return Array . from ( document . querySelectorAll ( 'button' ) )
53
+ . filter ( b => b . innerText === MIDDLE_BUTTON ) ;
54
+ } ) ;
48
55
} ) ;
49
- } ) ;
50
56
51
- it ( '(baseline) should click the last button' , async ( ) => {
52
- await benchmark ( '(baseline) click last button' , async ( ) => {
53
- const button = getButtonWithText ( LAST_BUTTON ) ;
54
- await button . click ( ) ;
57
+ it ( 'should click a button' , async ( ) => {
58
+ const button = document . querySelector ( 'button' ) ! ;
59
+ await benchmark ( '(baseline) click a button' , async ( ) => {
60
+ button . click ( ) ;
61
+ fixture . detectChanges ( ) ;
62
+ } ) ;
55
63
} ) ;
56
- } ) ;
57
64
58
- it ( '(baseline) should click all of the buttons' , async ( ) => {
59
- await benchmark ( '(baseline) click every button' , async ( ) => {
60
- const buttons = document . getElementsByTagName ( 'button' ) ;
61
- for ( let i = 0 ; i < buttons . length ; i ++ ) {
62
- const button = buttons [ i ] ;
63
- await button . click ( ) ;
64
- }
65
+ it ( 'should click all buttons' , async ( ) => {
66
+ const buttons = Array . prototype . slice . call ( document . querySelectorAll ( 'button' ) ) ;
67
+ await benchmark ( '(baseline) click all buttons' , async ( ) => {
68
+ buttons . forEach ( button => button . click ( ) ) ;
69
+ fixture . detectChanges ( ) ;
70
+ } ) ;
65
71
} ) ;
66
72
} ) ;
67
- } ) ;
68
-
69
- describe ( 'performance tests for the testbed harness' , ( ) => {
70
- let fixture : ComponentFixture < ButtonHarnessTest > ;
71
- let loader : HarnessLoader ;
72
-
73
- beforeEach ( async ( ) => {
74
- await TestBed . configureTestingModule ( {
75
- imports : [ MatButtonModule ] ,
76
- declarations : [ ButtonHarnessTest ] ,
77
- } ) . compileComponents ( ) ;
78
-
79
- fixture = TestBed . createComponent ( ButtonHarnessTest ) ;
80
- fixture . detectChanges ( ) ;
81
- loader = TestbedHarnessEnvironment . loader ( fixture ) ;
82
- } ) ;
83
73
84
- it ( 'should retrieve all of the buttons' , async ( ) => {
85
- await benchmark ( 'get every button' , async ( ) => {
86
- await loader . getAllHarnesses ( MatButtonHarness ) ;
74
+ describe ( '(with harness)' , ( ) => {
75
+ it ( 'should find a button' , async ( ) => {
76
+ await benchmark ( '(with harness) find a button' , async ( ) => {
77
+ await loader . getHarness ( MatButtonHarness ) ;
78
+ } ) ;
87
79
} ) ;
88
- } ) ;
89
80
90
- it ( 'should click the first button ' , async ( ) => {
91
- await benchmark ( 'click first button ' , async ( ) => {
92
- const button = await loader . getHarness ( MatButtonHarness . with ( { text : FIRST_BUTTON } ) ) ;
93
- await button . click ( ) ;
81
+ it ( 'should find all buttons ' , async ( ) => {
82
+ await benchmark ( '(with harness) find all buttons ' , async ( ) => {
83
+ await loader . getAllHarnesses ( MatButtonHarness ) ;
84
+ } ) ;
94
85
} ) ;
95
- } ) ;
96
86
97
- it ( 'should click the middle button' , async ( ) => {
98
- await benchmark ( 'click middle button' , async ( ) => {
99
- const button = await loader . getHarness ( MatButtonHarness . with ( { text : MIDDLE_BUTTON } ) ) ;
100
- await button . click ( ) ;
87
+ it ( 'should find a button via text filter ' , async ( ) => {
88
+ await benchmark ( '(with harness) find a button via text filter ' , async ( ) => {
89
+ await loader . getAllHarnesses ( MatButtonHarness . with ( { text : MIDDLE_BUTTON } ) ) ;
90
+ } ) ;
101
91
} ) ;
102
- } ) ;
103
92
104
- it ( 'should click the last button' , async ( ) => {
105
- await benchmark ( 'click last button' , async ( ) => {
106
- const button = await loader . getHarness ( MatButtonHarness . with ( { text : LAST_BUTTON } ) ) ;
107
- await button . click ( ) ;
93
+ it ( 'should click a button' , async ( ) => {
94
+ const button = await loader . getHarness ( MatButtonHarness ) ;
95
+ await benchmark ( '(with harness) click a button' , async ( ) => {
96
+ await button . click ( ) ;
97
+ } ) ;
108
98
} ) ;
109
- } ) ;
110
99
111
- it ( 'should click all of the buttons' , async ( ) => {
112
- await benchmark ( 'click every button' , async ( ) => {
100
+ it ( 'should click all buttons' , async ( ) => {
113
101
const buttons = await loader . getAllHarnesses ( MatButtonHarness ) ;
114
- for ( let i = 0 ; i < buttons . length ; i ++ ) {
115
- const button = buttons [ i ] ;
116
- await button . click ( ) ;
117
- }
102
+ await benchmark ( '(with harness) click all buttons' , async ( ) => {
103
+ await Promise . all ( buttons . map ( button => button . click ( ) ) ) ;
104
+ } ) ;
118
105
} ) ;
119
106
} ) ;
120
107
121
- it ( 'should fail intentionally' , ( ) => expect ( 1 ) . toBe ( 2 ) ) ;
108
+ it ( 'should fail intentionally so performance numbers are logged' , fail ) ;
122
109
} ) ;
123
110
124
111
@Component ( {
@@ -127,5 +114,5 @@ describe('performance tests for the testbed harness', () => {
127
114
` ,
128
115
} )
129
116
export class ButtonHarnessTest {
130
- vals = Array . from ( { length : NUM_BUTTONS } , ( _ , i ) => i ) ;
117
+ vals = Array . from ( { length : NUM_BUTTONS } , ( _ , i ) => i ) ;
131
118
}
0 commit comments