2017-08-22 10:53:26 +03:00
|
|
|
import Service from '@ember/service';
|
2017-05-29 21:50:03 +03:00
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
2019-01-02 12:58:55 +03:00
|
|
|
import {click, find, render} from '@ember/test-helpers';
|
2016-11-24 01:50:57 +03:00
|
|
|
import {describe, it} from 'mocha';
|
2017-05-29 21:50:03 +03:00
|
|
|
import {expect} from 'chai';
|
2019-01-02 12:58:55 +03:00
|
|
|
import {setupRenderingTest} from 'ember-mocha';
|
2016-01-19 17:25:36 +03:00
|
|
|
|
2016-06-11 19:52:36 +03:00
|
|
|
const featureStub = Service.extend({
|
2016-05-05 17:03:09 +03:00
|
|
|
testFlag: true
|
|
|
|
});
|
2016-01-19 17:25:36 +03:00
|
|
|
|
2018-01-05 18:38:23 +03:00
|
|
|
describe('Integration: Component: gh-feature-flag', function () {
|
2019-01-02 12:58:55 +03:00
|
|
|
setupRenderingTest();
|
2016-11-24 01:50:57 +03:00
|
|
|
|
|
|
|
beforeEach(function () {
|
2019-01-02 12:58:55 +03:00
|
|
|
this.owner.register('service:feature', featureStub);
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
it('renders properties correctly', async function () {
|
2020-01-16 18:14:03 +03:00
|
|
|
await render(hbs`<GhFeatureFlag @flag="testFlag" />`);
|
2019-01-02 12:58:55 +03:00
|
|
|
expect(find('label').getAttribute('for')).to.equal(find('input[type="checkbox"]').id);
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
it('renders correctly when flag is set to true', async function () {
|
2020-01-16 18:14:03 +03:00
|
|
|
await render(hbs`<GhFeatureFlag @flag="testFlag" />`);
|
2019-01-02 12:58:55 +03:00
|
|
|
expect(find('label input[type="checkbox"]').checked).to.be.true;
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
it('renders correctly when flag is set to false', async function () {
|
|
|
|
let feature = this.owner.lookup('service:feature');
|
|
|
|
feature.set('testFlag', false);
|
2016-11-24 01:50:57 +03:00
|
|
|
|
2020-01-16 18:14:03 +03:00
|
|
|
await render(hbs`<GhFeatureFlag @flag="testFlag" />`);
|
2019-01-02 12:58:55 +03:00
|
|
|
expect(find('label input[type="checkbox"]').checked).to.be.false;
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
it('updates to reflect changes in flag property', async function () {
|
2020-01-16 18:14:03 +03:00
|
|
|
await render(hbs`<GhFeatureFlag @flag="testFlag" />`);
|
2019-01-02 12:58:55 +03:00
|
|
|
expect(find('label input[type="checkbox"]').checked).to.be.true;
|
2016-11-24 01:50:57 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
await click('label');
|
|
|
|
expect(find('label input[type="checkbox"]').checked).to.be.false;
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
});
|