gr-request/gr-ajax cleanup (gr-reviewer-list)

Bug: Issue 3988
Change-Id: I432557954fa8d745ce1ac766e15082650fd13100
diff --git a/polygerrit-ui/app/elements/change/gr-reviewer-list/gr-reviewer-list_test.html b/polygerrit-ui/app/elements/change/gr-reviewer-list/gr-reviewer-list_test.html
index eccc72e..9311e91 100644
--- a/polygerrit-ui/app/elements/change/gr-reviewer-list/gr-reviewer-list_test.html
+++ b/polygerrit-ui/app/elements/change/gr-reviewer-list/gr-reviewer-list_test.html
@@ -34,20 +34,12 @@
 <script>
   suite('gr-reviewer-list tests', function() {
     var element;
-    var server;
 
     setup(function() {
       element = fixture('basic');
-
-      server = sinon.fakeServer.create();
-      server.respondWith(
-        'GET',
-        /\/changes\/42\/suggest_reviewers\?n=10&q=andy(.*)/,
-        [
-          200,
-          {'Content-Type': 'application/json'},
-          ')]}\'\n' +
-          JSON.stringify([
+      stub('gr-rest-api-interface', {
+        getChangeSuggestedReviewers: function() {
+          return Promise.resolve([
             {
               account: {
                 _account_id: 1021482,
@@ -68,41 +60,32 @@
                 name: 'andy',
               }
             }
-          ]),
-        ]
-      );
-      server.respondWith(
-        'POST',
-        '/changes/42/reviewers',
-        [
-          200,
-          {'Content-Type': 'application/json'},
-          ')]}\'\n' +
-          JSON.stringify({
-            reviewers: [{
-              _account_id: 1021482,
-              approvals: {
-                'Code-Review': ' 0'
-              },
-              email: 'andybons@chromium.org',
-              name: 'Andrew Bonventre',
-            }]
-          }),
-        ]
-      );
-      server.respondWith(
-        'DELETE',
-        '/changes/42/reviewers/1021482',
-        [
-          204,
-          {'Content-Type': 'application/json'},
-          ')]}\'\n{}',
-        ]
-      );
-    });
-
-    teardown(function() {
-      server.restore();
+          ]);
+        },
+        addChangeReviewer: function() {
+          return Promise.resolve({
+            ok: true,
+            text: function() {
+              return Promise.resolve(
+                ')]}\'\n' +
+                JSON.stringify({
+                  reviewers: [{
+                    _account_id: 1021482,
+                    approvals: {
+                      'Code-Review': ' 0'
+                    },
+                    email: 'andybons@chromium.org',
+                    name: 'Andrew Bonventre',
+                  }]
+                })
+              );
+            },
+          });
+        },
+        removeChangeReviewer: function() {
+          return Promise.resolve({ok: true});
+        },
+      });
     });
 
     test('controls hidden on immutable element', function() {
@@ -176,7 +159,7 @@
       };
       flushAsynchronousOperations();
       var chips =
-        Polymer.dom(element.root).querySelectorAll('gr-account-chip');
+          Polymer.dom(element.root).querySelectorAll('gr-account-chip');
       assert.equal(chips.length, 3);
       Array.from(chips).forEach(function(el) {
         var accountID = parseInt(el.getAttribute('data-account-id'), 10);
@@ -195,17 +178,15 @@
     test('autocomplete starts at >= 3 chars', function() {
       element._inputRequestTimeout = 0;
       element._mutable = true;
-      var genRequestStub = sinon.stub(
-        element.$.autocompleteXHR,
-        'generateRequest',
+      var requestStub = sinon.stub(element, '_getSuggestedReviewers',
         function() {
-          assert(false, 'generateRequest should not be called for input ' +
-              'lengths of less than 3 chars');
+          assert(false, '_getSuggestedReviewers should not be called for ' +
+              'input lengths of less than 3 chars');
         }
       );
       element._inputVal = 'fo';
       flushAsynchronousOperations();
-      genRequestStub.restore();
+      requestStub.restore();
     });
 
     test('add/remove reviewer flow', function(done) {
@@ -220,9 +201,8 @@
       MockInteractions.tap(element.$$('.addReviewer'));
       flushAsynchronousOperations();
       element._inputVal = 'andy';
-      server.respond();
 
-      element._lastAutocompleteRequest.completes.then(function() {
+      element._lastAutocompleteRequest.then(function() {
         flushAsynchronousOperations();
         assert.isFalse(element.$$('.dropdown').hasAttribute('hidden'));
         var itemEls = Polymer.dom(element.root).querySelectorAll('.reviewer');
@@ -242,8 +222,7 @@
         assert.isTrue(element.$$('.dropdown').hasAttribute('hidden'));
 
         element._inputVal = 'andyb';
-        server.respond();
-        element._lastAutocompleteRequest.completes.then(function() {
+        element._lastAutocompleteRequest.then(function() {
           assert.isFalse(element.$$('.dropdown').hasAttribute('hidden'));
           var itemEls = Polymer.dom(element.root).querySelectorAll('.reviewer');
           assert.equal(itemEls.length, 3);
@@ -251,7 +230,6 @@
           assert.isFalse(itemEls[1].hasAttribute('selected'));
           MockInteractions.pressAndReleaseKeyOn(element, 13); // 'enter'
           assert.isTrue(element.disabled);
-          server.respond();
 
           element._xhrPromise.then(function() {
             assert.isFalse(element.disabled);
@@ -262,13 +240,12 @@
             MockInteractions.tap(element.$$('.reviewer').$$('gr-button'));
             flushAsynchronousOperations();
             assert.isTrue(element.disabled);
-            server.respond();
 
             element._xhrPromise.then(function() {
               flushAsynchronousOperations();
               assert.isFalse(element.disabled);
               var reviewerEls =
-                Polymer.dom(element.root).querySelectorAll('.reviewer');
+                  Polymer.dom(element.root).querySelectorAll('.reviewer');
               assert.equal(reviewerEls.length, 0);
               done();
             });