blob: 27532b496033750841b38b5e6c7b1b6e87d79bf9 [file] [log] [blame]
<!DOCTYPE html>
<!--
@license
Copyright (C) 2016 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.
-->
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<meta charset="utf-8">
<title>gr-settings-view</title>
<script src="/node_modules/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js"></script>
<script src="/node_modules/@webcomponents/webcomponentsjs/webcomponents-lite.js"></script>
<script src="/components/wct-browser-legacy/browser.js"></script>
<test-fixture id="basic">
<template>
<gr-change-table-editor></gr-change-table-editor>
</template>
</test-fixture>
<script type="module">
import '../../../test/common-test-setup.js';
import './gr-change-table-editor.js';
suite('gr-change-table-editor tests', () => {
let element;
let columns;
let sandbox;
setup(() => {
element = fixture('basic');
sandbox = sinon.sandbox.create();
columns = [
'Subject',
'Status',
'Owner',
'Assignee',
'Reviewers',
'Comments',
'Repo',
'Branch',
'Updated',
];
element.set('displayedColumns', columns);
element.showNumber = false;
flushAsynchronousOperations();
});
teardown(() => {
sandbox.restore();
});
test('renders', () => {
const rows = element.shadowRoot
.querySelector('tbody').querySelectorAll('tr');
let tds;
// The `+ 1` is for the number column, which isn't included in the change
// table behavior's list.
assert.equal(rows.length, element.columnNames.length + 1);
for (let i = 0; i < columns.length; i++) {
tds = rows[i + 1].querySelectorAll('td');
assert.equal(tds[0].textContent, columns[i]);
}
});
test('hide item', () => {
const checkbox = element.shadowRoot
.querySelector('table tr:nth-child(2) input');
const isChecked = checkbox.checked;
const displayedLength = element.displayedColumns.length;
assert.isTrue(isChecked);
MockInteractions.tap(checkbox);
flushAsynchronousOperations();
assert.equal(element.displayedColumns.length, displayedLength - 1);
});
test('show item', () => {
element.set('displayedColumns', [
'Status',
'Owner',
'Assignee',
'Repo',
'Branch',
'Updated',
]);
flushAsynchronousOperations();
const checkbox = element.shadowRoot
.querySelector('table tr:nth-child(2) input');
const isChecked = checkbox.checked;
const displayedLength = element.displayedColumns.length;
assert.isFalse(isChecked);
assert.equal(element.shadowRoot
.querySelector('table').style.display, '');
MockInteractions.tap(checkbox);
flushAsynchronousOperations();
assert.equal(element.displayedColumns.length,
displayedLength + 1);
});
test('_getDisplayedColumns', () => {
assert.deepEqual(element._getDisplayedColumns(), columns);
MockInteractions.tap(
element.shadowRoot
.querySelector('.checkboxContainer input[name=Assignee]'));
assert.deepEqual(element._getDisplayedColumns(),
columns.filter(c => c !== 'Assignee'));
});
test('_handleCheckboxContainerClick relays taps to checkboxes', () => {
sandbox.stub(element, '_handleNumberCheckboxClick');
sandbox.stub(element, '_handleTargetClick');
MockInteractions.tap(
element.shadowRoot
.querySelector('table tr:first-of-type .checkboxContainer'));
assert.isTrue(element._handleNumberCheckboxClick.calledOnce);
assert.isFalse(element._handleTargetClick.called);
MockInteractions.tap(
element.shadowRoot
.querySelector('table tr:last-of-type .checkboxContainer'));
assert.isTrue(element._handleNumberCheckboxClick.calledOnce);
assert.isTrue(element._handleTargetClick.calledOnce);
});
test('_handleNumberCheckboxClick', () => {
sandbox.spy(element, '_handleNumberCheckboxClick');
MockInteractions
.tap(element.shadowRoot
.querySelector('.checkboxContainer input[name=number]'));
assert.isTrue(element._handleNumberCheckboxClick.calledOnce);
assert.isTrue(element.showNumber);
MockInteractions
.tap(element.shadowRoot
.querySelector('.checkboxContainer input[name=number]'));
assert.isTrue(element._handleNumberCheckboxClick.calledTwice);
assert.isFalse(element.showNumber);
});
test('_handleTargetClick', () => {
sandbox.spy(element, '_handleTargetClick');
assert.include(element.displayedColumns, 'Assignee');
MockInteractions
.tap(element.shadowRoot
.querySelector('.checkboxContainer input[name=Assignee]'));
assert.isTrue(element._handleTargetClick.calledOnce);
assert.notInclude(element.displayedColumns, 'Assignee');
});
});
</script>