Add the UI for scheduling a A/B testing with a custom root
[WebKit-https.git] / Websites / perf.webkit.org / unit-tests / analysis-task-tests.js
index 415ea01..b20fecf 100644 (file)
@@ -15,7 +15,6 @@ function sampleAnalysisTask()
                 'bugs': [],
                 'buildRequestCount': '14',
                 'finishedBuildRequestCount': '6',
-                'category': 'identified',
                 'causes': [
                     '105975'
                 ],
@@ -24,10 +23,10 @@ function sampleAnalysisTask()
                 'endRunTime': 1454515020303,
                 'fixes': [],
                 'id': '1082',
-                'metric': '2884',
+                'metric': MockModels.someMetric.id(),
                 'name': 'Potential 1.2% regression between 2016-02-02 20:20 and 02-03 15:57',
                 'needed': null,
-                'platform': '65',
+                'platform': MockModels.somePlatform.id(),
                 'result': 'regression',
                 'segmentationStrategy': '1',
                 'startRun': '37117949',
@@ -53,6 +52,38 @@ function sampleAnalysisTask()
     };
 }
 
+function sampleCustomAnalysisTask()
+{
+    return {
+        'analysisTasks': [
+            {
+                'id': '1000',
+                'createdAt': 1454594330000,
+                'author': null,
+                'buildRequestCount': '0',
+                'finishedBuildRequestCount': '0',
+                'bugs': [],
+                'causes': [ ],
+                'fixes': [],
+                'startRun': null,
+                'startRunTime': null,
+                'endRun': null,
+                'endRunTime': null,
+                'metric': null,
+                'name': 'Potential 1.2% regression between 2016-02-02 20:20 and 02-03 15:57',
+                'needed': null,
+                'platform': null,
+                'result': null,
+                'segmentationStrategy': null,
+                'testRangeStragegy': null,
+            }
+        ],
+        'commits': [],
+        'bugs': [],
+        'status': 'OK'
+    };
+}
+
 function measurementCluster()
 {
     return {
@@ -120,6 +151,43 @@ describe('AnalysisTask', () => {
     MockModels.inject();
     let requests = MockRemoteAPI.inject();
 
+    function loadAnalysisTasks(rawData)
+    {
+        AnalysisTask._constructAnalysisTasksFromRawData(rawData);
+        return Promise.resolve();
+    }
+
+    describe('findByPlatformAndMetric', () => {
+        it('should return an empty array when there are no analysis tasks', () => {
+            assert.deepEqual(AnalysisTask.findByPlatformAndMetric(MockModels.somePlatform, MockModels.someMetric), []);
+        });
+
+        it('should return an array containing the matching non-custom analysis tasks', () => {
+            return loadAnalysisTasks(sampleAnalysisTask()).then(() => {
+                return loadAnalysisTasks(sampleCustomAnalysisTask());
+            }).then(() => {
+                const tasks = AnalysisTask.findByPlatformAndMetric(MockModels.somePlatform.id(), MockModels.someMetric.id());
+                assert.equal(tasks.length, 1);
+                const task = tasks[0];
+                assert.equal(task.id(), 1082);
+                assert.equal(task.isCustom(), false);
+                assert.equal(task.hasResults(), true);
+                assert.equal(task.hasPendingRequests(), true);
+                assert.equal(task.requestLabel(), '6 of 14');
+                assert.equal(task.startMeasurementId(), 37117949);
+                assert.equal(task.endMeasurementId(), 37253448);
+                assert.equal(task.author(), '');
+                assert.deepEqual(task.bugs(), []);
+                assert.deepEqual(task.causes(), [CommitLog.findById(105975)]);
+                assert.deepEqual(task.fixes(), []);
+                assert.deepEqual(task.platform(), MockModels.somePlatform);
+                assert.deepEqual(task.metric(), MockModels.someMetric);
+                assert.deepEqual(task.changeType(), 'regression');
+                assert.deepEqual(task.category(), 'investigated');
+            });
+        });
+    });
+
     describe('fetchAll', () => {
         it('should request all analysis tasks', () => {
             let callCount = 0;