Merge changes I3c65719a,Iab5f8350
* changes:
Fix template problems with gr-edit-file-controls
Convert gr-edit-file-controls_test.js to typescript
diff --git a/polygerrit-ui/app/BUILD b/polygerrit-ui/app/BUILD
index 36fc456..e0a6917 100644
--- a/polygerrit-ui/app/BUILD
+++ b/polygerrit-ui/app/BUILD
@@ -120,7 +120,6 @@
"elements/diff/gr-patch-range-select/gr-patch-range-select_html.ts",
"elements/documentation/gr-documentation-search/gr-documentation-search_html.ts",
"elements/edit/gr-edit-controls/gr-edit-controls_html.ts",
- "elements/edit/gr-edit-file-controls/gr-edit-file-controls_html.ts",
"elements/gr-app-element_html.ts",
"elements/settings/gr-cla-view/gr-cla-view_html.ts",
"elements/settings/gr-edit-preferences/gr-edit-preferences_html.ts",
diff --git a/polygerrit-ui/app/elements/edit/gr-edit-file-controls/gr-edit-file-controls_test.js b/polygerrit-ui/app/elements/edit/gr-edit-file-controls/gr-edit-file-controls_test.js
deleted file mode 100644
index 180a3a4..0000000
--- a/polygerrit-ui/app/elements/edit/gr-edit-file-controls/gr-edit-file-controls_test.js
+++ /dev/null
@@ -1,92 +0,0 @@
-/**
- * @license
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import '../../../test/common-test-setup-karma.js';
-import '../gr-edit-constants.js';
-import './gr-edit-file-controls.js';
-import {GrEditConstants} from '../gr-edit-constants.js';
-
-const basicFixture = fixtureFromElement('gr-edit-file-controls');
-
-suite('gr-edit-file-controls tests', () => {
- let element;
-
- let fileActionHandler;
-
- setup(() => {
- element = basicFixture.instantiate();
- fileActionHandler = sinon.stub();
- element.addEventListener('file-action-tap', fileActionHandler);
- });
-
- test('open tap emits event', () => {
- const actions = element.$.actions;
- element.filePath = 'foo';
- actions._open();
- flush();
-
- MockInteractions.tap(actions.shadowRoot
- .querySelector('li [data-id="open"]'));
- assert.isTrue(fileActionHandler.called);
- assert.deepEqual(fileActionHandler.lastCall.args[0].detail,
- {action: GrEditConstants.Actions.OPEN.id, path: 'foo'});
- });
-
- test('delete tap emits event', () => {
- const actions = element.$.actions;
- element.filePath = 'foo';
- actions._open();
- flush();
-
- MockInteractions.tap(actions.shadowRoot
- .querySelector('li [data-id="delete"]'));
- assert.isTrue(fileActionHandler.called);
- assert.deepEqual(fileActionHandler.lastCall.args[0].detail,
- {action: GrEditConstants.Actions.DELETE.id, path: 'foo'});
- });
-
- test('restore tap emits event', () => {
- const actions = element.$.actions;
- element.filePath = 'foo';
- actions._open();
- flush();
-
- MockInteractions.tap(actions.shadowRoot
- .querySelector('li [data-id="restore"]'));
- assert.isTrue(fileActionHandler.called);
- assert.deepEqual(fileActionHandler.lastCall.args[0].detail,
- {action: GrEditConstants.Actions.RESTORE.id, path: 'foo'});
- });
-
- test('rename tap emits event', () => {
- const actions = element.$.actions;
- element.filePath = 'foo';
- actions._open();
- flush();
-
- MockInteractions.tap(actions.shadowRoot
- .querySelector('li [data-id="rename"]'));
- assert.isTrue(fileActionHandler.called);
- assert.deepEqual(fileActionHandler.lastCall.args[0].detail,
- {action: GrEditConstants.Actions.RENAME.id, path: 'foo'});
- });
-
- test('computed properties', () => {
- assert.equal(element._allFileActions.length, 4);
- });
-});
-
diff --git a/polygerrit-ui/app/elements/edit/gr-edit-file-controls/gr-edit-file-controls_test.ts b/polygerrit-ui/app/elements/edit/gr-edit-file-controls/gr-edit-file-controls_test.ts
new file mode 100644
index 0000000..a432ebf
--- /dev/null
+++ b/polygerrit-ui/app/elements/edit/gr-edit-file-controls/gr-edit-file-controls_test.ts
@@ -0,0 +1,102 @@
+/**
+ * @license
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import '../../../test/common-test-setup-karma';
+import './gr-edit-file-controls';
+import {GrEditFileControls} from './gr-edit-file-controls';
+import {GrEditConstants} from '../gr-edit-constants';
+import {queryAndAssert} from '../../../test/test-utils';
+import {GrDropdown} from '../../shared/gr-dropdown/gr-dropdown';
+import * as MockInteractions from '@polymer/iron-test-helpers/mock-interactions';
+
+const basicFixture = fixtureFromElement('gr-edit-file-controls');
+
+suite('gr-edit-file-controls tests', () => {
+ let element: GrEditFileControls;
+
+ let fileActionHandler: sinon.SinonStub;
+
+ setup(() => {
+ element = basicFixture.instantiate();
+ fileActionHandler = sinon.stub();
+ element.addEventListener('file-action-tap', fileActionHandler);
+ });
+
+ test('open tap emits event', () => {
+ const actions = queryAndAssert<GrDropdown>(element, '#actions');
+ element.filePath = 'foo';
+ actions._open();
+ flush();
+
+ const row = queryAndAssert(actions, 'li [data-id="open"]');
+ MockInteractions.tap(row);
+ assert.isTrue(fileActionHandler.called);
+ assert.deepEqual(fileActionHandler.lastCall.args[0].detail, {
+ action: GrEditConstants.Actions.OPEN.id,
+ path: 'foo',
+ });
+ });
+
+ test('delete tap emits event', () => {
+ const actions = queryAndAssert<GrDropdown>(element, '#actions');
+ element.filePath = 'foo';
+ actions._open();
+ flush();
+
+ const row = queryAndAssert(actions, 'li [data-id="delete"]');
+ MockInteractions.tap(row);
+ assert.isTrue(fileActionHandler.called);
+ assert.deepEqual(fileActionHandler.lastCall.args[0].detail, {
+ action: GrEditConstants.Actions.DELETE.id,
+ path: 'foo',
+ });
+ });
+
+ test('restore tap emits event', () => {
+ const actions = queryAndAssert<GrDropdown>(element, '#actions');
+ element.filePath = 'foo';
+ actions._open();
+ flush();
+
+ const row = queryAndAssert(actions, 'li [data-id="restore"]');
+ MockInteractions.tap(row);
+ assert.isTrue(fileActionHandler.called);
+ assert.deepEqual(fileActionHandler.lastCall.args[0].detail, {
+ action: GrEditConstants.Actions.RESTORE.id,
+ path: 'foo',
+ });
+ });
+
+ test('rename tap emits event', () => {
+ const actions = queryAndAssert<GrDropdown>(element, '#actions');
+ element.filePath = 'foo';
+ actions._open();
+ flush();
+
+ const row = queryAndAssert(actions, 'li [data-id="rename"]');
+ MockInteractions.tap(row);
+ assert.isTrue(fileActionHandler.called);
+ assert.deepEqual(fileActionHandler.lastCall.args[0].detail, {
+ action: GrEditConstants.Actions.RENAME.id,
+ path: 'foo',
+ });
+ });
+
+ test('computed properties', () => {
+ assert.equal(element._allFileActions.length, 4);
+ });
+});
diff --git a/polygerrit-ui/app/types/events.ts b/polygerrit-ui/app/types/events.ts
index cc163c8..e168936 100644
--- a/polygerrit-ui/app/types/events.ts
+++ b/polygerrit-ui/app/types/events.ts
@@ -45,6 +45,7 @@
SHOW_ERROR = 'show-error',
SHOW_PRIMARY_TAB = 'show-primary-tab',
SHOW_SECONDARY_TAB = 'show-secondary-tab',
+ TAP_ITEM = 'tap-item',
THREAD_LIST_MODIFIED = 'thread-list-modified',
TITLE_CHANGE = 'title-change',
}
@@ -74,6 +75,7 @@
'show-error': ShowErrorEvent;
'show-primary-tab': SwitchTabEvent;
'show-secondary-tab': SwitchTabEvent;
+ 'tap-item': TapItemEvent;
'thread-list-modified': ThreadListModifiedEvent;
'title-change': TitleChangeEvent;
}
@@ -217,6 +219,8 @@
}
export type SwitchTabEvent = CustomEvent<SwitchTabEventDetail>;
+export type TapItemEvent = CustomEvent;
+
export interface ThreadListModifiedDetail {
rootId: UrlEncodedCommentId;
path: string;