2016-08-17 18:01:46 +03:00
|
|
|
import $ from 'jquery';
|
2017-05-29 21:50:03 +03:00
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
|
|
|
import sinon from 'sinon';
|
|
|
|
import {describe, it} from 'mocha';
|
|
|
|
import {expect} from 'chai';
|
2017-08-22 10:53:26 +03:00
|
|
|
import {run} from '@ember/runloop';
|
2017-05-29 21:50:03 +03:00
|
|
|
import {setupComponentTest} from 'ember-mocha';
|
2016-08-17 18:01:46 +03:00
|
|
|
|
2018-01-05 18:38:23 +03:00
|
|
|
describe('Integration: Component: gh-theme-table', function () {
|
2016-11-24 01:50:57 +03:00
|
|
|
setupComponentTest('gh-theme-table', {
|
2016-08-17 18:01:46 +03:00
|
|
|
integration: true
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
|
2018-01-05 18:38:23 +03:00
|
|
|
it('renders', function () {
|
2017-02-21 21:28:44 +03:00
|
|
|
this.set('themes', [
|
2017-03-03 18:31:42 +03:00
|
|
|
{name: 'Daring', package: {name: 'Daring', version: '0.1.4'}, active: true},
|
2016-11-24 01:50:57 +03:00
|
|
|
{name: 'casper', package: {name: 'Casper', version: '1.3.1'}},
|
|
|
|
{name: 'oscar-ghost-1.1.0', package: {name: 'Lanyon', version: '1.1.0'}},
|
|
|
|
{name: 'foo'}
|
|
|
|
]);
|
|
|
|
this.set('actionHandler', sinon.spy());
|
|
|
|
|
|
|
|
this.render(hbs`{{gh-theme-table
|
2017-02-21 21:28:44 +03:00
|
|
|
themes=themes
|
2016-11-24 01:50:57 +03:00
|
|
|
activateTheme=(action actionHandler)
|
|
|
|
downloadTheme=(action actionHandler)
|
|
|
|
deleteTheme=(action actionHandler)
|
|
|
|
}}`);
|
|
|
|
|
2017-08-11 18:28:05 +03:00
|
|
|
expect(this.$('[data-test-themes-list]').length, 'themes list is present').to.equal(1);
|
|
|
|
expect(this.$('[data-test-theme-id]').length, 'number of rows').to.equal(4);
|
2016-11-24 01:50:57 +03:00
|
|
|
|
2018-01-05 18:38:23 +03:00
|
|
|
let packageNames = this.$('[data-test-theme-title]').map((i, name) => $(name).text().trim()).toArray();
|
2016-11-24 01:50:57 +03:00
|
|
|
|
|
|
|
expect(
|
|
|
|
packageNames,
|
2017-02-27 15:34:46 +03:00
|
|
|
'themes are ordered by label, casper has "default"'
|
2016-11-24 01:50:57 +03:00
|
|
|
).to.deep.equal([
|
2017-02-27 15:34:46 +03:00
|
|
|
'Casper (default)',
|
|
|
|
'Daring',
|
2016-11-24 01:50:57 +03:00
|
|
|
'foo',
|
2017-02-27 15:34:46 +03:00
|
|
|
'Lanyon'
|
2016-11-24 01:50:57 +03:00
|
|
|
]);
|
|
|
|
|
|
|
|
expect(
|
2017-08-11 18:28:05 +03:00
|
|
|
this.$('[data-test-theme-active="true"]').find('[data-test-theme-title]').text().trim(),
|
2016-11-24 01:50:57 +03:00
|
|
|
'active theme is highlighted'
|
2017-02-27 15:34:46 +03:00
|
|
|
).to.equal('Daring');
|
2016-11-24 01:50:57 +03:00
|
|
|
|
|
|
|
expect(
|
2017-08-11 18:28:05 +03:00
|
|
|
this.$('[data-test-theme-activate-button]').length === 3,
|
2016-11-24 01:50:57 +03:00
|
|
|
'non-active themes have an activate link'
|
|
|
|
).to.be.true;
|
|
|
|
|
|
|
|
expect(
|
2017-08-11 18:28:05 +03:00
|
|
|
this.$('[data-test-theme-active="true"]').find('[data-test-theme-activate-button]').length === 0,
|
2016-11-24 01:50:57 +03:00
|
|
|
'active theme doesn\'t have an activate link'
|
|
|
|
).to.be.true;
|
|
|
|
|
|
|
|
expect(
|
2017-08-11 18:28:05 +03:00
|
|
|
this.$('[data-test-theme-download-button]').length,
|
2016-11-24 01:50:57 +03:00
|
|
|
'all themes have a download link'
|
|
|
|
).to.equal(4);
|
|
|
|
|
|
|
|
expect(
|
2017-08-11 18:28:05 +03:00
|
|
|
this.$('[data-test-theme-id="foo"]').find('[data-test-theme-delete-button]').length === 1,
|
2016-11-24 01:50:57 +03:00
|
|
|
'non-active, non-casper theme has delete link'
|
|
|
|
).to.be.true;
|
|
|
|
|
|
|
|
expect(
|
2017-08-11 18:28:05 +03:00
|
|
|
this.$('[data-test-theme-id="casper"]').find('[data-test-theme-delete-button]').length === 0,
|
2016-11-24 01:50:57 +03:00
|
|
|
'casper doesn\'t have delete link'
|
|
|
|
).to.be.true;
|
|
|
|
|
|
|
|
expect(
|
2017-08-11 18:28:05 +03:00
|
|
|
this.$('[data-test-theme-active="true"]').find('[data-test-theme-delete-button]').length === 0,
|
2016-11-24 01:50:57 +03:00
|
|
|
'active theme doesn\'t have delete link'
|
|
|
|
).to.be.true;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('delete link triggers passed in action', function () {
|
|
|
|
let deleteAction = sinon.spy();
|
|
|
|
let actionHandler = sinon.spy();
|
|
|
|
|
2017-02-21 21:28:44 +03:00
|
|
|
this.set('themes', [
|
2016-11-24 01:50:57 +03:00
|
|
|
{name: 'Foo', active: true},
|
|
|
|
{name: 'Bar'}
|
|
|
|
]);
|
|
|
|
this.set('deleteAction', deleteAction);
|
|
|
|
this.set('actionHandler', actionHandler);
|
|
|
|
|
|
|
|
this.render(hbs`{{gh-theme-table
|
2017-02-21 21:28:44 +03:00
|
|
|
themes=themes
|
2016-11-24 01:50:57 +03:00
|
|
|
activateTheme=(action actionHandler)
|
|
|
|
downloadTheme=(action actionHandler)
|
|
|
|
deleteTheme=(action deleteAction)
|
|
|
|
}}`);
|
|
|
|
|
|
|
|
run(() => {
|
2017-08-11 18:28:05 +03:00
|
|
|
this.$('[data-test-theme-id="Bar"] [data-test-theme-delete-button]').click();
|
2016-08-17 18:01:46 +03:00
|
|
|
});
|
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
expect(deleteAction.calledOnce).to.be.true;
|
|
|
|
expect(deleteAction.firstCall.args[0].name).to.equal('Bar');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('download link triggers passed in action', function () {
|
|
|
|
let downloadAction = sinon.spy();
|
|
|
|
let actionHandler = sinon.spy();
|
|
|
|
|
2017-02-21 21:28:44 +03:00
|
|
|
this.set('themes', [
|
2016-11-24 01:50:57 +03:00
|
|
|
{name: 'Foo', active: true},
|
|
|
|
{name: 'Bar'}
|
|
|
|
]);
|
|
|
|
this.set('downloadAction', downloadAction);
|
|
|
|
this.set('actionHandler', actionHandler);
|
|
|
|
|
|
|
|
this.render(hbs`{{gh-theme-table
|
2017-02-21 21:28:44 +03:00
|
|
|
themes=themes
|
2016-11-24 01:50:57 +03:00
|
|
|
activateTheme=(action actionHandler)
|
|
|
|
downloadTheme=(action downloadAction)
|
|
|
|
deleteTheme=(action actionHandler)
|
|
|
|
}}`);
|
|
|
|
|
|
|
|
run(() => {
|
2017-08-11 18:28:05 +03:00
|
|
|
this.$('[data-test-theme-id="Foo"] [data-test-theme-download-button]').click();
|
2016-08-17 18:01:46 +03:00
|
|
|
});
|
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
expect(downloadAction.calledOnce).to.be.true;
|
|
|
|
expect(downloadAction.firstCall.args[0].name).to.equal('Foo');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('activate link triggers passed in action', function () {
|
|
|
|
let activateAction = sinon.spy();
|
|
|
|
let actionHandler = sinon.spy();
|
|
|
|
|
2017-02-21 21:28:44 +03:00
|
|
|
this.set('themes', [
|
2016-11-24 01:50:57 +03:00
|
|
|
{name: 'Foo', active: true},
|
|
|
|
{name: 'Bar'}
|
|
|
|
]);
|
|
|
|
this.set('activateAction', activateAction);
|
|
|
|
this.set('actionHandler', actionHandler);
|
|
|
|
|
|
|
|
this.render(hbs`{{gh-theme-table
|
2017-02-21 21:28:44 +03:00
|
|
|
themes=themes
|
2016-11-24 01:50:57 +03:00
|
|
|
activateTheme=(action activateAction)
|
|
|
|
downloadTheme=(action actionHandler)
|
|
|
|
deleteTheme=(action actionHandler)
|
|
|
|
}}`);
|
|
|
|
|
|
|
|
run(() => {
|
2017-08-11 18:28:05 +03:00
|
|
|
this.$('[data-test-theme-id="Bar"] [data-test-theme-activate-button]').click();
|
2016-08-17 18:01:46 +03:00
|
|
|
});
|
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
expect(activateAction.calledOnce).to.be.true;
|
|
|
|
expect(activateAction.firstCall.args[0].name).to.equal('Bar');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('displays folder names if there are duplicate package names', function () {
|
2017-02-21 21:28:44 +03:00
|
|
|
this.set('themes', [
|
2016-11-24 01:50:57 +03:00
|
|
|
{name: 'daring', package: {name: 'Daring', version: '0.1.4'}, active: true},
|
|
|
|
{name: 'daring-0.1.5', package: {name: 'Daring', version: '0.1.4'}},
|
|
|
|
{name: 'casper', package: {name: 'Casper', version: '1.3.1'}},
|
|
|
|
{name: 'another', package: {name: 'Casper', version: '1.3.1'}},
|
|
|
|
{name: 'mine', package: {name: 'Casper', version: '1.3.1'}},
|
|
|
|
{name: 'foo'}
|
|
|
|
]);
|
|
|
|
this.set('actionHandler', sinon.spy());
|
|
|
|
|
|
|
|
this.render(hbs`{{gh-theme-table
|
2017-02-21 21:28:44 +03:00
|
|
|
themes=themes
|
2016-11-24 01:50:57 +03:00
|
|
|
activateTheme=(action actionHandler)
|
|
|
|
downloadTheme=(action actionHandler)
|
|
|
|
deleteTheme=(action actionHandler)
|
|
|
|
}}`);
|
|
|
|
|
2018-01-05 18:38:23 +03:00
|
|
|
let packageNames = this.$('[data-test-theme-title]').map((i, name) => $(name).text().trim()).toArray();
|
2016-11-24 01:50:57 +03:00
|
|
|
|
|
|
|
expect(
|
|
|
|
packageNames,
|
|
|
|
'themes are ordered by label, folder names shown for duplicates'
|
|
|
|
).to.deep.equal([
|
2017-02-27 15:34:46 +03:00
|
|
|
'Casper (another)',
|
|
|
|
'Casper (default)',
|
|
|
|
'Casper (mine)',
|
|
|
|
'Daring (daring)',
|
|
|
|
'Daring (daring-0.1.5)',
|
2016-11-24 01:50:57 +03:00
|
|
|
'foo'
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|