Merge "Update change.maxPatchSets value from 1500 to 1000"
diff --git a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-change-reply-js-api_test.js b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-change-reply-js-api_test.js
deleted file mode 100644
index f19996b..0000000
--- a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-change-reply-js-api_test.js
+++ /dev/null
@@ -1,87 +0,0 @@
-/**
- * @license
- * Copyright 2016 Google LLC
- * SPDX-License-Identifier: Apache-2.0
- */
-import '../../../test/common-test-setup';
-import '../../change/gr-reply-dialog/gr-reply-dialog';
-import {stubRestApi} from '../../../test/test-utils';
-// eslint-disable-next-line import/named
-import {fixture, html, assert} from '@open-wc/testing';
-
-suite('gr-change-reply-js-api tests', () => {
-  let element;
-  let changeReply;
-  let plugin;
-
-  setup(() => {
-    stubRestApi('getAccount').returns(Promise.resolve(null));
-  });
-
-  suite('early init', () => {
-    setup(async () => {
-      window.Gerrit.install(
-          p => {
-            plugin = p;
-          },
-          '0.1',
-          'http://test.com/plugins/testplugin/static/test.js'
-      );
-      changeReply = plugin.changeReply();
-      element = await fixture(html`<gr-reply-dialog></gr-reply-dialog>`);
-    });
-
-    teardown(() => {
-      changeReply = null;
-    });
-
-    test('works', () => {
-      sinon.stub(element, 'getLabelValue').returns('+123');
-      assert.equal(changeReply.getLabelValue('My-Label'), '+123');
-
-      sinon.stub(element, 'setLabelValue');
-      changeReply.setLabelValue('My-Label', '+1337');
-      assert.isTrue(
-          element.setLabelValue.calledWithExactly('My-Label', '+1337')
-      );
-
-      sinon.stub(element, 'setPluginMessage');
-      changeReply.showMessage('foobar');
-      assert.isTrue(element.setPluginMessage.calledWithExactly('foobar'));
-    });
-  });
-
-  suite('normal init', () => {
-    setup(async () => {
-      element = await fixture(html`<gr-reply-dialog></gr-reply-dialog>`);
-      window.Gerrit.install(
-          p => {
-            plugin = p;
-          },
-          '0.1',
-          'http://test.com/plugins/testplugin/static/test.js'
-      );
-      changeReply = plugin.changeReply();
-    });
-
-    teardown(() => {
-      changeReply = null;
-    });
-
-    test('works', () => {
-      sinon.stub(element, 'getLabelValue').returns('+123');
-      assert.equal(changeReply.getLabelValue('My-Label'), '+123');
-
-      sinon.stub(element, 'setLabelValue');
-      changeReply.setLabelValue('My-Label', '+1337');
-      assert.isTrue(
-          element.setLabelValue.calledWithExactly('My-Label', '+1337')
-      );
-
-      sinon.stub(element, 'setPluginMessage');
-      changeReply.showMessage('foobar');
-      assert.isTrue(element.setPluginMessage.calledWithExactly('foobar'));
-    });
-  });
-});
-
diff --git a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-change-reply-js-api_test.ts b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-change-reply-js-api_test.ts
new file mode 100644
index 0000000..1d47d37
--- /dev/null
+++ b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-change-reply-js-api_test.ts
@@ -0,0 +1,74 @@
+/**
+ * @license
+ * Copyright 2016 Google LLC
+ * SPDX-License-Identifier: Apache-2.0
+ */
+import '../../../test/common-test-setup';
+import '../../change/gr-reply-dialog/gr-reply-dialog';
+import {stubElement} from '../../../test/test-utils';
+import {assert} from '@open-wc/testing';
+import {PluginApi} from '../../../api/plugin';
+import {ChangeReplyPluginApi} from '../../../api/change-reply';
+
+suite('gr-change-reply-js-api tests', () => {
+  let changeReply: ChangeReplyPluginApi;
+  let plugin: PluginApi;
+
+  suite('early init', () => {
+    setup(async () => {
+      window.Gerrit.install(
+        p => {
+          plugin = p;
+        },
+        '0.1',
+        'http://test.com/plugins/testplugin/static/test.js'
+      );
+      changeReply = plugin.changeReply();
+    });
+
+    test('works', () => {
+      stubElement('gr-reply-dialog', 'getLabelValue').returns('+123');
+      assert.equal(changeReply.getLabelValue('My-Label'), '+123');
+
+      const setLabelValueStub = stubElement('gr-reply-dialog', 'setLabelValue');
+      changeReply.setLabelValue('My-Label', '+1337');
+      assert.isTrue(setLabelValueStub.calledWithExactly('My-Label', '+1337'));
+
+      const setPluginMessageStub = stubElement(
+        'gr-reply-dialog',
+        'setPluginMessage'
+      );
+      changeReply.showMessage('foobar');
+      assert.isTrue(setPluginMessageStub.calledWithExactly('foobar'));
+    });
+  });
+
+  suite('normal init', () => {
+    setup(async () => {
+      window.Gerrit.install(
+        p => {
+          plugin = p;
+        },
+        '0.1',
+        'http://test.com/plugins/testplugin/static/test.js'
+      );
+      changeReply = plugin.changeReply();
+    });
+
+    test('works', () => {
+      stubElement('gr-reply-dialog', 'getLabelValue').returns('+123');
+      assert.equal(changeReply.getLabelValue('My-Label'), '+123');
+
+      const setLabelValueStub = stubElement('gr-reply-dialog', 'setLabelValue');
+      changeReply.setLabelValue('My-Label', '+1337');
+      assert.isTrue(setLabelValueStub.calledWithExactly('My-Label', '+1337'));
+
+      const setPluginMessageStub = stubElement(
+        'gr-reply-dialog',
+        'setPluginMessage'
+      );
+      changeReply.showMessage('foobar');
+      assert.isTrue(setPluginMessageStub.calledWithExactly('foobar'));
+    });
+  });
+});
diff --git a/polygerrit-ui/app/models/bulk-actions/bulk-actions-model.ts b/polygerrit-ui/app/models/bulk-actions/bulk-actions-model.ts
index c7d63c2..b58fc3f 100644
--- a/polygerrit-ui/app/models/bulk-actions/bulk-actions-model.ts
+++ b/polygerrit-ui/app/models/bulk-actions/bulk-actions-model.ts
@@ -35,6 +35,7 @@
 }
 export interface BulkActionsState {
   loadingState: LoadingState;
+  selectableChangeNums: NumericChangeId[];
   selectedChangeNums: NumericChangeId[];
   allChanges: Map<NumericChangeId, ChangeInfo>;
 }
