2016-07-26 13:24:37 +03:00
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
|
|
|
import sinon from 'sinon';
|
2019-01-02 12:58:55 +03:00
|
|
|
import {blur, fillIn, find, findAll, render} from '@ember/test-helpers';
|
2017-05-29 21:50:03 +03:00
|
|
|
import {describe, it} from 'mocha';
|
|
|
|
import {expect} from 'chai';
|
2019-01-02 12:58:55 +03:00
|
|
|
import {setupRenderingTest} from 'ember-mocha';
|
2016-07-26 13:24:37 +03:00
|
|
|
|
2018-01-05 18:38:23 +03:00
|
|
|
describe('Integration: Component: gh-timezone-select', function () {
|
2019-01-02 12:58:55 +03:00
|
|
|
setupRenderingTest();
|
2016-07-26 13:24:37 +03:00
|
|
|
|
2016-11-24 01:50:57 +03: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'}
|
|
|
|
]);
|
2020-06-24 17:34:59 +03:00
|
|
|
this.set('timezone', 'Etc/UTC');
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
2016-07-26 13:24:37 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
it('renders', async function () {
|
2023-01-04 12:39:32 +03:00
|
|
|
await render(hbs`<GhTimezoneSelect
|
|
|
|
@availableTimezones={{this.availableTimezones}}
|
|
|
|
@timezone={{this.timezone}}
|
|
|
|
/>`);
|
2016-07-26 13:24:37 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
expect(this.element, 'top-level elements').to.exist;
|
|
|
|
expect(findAll('option'), 'number of options').to.have.length(3);
|
|
|
|
expect(find('select').value, 'selected option value').to.equal('Etc/UTC');
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
2016-07-26 13:24:37 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
it('handles an unknown timezone', async function () {
|
2020-06-24 17:34:59 +03:00
|
|
|
this.set('timezone', 'Europe/London');
|
2016-07-26 13:24:37 +03:00
|
|
|
|
2023-01-04 12:39:32 +03:00
|
|
|
await render(hbs`<GhTimezoneSelect
|
|
|
|
@availableTimezones={{this.availableTimezones}}
|
|
|
|
@timezone={{this.timezone}}
|
|
|
|
/>`);
|
2016-07-26 13:24:37 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
// we have an additional blank option at the top
|
2019-01-02 12:58:55 +03:00
|
|
|
expect(findAll('option'), 'number of options').to.have.length(4);
|
2016-11-24 01:50:57 +03:00
|
|
|
// blank option is selected
|
2019-01-02 12:58:55 +03:00
|
|
|
expect(find('select').value, 'selected option value').to.equal('');
|
2016-11-24 01:50:57 +03:00
|
|
|
// we indicate the manual override
|
2019-01-02 12:58:55 +03:00
|
|
|
expect(find('p').textContent).to.match(/Your timezone has been automatically set to Europe\/London/);
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
2016-07-26 13:24:37 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
it('triggers update action on change', async function () {
|
2016-11-24 01:50:57 +03:00
|
|
|
let update = sinon.spy();
|
|
|
|
this.set('update', update);
|
2016-07-26 13:24:37 +03:00
|
|
|
|
2023-01-04 12:39:32 +03:00
|
|
|
await render(hbs`<GhTimezoneSelect
|
|
|
|
@availableTimezones={{this.availableTimezones}}
|
|
|
|
@timezone={{this.timezone}}
|
|
|
|
@update={{this.update}}
|
|
|
|
/>`);
|
2016-11-24 01:50:57 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
await fillIn('select', 'Pacific/Pago_Pago');
|
|
|
|
await blur('select');
|
2016-07-26 13:24:37 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
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');
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
2016-07-26 13:24:37 +03:00
|
|
|
|
2016-11-24 01:50:57 +03: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');
|
|
|
|
});
|