'custom-configuration-test-group-form' should update test name when selected test...
[WebKit.git] / Websites / perf.webkit.org / browser-tests / custom-analysis-task-configurator-tests.js
1 describe('CustomAnalysisTaskConfigurator', () => {
2     const scripts = ['instrumentation.js', '../shared/common-component-base.js', 'components/base.js', 'models/data-model.js', 'models/commit-log.js',
3         'models/commit-set.js', 'models/repository.js', 'models/metric.js', 'models/triggerable.js', 'models/test.js', 'models/platform.js', 'components/test-group-form.js',
4         'components/custom-analysis-task-configurator.js', 'components/instant-file-uploader.js', 'lazily-evaluated-function.js'];
5
6     async function createCustomAnalysisTaskConfiguratorWithContext(context)
7     {
8         await context.importScripts(scripts, 'ComponentBase', 'DataModelObject', 'Repository', 'CommitLog', 'Platform', 'Test', 'Metric', 'Triggerable',
9             'TriggerableRepositoryGroup', 'CustomCommitSet', 'CustomAnalysisTaskConfigurator', 'MockRemoteAPI', 'LazilyEvaluatedFunction');
10         const customAnalysisTaskConfigurator = new context.symbols.CustomAnalysisTaskConfigurator;
11         context.document.body.appendChild(customAnalysisTaskConfigurator.element());
12         return customAnalysisTaskConfigurator;
13     }
14
15     async function sleep(timeout)
16     {
17         await new Promise((resolve) => setTimeout(() => resolve(), timeout));
18     }
19
20     it('Should be able to schedule A/B test even fetching commit information never returns', async () => {
21         const context = new BrowsingContext();
22         const customAnalysisTaskConfigurator = await createCustomAnalysisTaskConfiguratorWithContext(context);
23         context.symbols.CustomAnalysisTaskConfigurator.commitFetchInterval = 1;
24
25         const test = new context.symbols.Test(1, {name: 'Speedometer'});
26         const platform = new context.symbols.Platform(1, {
27             name: 'Mojave',
28             metrics: [
29                 new context.symbols.Metric(1, {
30                     name: 'Allocation',
31                     aggregator: 'Arithmetic',
32                     test
33                 })
34             ],
35             lastModifiedByMetric: Date.now(),
36         });
37         const repository = context.symbols.Repository.ensureSingleton(1, {name: 'WebKit'});
38         const triggerableRepositoryGroup = new context.symbols.TriggerableRepositoryGroup(1, {repositories: [{repository}]});
39         new context.symbols.Triggerable(1, {
40             name: 'test-triggerable',
41             isDisabled: false,
42             repositoryGroups: [triggerableRepositoryGroup],
43             configurations: [{test, platform}],
44         });
45         customAnalysisTaskConfigurator.selectTests([test]);
46         customAnalysisTaskConfigurator.selectPlatform(platform);
47
48         await waitForComponentsToRender(context);
49
50         const requests = context.symbols.MockRemoteAPI.requests;
51         expect(requests.length).to.be(1);
52         expect(requests[0].url).to.be('/api/commits/1/latest?platform=1');
53         requests[0].reject();
54
55         customAnalysisTaskConfigurator.content('baseline-revision-table').querySelector('input').value = '123';
56         customAnalysisTaskConfigurator.content('baseline-revision-table').querySelector('input').dispatchEvent(new Event('input'));
57         await sleep(context.symbols.CustomAnalysisTaskConfigurator.commitFetchInterval);
58         expect(requests.length).to.be(2);
59         expect(requests[1].url).to.be('/api/commits/1/123');
60
61         customAnalysisTaskConfigurator._configureComparison();
62         await waitForComponentsToRender(context);
63
64         customAnalysisTaskConfigurator.content('comparison-revision-table').querySelector('input').value = '456';
65         customAnalysisTaskConfigurator.content('comparison-revision-table').querySelector('input').dispatchEvent(new Event('input'));
66         await sleep(context.symbols.CustomAnalysisTaskConfigurator.commitFetchInterval);
67         expect(requests.length).to.be(3);
68         expect(requests[2].url).to.be('/api/commits/1/456');
69
70         const commitSets = customAnalysisTaskConfigurator.commitSets();
71         expect(commitSets.length).to.be(2);
72         expect(commitSets[0].repositories().length).to.be(1);
73         expect(commitSets[0].revisionForRepository(repository)).to.be('123');
74         expect(commitSets[1].repositories().length).to.be(1);
75         expect(commitSets[1].revisionForRepository(repository)).to.be('456');
76
77         context.symbols.CustomAnalysisTaskConfigurator.commitFetchInterval = 100;
78     });
79
80     it('Should not update commitSetMap if baseline is set and unmodified but comparison is null', async () => {
81         const context = new BrowsingContext();
82         const customAnalysisTaskConfigurator = await createCustomAnalysisTaskConfiguratorWithContext(context);
83
84         await waitForComponentsToRender(context);
85         const repository = context.symbols.Repository.ensureSingleton(1, {name: 'WebKit'});
86         const commitSet = new context.symbols.CustomCommitSet;
87         commitSet.setRevisionForRepository(repository, '210948', null);
88         customAnalysisTaskConfigurator._commitSetMap = {'Baseline': commitSet, 'Comparison': null};
89         customAnalysisTaskConfigurator._repositoryGroupByConfiguration['Baseline'] = new context.symbols.TriggerableRepositoryGroup(1, {repositories: [{repository}]});
90         customAnalysisTaskConfigurator._specifiedRevisions['Baseline'].set(repository, '210948');
91
92         const originalCommitSet = customAnalysisTaskConfigurator._commitSetMap;
93         await customAnalysisTaskConfigurator._updateCommitSetMap();
94
95         expect(customAnalysisTaskConfigurator._commitSetMap).to.be(originalCommitSet);
96     });
97
98     it('Should preserve user specified revision if user has ever modified the revision', async () => {
99         const context = new BrowsingContext();
100         const customAnalysisTaskConfigurator = await createCustomAnalysisTaskConfiguratorWithContext(context);
101         context.symbols.CustomAnalysisTaskConfigurator.commitFetchInterval = 1;
102
103         const test = new context.symbols.Test(1, {name: 'Speedometer'});
104         const mojave = new context.symbols.Platform(1, {
105             name: 'Mojave',
106             metrics: [
107                 new context.symbols.Metric(1, {
108                     name: 'Allocation',
109                     aggregator: 'Arithmetic',
110                     test
111                 })
112             ],
113             lastModifiedByMetric: Date.now(),
114         });
115         const highSierra = new context.symbols.Platform(2, {
116             name: 'High Sierra',
117             metrics: [
118                 new context.symbols.Metric(1, {
119                     name: 'Allocation',
120                     aggregator: 'Arithmetic',
121                     test
122                 })
123             ],
124             lastModifiedByMetric: Date.now(),
125         });
126         const repository = context.symbols.Repository.ensureSingleton(1, {name: 'WebKit'});
127         const triggerableRepositoryGroup = new context.symbols.TriggerableRepositoryGroup(1, {repositories: [{repository}]});
128         new context.symbols.Triggerable(1, {
129             name: 'test-triggerable',
130             isDisabled: false,
131             repositoryGroups: [triggerableRepositoryGroup],
132             configurations: [{test, platform: mojave}, {test, platform: highSierra}],
133         });
134         customAnalysisTaskConfigurator.selectTests([test]);
135         customAnalysisTaskConfigurator.selectPlatform(mojave);
136
137         await waitForComponentsToRender(context);
138
139         const requests = context.symbols.MockRemoteAPI.requests;
140         expect(requests.length).to.be(1);
141         expect(requests[0].url).to.be('/api/commits/1/latest?platform=1');
142         requests[0].reject();
143
144         customAnalysisTaskConfigurator.content('baseline-revision-table').querySelector('input').value = '123';
145         customAnalysisTaskConfigurator.content('baseline-revision-table').querySelector('input').dispatchEvent(new Event('input'));
146         await sleep(context.symbols.CustomAnalysisTaskConfigurator.commitFetchInterval);
147         expect(requests.length).to.be(2);
148         expect(requests[1].url).to.be('/api/commits/1/123');
149
150         customAnalysisTaskConfigurator._configureComparison();
151         await waitForComponentsToRender(context);
152
153         customAnalysisTaskConfigurator.content('comparison-revision-table').querySelector('input').value = '456';
154         customAnalysisTaskConfigurator.content('comparison-revision-table').querySelector('input').dispatchEvent(new Event('input'));
155         await sleep(context.symbols.CustomAnalysisTaskConfigurator.commitFetchInterval);
156         expect(requests.length).to.be(3);
157         expect(requests[2].url).to.be('/api/commits/1/456');
158
159         let commitSets = customAnalysisTaskConfigurator.commitSets();
160         expect(commitSets.length).to.be(2);
161         expect(commitSets[0].repositories().length).to.be(1);
162         expect(commitSets[0].revisionForRepository(repository)).to.be('123');
163         expect(commitSets[1].repositories().length).to.be(1);
164         expect(commitSets[1].revisionForRepository(repository)).to.be('456');
165
166         customAnalysisTaskConfigurator.selectPlatform(highSierra);
167         await waitForComponentsToRender(context);
168
169         commitSets = customAnalysisTaskConfigurator.commitSets();
170         expect(commitSets.length).to.be(2);
171         expect(commitSets[0].repositories().length).to.be(1);
172         expect(commitSets[0].revisionForRepository(repository)).to.be('123');
173         expect(commitSets[1].repositories().length).to.be(1);
174         expect(commitSets[1].revisionForRepository(repository)).to.be('456');
175         context.symbols.CustomAnalysisTaskConfigurator.commitFetchInterval = 100;
176     });
177
178     it('Should reset commit set if user has never modified the revision', async () => {
179         const context = new BrowsingContext();
180         const customAnalysisTaskConfigurator = await createCustomAnalysisTaskConfiguratorWithContext(context);
181
182         const test = new context.symbols.Test(1, {name: 'Speedometer'});
183         const mojave = new context.symbols.Platform(1, {
184             name: 'Mojave',
185             metrics: [
186                 new context.symbols.Metric(1, {
187                     name: 'Allocation',
188                     aggregator: 'Arithmetic',
189                     test
190                 })
191             ],
192             lastModifiedByMetric: Date.now(),
193         });
194         const highSierra = new context.symbols.Platform(2, {
195             name: 'High Sierra',
196             metrics: [
197                 new context.symbols.Metric(1, {
198                     name: 'Allocation',
199                     aggregator: 'Arithmetic',
200                     test
201                 })
202             ],
203             lastModifiedByMetric: Date.now(),
204         });
205         const repository = context.symbols.Repository.ensureSingleton(1, {name: 'WebKit'});
206         const triggerableRepositoryGroup = new context.symbols.TriggerableRepositoryGroup(1, {name: 'test-triggerable', repositories: [{repository}]});
207         new context.symbols.Triggerable(1, {
208             name: 'test-triggerable',
209             isDisabled: false,
210             repositoryGroups: [triggerableRepositoryGroup],
211             configurations: [{test, platform: mojave}, {test, platform: highSierra}],
212         });
213         customAnalysisTaskConfigurator.selectTests([test]);
214         customAnalysisTaskConfigurator.selectPlatform(mojave);
215         await waitForComponentsToRender(context);
216
217         const requests = context.symbols.MockRemoteAPI.requests;
218         expect(requests.length).to.be(1);
219         expect(requests[0].url).to.be('/api/commits/1/latest?platform=1');
220         requests[0].resolve({commits: [{
221             id: 1,
222             revision: '123',
223             repository: repository.id(),
224             time: Date.now(),
225         }]});
226         await waitForComponentsToRender(context);
227
228         expect(customAnalysisTaskConfigurator.content('baseline-revision-table').querySelector('input').value).to.be('123');
229         customAnalysisTaskConfigurator.selectPlatform(highSierra);
230
231         await waitForComponentsToRender(context);
232         expect(customAnalysisTaskConfigurator.content('baseline-revision-table').querySelector('input').value).to.be('');
233     });
234
235     it('Should dispatch "testConfigChange" action when selected platform changed', async () => {
236         const context = new BrowsingContext();
237         const customAnalysisTaskConfigurator = await createCustomAnalysisTaskConfiguratorWithContext(context);
238         let testConfigChangeActionCount = 0;
239         context.symbols.CustomAnalysisTaskConfigurator.commitFetchInterval = 1;
240
241         customAnalysisTaskConfigurator.listenToAction("testConfigChange", () => testConfigChangeActionCount += 1);
242
243         const test = new context.symbols.Test(1, {name: 'Speedometer'});
244         const mojave = new context.symbols.Platform(1, {
245             name: 'Mojave',
246             metrics: [
247                 new context.symbols.Metric(1, {
248                     name: 'Allocation',
249                     aggregator: 'Arithmetic',
250                     test
251                 })
252             ],
253             lastModifiedByMetric: Date.now(),
254         });
255         const highSierra = new context.symbols.Platform(2, {
256             name: 'High Sierra',
257             metrics: [
258                 new context.symbols.Metric(1, {
259                     name: 'Allocation',
260                     aggregator: 'Arithmetic',
261                     test
262                 })
263             ],
264             lastModifiedByMetric: Date.now(),
265         });
266         const repository = context.symbols.Repository.ensureSingleton(1, {name: 'WebKit'});
267         const triggerableRepositoryGroup = new context.symbols.TriggerableRepositoryGroup(1, {repositories: [{repository}]});
268         new context.symbols.Triggerable(1, {
269             name: 'test-triggerable',
270             isDisabled: false,
271             repositoryGroups: [triggerableRepositoryGroup],
272             configurations: [{test, platform: mojave}, {test, platform: highSierra}],
273         });
274         customAnalysisTaskConfigurator.selectTests([test]);
275         customAnalysisTaskConfigurator.selectPlatform(mojave);
276
277         await waitForComponentsToRender(context);
278         expect(testConfigChangeActionCount).to.be(2);
279
280         const requests = context.symbols.MockRemoteAPI.requests;
281         expect(requests.length).to.be(1);
282         expect(requests[0].url).to.be('/api/commits/1/latest?platform=1');
283         requests[0].reject();
284
285         customAnalysisTaskConfigurator.content('baseline-revision-table').querySelector('input').value = '123';
286         customAnalysisTaskConfigurator.content('baseline-revision-table').querySelector('input').dispatchEvent(new Event('input'));
287         await sleep(context.symbols.CustomAnalysisTaskConfigurator.commitFetchInterval);
288         expect(requests.length).to.be(2);
289         expect(requests[1].url).to.be('/api/commits/1/123');
290
291         customAnalysisTaskConfigurator._configureComparison();
292         await waitForComponentsToRender(context);
293         expect(testConfigChangeActionCount).to.be(3);
294
295         customAnalysisTaskConfigurator.selectPlatform(highSierra);
296         await waitForComponentsToRender(context);
297         expect(testConfigChangeActionCount).to.be(4);
298     });
299 });