@@ -42,6 +43,7 @@
 const initialState: BulkActionsState = {
   loadingState: LoadingState.NOT_SYNCED,
   selectedChangeNums: [],
+  selectableChangeNums: [],
   allChanges: new Map(),
 };
 
@@ -68,11 +70,6 @@
     bulkActionsState => bulkActionsState.loadingState
   );
 
-  public readonly allChanges$ = select(
-    this.state$,
-    bulkActionsState => bulkActionsState.allChanges
-  );
-
   public readonly selectedChanges$ = select(this.state$, bulkActionsState => {
     const result = [];
     for (const changeNum of bulkActionsState.selectedChangeNums) {
@@ -90,7 +87,7 @@
 
   addSelectedChangeNum(changeNum: NumericChangeId) {
     const current = this.getState();
-    if (!current.allChanges.has(changeNum)) {
+    if (!current.selectableChangeNums.includes(changeNum)) {
       throw new Error(
         `Trying to add change ${changeNum} that is not part of bulk-actions model`
       );
@@ -102,7 +99,7 @@
 
   removeSelectedChangeNum(changeNum: NumericChangeId) {
     const current = this.getState();
-    if (!current.allChanges.has(changeNum)) {
+    if (!current.selectableChangeNums.includes(changeNum)) {
       throw new Error(
         `Trying to remove change ${changeNum} that is not part of bulk-actions model`
       );
@@ -242,10 +239,12 @@
     const selectedChangeNums = currentState.selectedChangeNums.filter(
       changeNum => basicChanges.has(changeNum)
     );
+    const selectableChangeNums = changes.map(c => c._number);
     this.updateState({
       loadingState: LoadingState.LOADING,
       selectedChangeNums,
-      allChanges: basicChanges,
+      selectableChangeNums,
+      allChanges: new Map(),
     });
 
     if (changes.length === 0) {
@@ -257,7 +256,7 @@
       );
     currentState = this.getState();
     // Return early if sync has been called again since starting the load.
-    if (basicChanges !== currentState.allChanges) return;
+    if (selectableChangeNums !== currentState.selectableChangeNums) return;
     const allDetailedChanges: Map<NumericChangeId, ChangeInfo> = new Map();
     for (const detailedChange of changeDetails ?? []) {
       const basicChange = basicChanges.get(detailedChange._number)!;
diff --git a/polygerrit-ui/app/models/bulk-actions/bulk-actions-model_test.ts b/polygerrit-ui/app/models/bulk-actions/bulk-actions-model_test.ts
index 686f9d9..7bc37d6 100644
--- a/polygerrit-ui/app/models/bulk-actions/bulk-actions-model_test.ts
+++ b/polygerrit-ui/app/models/bulk-actions/bulk-actions-model_test.ts
@@ -79,6 +79,7 @@
     bulkActionsModel.sync([c1, c2]);
 
     assert.isEmpty(bulkActionsModel.getState().selectedChangeNums);
+    assert.deepEqual(bulkActionsModel.getState().selectableChangeNums, [1, 2]);
 
     bulkActionsModel.addSelectedChangeNum(c1._number);
     assert.sameMembers(bulkActionsModel.getState().selectedChangeNums, [