|
24 | 24 | */ |
25 | 25 | import { |
26 | 26 | SyntheticsGenerator, |
27 | | - ActionInContext, |
| 27 | + Step, |
| 28 | + Steps, |
28 | 29 | } from '../../src/formatter/javascript'; |
29 | 30 |
|
30 | | -const recorderActions: Array<ActionInContext> = [ |
31 | | - { |
32 | | - pageAlias: 'page', |
33 | | - isMainFrame: true, |
34 | | - frameUrl: 'about:blank', |
35 | | - committed: true, |
36 | | - action: { |
37 | | - name: 'openPage', |
38 | | - url: 'about:blank', |
39 | | - signals: [], |
| 31 | +const recorderStep: Step = { |
| 32 | + actions: [ |
| 33 | + { |
| 34 | + pageAlias: 'page', |
| 35 | + isMainFrame: true, |
| 36 | + frameUrl: 'about:blank', |
| 37 | + committed: true, |
| 38 | + action: { |
| 39 | + name: 'openPage', |
| 40 | + url: 'about:blank', |
| 41 | + signals: [], |
| 42 | + }, |
40 | 43 | }, |
41 | | - }, |
42 | | - { |
43 | | - pageAlias: 'page', |
44 | | - isMainFrame: true, |
45 | | - frameUrl: 'https://vigneshh.in/', |
46 | | - committed: true, |
47 | | - action: { |
48 | | - name: 'navigate', |
49 | | - url: 'https://vigneshh.in/', |
50 | | - signals: [], |
| 44 | + { |
| 45 | + pageAlias: 'page', |
| 46 | + isMainFrame: true, |
| 47 | + frameUrl: 'https://vigneshh.in/', |
| 48 | + committed: true, |
| 49 | + action: { |
| 50 | + name: 'navigate', |
| 51 | + url: 'https://vigneshh.in/', |
| 52 | + signals: [], |
| 53 | + }, |
51 | 54 | }, |
52 | | - }, |
53 | | - { |
54 | | - pageAlias: 'page', |
55 | | - isMainFrame: true, |
56 | | - frameUrl: 'https://vigneshh.in/', |
57 | | - action: { |
58 | | - name: 'assert', |
59 | | - isAssert: true, |
60 | | - command: 'isVisible', |
61 | | - selector: 'text=Babel Minify', |
62 | | - signals: [], |
| 55 | + { |
| 56 | + pageAlias: 'page', |
| 57 | + isMainFrame: true, |
| 58 | + frameUrl: 'https://vigneshh.in/', |
| 59 | + action: { |
| 60 | + name: 'assert', |
| 61 | + isAssert: true, |
| 62 | + command: 'isVisible', |
| 63 | + selector: 'text=Babel Minify', |
| 64 | + signals: [], |
| 65 | + }, |
63 | 66 | }, |
64 | | - }, |
65 | | - { |
66 | | - pageAlias: 'page', |
67 | | - isMainFrame: true, |
68 | | - frameUrl: 'https://vigneshh.in/', |
69 | | - action: { |
70 | | - name: 'assert', |
71 | | - isAssert: true, |
72 | | - command: 'isEditable', |
73 | | - selector: 'text=Babel Minify', |
74 | | - signals: [], |
| 67 | + { |
| 68 | + pageAlias: 'page', |
| 69 | + isMainFrame: true, |
| 70 | + frameUrl: 'https://vigneshh.in/', |
| 71 | + action: { |
| 72 | + name: 'assert', |
| 73 | + isAssert: true, |
| 74 | + command: 'isEditable', |
| 75 | + selector: 'text=Babel Minify', |
| 76 | + signals: [], |
| 77 | + }, |
75 | 78 | }, |
76 | | - }, |
77 | | - { |
78 | | - pageAlias: 'page', |
79 | | - isMainFrame: true, |
80 | | - frameUrl: 'https://vigneshh.in/', |
81 | | - action: { |
82 | | - name: 'assert', |
83 | | - isAssert: true, |
84 | | - command: 'textContent', |
85 | | - selector: 'text=Babel Minify', |
86 | | - value: 'Babel', |
87 | | - signals: [], |
| 79 | + { |
| 80 | + pageAlias: 'page', |
| 81 | + isMainFrame: true, |
| 82 | + frameUrl: 'https://vigneshh.in/', |
| 83 | + action: { |
| 84 | + name: 'assert', |
| 85 | + isAssert: true, |
| 86 | + command: 'textContent', |
| 87 | + selector: 'text=Babel Minify', |
| 88 | + value: 'Babel', |
| 89 | + signals: [], |
| 90 | + }, |
88 | 91 | }, |
89 | | - }, |
90 | | - { |
91 | | - pageAlias: 'page', |
92 | | - isMainFrame: true, |
93 | | - frameUrl: 'https://vigneshh.in/', |
94 | | - action: { |
95 | | - name: 'click', |
96 | | - selector: 'text=Babel Minify', |
97 | | - signals: [ |
98 | | - { |
99 | | - name: 'popup', |
100 | | - popupAlias: 'page1', |
101 | | - isAsync: true, |
102 | | - }, |
103 | | - ], |
104 | | - button: 'left', |
105 | | - modifiers: 0, |
106 | | - clickCount: 1, |
| 92 | + { |
| 93 | + pageAlias: 'page', |
| 94 | + isMainFrame: true, |
| 95 | + frameUrl: 'https://vigneshh.in/', |
| 96 | + action: { |
| 97 | + name: 'click', |
| 98 | + selector: 'text=Babel Minify', |
| 99 | + signals: [ |
| 100 | + { |
| 101 | + name: 'popup', |
| 102 | + popupAlias: 'page1', |
| 103 | + isAsync: true, |
| 104 | + }, |
| 105 | + ], |
| 106 | + button: 'left', |
| 107 | + modifiers: 0, |
| 108 | + clickCount: 1, |
| 109 | + }, |
| 110 | + committed: true, |
107 | 111 | }, |
108 | | - committed: true, |
109 | | - }, |
110 | | - { |
111 | | - pageAlias: 'page1', |
112 | | - isMainFrame: true, |
113 | | - frameUrl: 'https://github.com/babel/minify', |
114 | | - action: { |
115 | | - name: 'click', |
116 | | - selector: 'a:has-text("smoke")', |
117 | | - signals: [ |
118 | | - { |
119 | | - name: 'navigation', |
120 | | - url: 'https://github.com/babel/minify', |
121 | | - }, |
122 | | - { |
123 | | - name: 'navigation', |
124 | | - url: 'https://github.com/babel/minify/tree/master/smoke', |
125 | | - }, |
126 | | - { |
127 | | - name: 'navigation', |
128 | | - url: 'https://github.com/babel/minify/tree/master/smoke', |
129 | | - isAsync: true, |
130 | | - }, |
131 | | - { |
132 | | - name: 'navigation', |
133 | | - url: 'https://github.com/babel/minify', |
134 | | - isAsync: true, |
135 | | - }, |
136 | | - ], |
137 | | - button: 'left', |
138 | | - modifiers: 0, |
139 | | - clickCount: 1, |
| 112 | + { |
| 113 | + pageAlias: 'page1', |
| 114 | + isMainFrame: true, |
| 115 | + frameUrl: 'https://github.com/babel/minify', |
| 116 | + action: { |
| 117 | + name: 'click', |
| 118 | + selector: 'a:has-text("smoke")', |
| 119 | + signals: [ |
| 120 | + { |
| 121 | + name: 'navigation', |
| 122 | + url: 'https://github.com/babel/minify', |
| 123 | + }, |
| 124 | + { |
| 125 | + name: 'navigation', |
| 126 | + url: 'https://github.com/babel/minify/tree/master/smoke', |
| 127 | + }, |
| 128 | + { |
| 129 | + name: 'navigation', |
| 130 | + url: 'https://github.com/babel/minify/tree/master/smoke', |
| 131 | + isAsync: true, |
| 132 | + }, |
| 133 | + { |
| 134 | + name: 'navigation', |
| 135 | + url: 'https://github.com/babel/minify', |
| 136 | + isAsync: true, |
| 137 | + }, |
| 138 | + ], |
| 139 | + button: 'left', |
| 140 | + modifiers: 0, |
| 141 | + clickCount: 1, |
| 142 | + }, |
140 | 143 | }, |
141 | | - }, |
142 | | - { |
143 | | - pageAlias: 'page1', |
144 | | - isMainFrame: true, |
145 | | - frameUrl: 'https://github.com/babel/minify', |
146 | | - committed: true, |
147 | | - action: { |
148 | | - name: 'closePage', |
149 | | - signals: [], |
| 144 | + { |
| 145 | + pageAlias: 'page1', |
| 146 | + isMainFrame: true, |
| 147 | + frameUrl: 'https://github.com/babel/minify', |
| 148 | + committed: true, |
| 149 | + action: { |
| 150 | + name: 'closePage', |
| 151 | + signals: [], |
| 152 | + }, |
150 | 153 | }, |
151 | | - }, |
152 | | - { |
153 | | - pageAlias: 'page', |
154 | | - isMainFrame: true, |
155 | | - frameUrl: 'https://vigneshh.in/', |
156 | | - committed: true, |
157 | | - action: { |
158 | | - name: 'closePage', |
159 | | - signals: [], |
| 154 | + { |
| 155 | + pageAlias: 'page', |
| 156 | + isMainFrame: true, |
| 157 | + frameUrl: 'https://vigneshh.in/', |
| 158 | + committed: true, |
| 159 | + action: { |
| 160 | + name: 'closePage', |
| 161 | + signals: [], |
| 162 | + }, |
160 | 163 | }, |
161 | | - }, |
162 | | -]; |
| 164 | + ], |
| 165 | +}; |
163 | 166 |
|
164 | 167 | describe('Synthetics JavaScript formatter', () => { |
165 | | - it('inline journeys', async () => { |
166 | | - const formatter = new SyntheticsGenerator(false); |
167 | | - expect(formatter.generateText(recorderActions)).toMatchSnapshot(); |
| 168 | + it('accepts custom step organization', () => { |
| 169 | + const generator = new SyntheticsGenerator(true); |
| 170 | + const testSteps: Steps = [ |
| 171 | + { actions: recorderStep.actions.slice(0, 2) }, |
| 172 | + { actions: recorderStep.actions.slice(2, 4) }, |
| 173 | + { actions: recorderStep.actions.slice(4, 7) }, |
| 174 | + { actions: recorderStep.actions.slice(7, 9) }, |
| 175 | + ]; |
| 176 | + expect(generator.generateFromSteps(testSteps)).toMatchSnapshot(); |
168 | 177 | }); |
169 | 178 |
|
170 | | - it('suite journeys', async () => { |
171 | | - const formatter = new SyntheticsGenerator(true); |
172 | | - expect(formatter.generateText(recorderActions)).toMatchSnapshot(); |
| 179 | + it('uses custom step names', () => { |
| 180 | + const generator = new SyntheticsGenerator(false); |
| 181 | + const testSteps: Steps = [{ actions: recorderStep.actions.slice(0, 4) }]; |
| 182 | + expect( |
| 183 | + generator.generateFromSteps( |
| 184 | + testSteps.map((s: Step) => { |
| 185 | + s.name = 'test-name'; |
| 186 | + return s; |
| 187 | + }) |
| 188 | + ) |
| 189 | + ).toMatchSnapshot(); |
173 | 190 | }); |
174 | 191 |
|
175 | | - it('use modified title if available', async () => { |
176 | | - const formatter = new SyntheticsGenerator(false); |
177 | | - const actions = [ |
178 | | - { |
179 | | - ...recorderActions[1], |
180 | | - title: 'Visiting profile', |
181 | | - }, |
182 | | - ]; |
183 | | - expect(formatter.generateText(actions)).toMatchSnapshot(); |
| 192 | + it('throws error if processing empty step', () => { |
| 193 | + const generator = new SyntheticsGenerator(false); |
| 194 | + const testSteps: Steps = [{ actions: [] }]; |
| 195 | + expect(() => generator.generateFromSteps(testSteps)).toThrowError( |
| 196 | + 'Cannot process an empty step' |
| 197 | + ); |
184 | 198 | }); |
185 | 199 | }); |
0 commit comments