Ghost-Admin/tests/integration/components/gh-timezone-select-test.js

74 lines
2.7 KiB
JavaScript
Raw Normal View History

/* jshint expr:true */
import {expect} from 'chai';
2016-11-23 23:50:57 +01:00
import {describe, it} from 'mocha';
import {setupComponentTest} from 'ember-mocha';
import hbs from 'htmlbars-inline-precompile';
import run from 'ember-runloop';
import wait from 'ember-test-helpers/wait';
import sinon from 'sinon';
2016-11-23 23:50:57 +01:00
describe('Integration: Component: gh-timezone-select', function() {
setupComponentTest('gh-timezone-select', {
integration: true
2016-11-23 23:50:57 +01:00
});
2016-11-23 23:50:57 +01:00
beforeEach(function () {
this.set('availableTimezones', [
{name: 'Pacific/Pago_Pago', label: '(GMT -11:00) Midway Island, Samoa'},
{name: 'Etc/UTC', label: '(GMT) UTC'},
{name: 'Pacific/Kwajalein', label: '(GMT +12:00) International Date Line West'}
]);
this.set('activeTimezone', 'Etc/UTC');
});
2016-11-23 23:50:57 +01:00
it('renders', function () {
this.render(hbs`{{gh-timezone-select
availableTimezones=availableTimezones
activeTimezone=activeTimezone}}`);
2016-11-23 23:50:57 +01:00
expect(this.$(), 'top-level elements').to.have.length(1);
expect(this.$('option'), 'number of options').to.have.length(3);
expect(this.$('select').val(), 'selected option value').to.equal('Etc/UTC');
});
2016-11-23 23:50:57 +01:00
it('handles an unknown timezone', function () {
this.set('activeTimezone', 'Europe/London');
2016-11-23 23:50:57 +01:00
this.render(hbs`{{gh-timezone-select
availableTimezones=availableTimezones
activeTimezone=activeTimezone}}`);
2016-11-23 23:50:57 +01:00
// we have an additional blank option at the top
expect(this.$('option'), 'number of options').to.have.length(4);
// blank option is selected
expect(this.$('select').val(), 'selected option value').to.equal('');
// we indicate the manual override
expect(this.$('p').text()).to.match(/Your timezone has been automatically set to Europe\/London/);
});
2016-11-23 23:50:57 +01:00
it('triggers update action on change', function (done) {
let update = sinon.spy();
this.set('update', update);
2016-11-23 23:50:57 +01:00
this.render(hbs`{{gh-timezone-select
availableTimezones=availableTimezones
activeTimezone=activeTimezone
update=(action update)}}`);
run(() => {
this.$('select').val('Pacific/Pago_Pago').change();
});
2016-11-23 23:50:57 +01:00
wait().then(() => {
expect(update.calledOnce, 'update was called once').to.be.true;
expect(update.firstCall.args[0].name, 'update was passed new timezone')
.to.equal('Pacific/Pago_Pago');
done();
});
2016-11-23 23:50:57 +01:00
});
2016-11-23 23:50:57 +01:00
// TODO: mock clock service, fake the time, test we have the correct
// local time and it changes alongside selection changes
it('renders local time');
});