1
0
Fork 0

Select all checkbox icon class for status

This commit is contained in:
Joe Wroten 2018-12-16 14:59:18 -06:00
parent d6d9569e8d
commit 98fe4f1afc
3 changed files with 25 additions and 1 deletions

View file

@ -1,5 +1,5 @@
import Component from '@ember/component';
import { set } from '@ember/object';
import { set, computed } from '@ember/object';
const defaultFiles = [];
const defaultSelectedFilePaths = [];
@ -7,6 +7,11 @@ const defaultSelectedFilePaths = [];
export default Component.extend({
files: defaultFiles,
selectedFilePaths: defaultSelectedFilePaths,
selectAllStatus: computed('selectedFilePaths.[]', 'files.[]', function() {
if (this.selectedFilePaths.length === this.files.length) {
return 'all';
} else return this.selectedFilePaths.length === 0 ? 'none' : 'some';
}),
actions: {
toggleSelectAll() {

View file

@ -3,6 +3,12 @@
data-test-action="file-table-select-all"
{{action "toggleSelectAll"}}
>
<i
class="file-table-select-status-{{selectAllStatus}}"
data-test-id="file-table-select-status-icon"
>
&nbsp;
</i>
Selected {{selectedFilePaths.length}}
</button>
<button data-test-action="file-table-download-selected">Download Selected</button>

View file

@ -74,4 +74,17 @@ module('Integration | Component | file-table', function(hooks) {
await click('[data-test-action=file-table-select-all]');
assert.equal(find('[data-test-action=file-table-select-all]').textContent.trim(), 'Selected ' + this.files.length);
});
test('select all checkbox changes appearance between some, all and none', async function(assert) {
this.set('files', [genericFile(), genericFile()]);
this.set('selectedFilePaths', [this.files[0].path]);
await render(hbs`{{file-table files=files selectedFilePaths=selectedFilePaths}}`);
assert.equal(find('[data-test-id=file-table-select-status-icon]').classList.contains('file-table-select-status-some'), true, 'Shows SOME checkbox status icon');
await click('[data-test-action=file-table-select-all]');
assert.equal(find('[data-test-id=file-table-select-status-icon]').classList.contains('file-table-select-status-all'), true, 'Shows ALL checkbox status icon');
await click('[data-test-action=file-table-select-all]');
assert.equal(find('[data-test-id=file-table-select-status-icon]').classList.contains('file-table-select-status-none'), true, 'Shows NONE checkbox status icon');
});
});