2016-01-19 17:25:36 +03:00
|
|
|
import { expect } from 'chai';
|
|
|
|
import {
|
2016-05-05 17:03:09 +03:00
|
|
|
describeComponent,
|
|
|
|
it
|
2016-01-19 17:25:36 +03:00
|
|
|
} from 'ember-mocha';
|
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
2016-06-30 13:21:47 +03:00
|
|
|
import Service from 'ember-service';
|
2016-01-19 17:25:36 +03:00
|
|
|
import wait from 'ember-test-helpers/wait';
|
|
|
|
|
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
|
|
|
|
|
|
|
describeComponent(
|
|
|
|
'gh-feature-flag',
|
|
|
|
'Integration: Component: gh-feature-flag',
|
|
|
|
{
|
|
|
|
integration: true
|
|
|
|
},
|
|
|
|
function() {
|
|
|
|
let server;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
2016-05-05 17:03:09 +03:00
|
|
|
this.register('service:feature', featureStub);
|
|
|
|
this.inject.service('feature', {as: 'feature'});
|
2016-01-19 17:25:36 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders properties correctly', function () {
|
|
|
|
this.render(hbs`{{gh-feature-flag "testFlag"}}`);
|
|
|
|
expect(this.$()).to.have.length(1);
|
|
|
|
expect(this.$('label').attr('for')).to.equal(this.$('input[type="checkbox"]').attr('id'));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders correctly when flag is set to true', function () {
|
|
|
|
this.render(hbs`{{gh-feature-flag "testFlag"}}`);
|
|
|
|
expect(this.$()).to.have.length(1);
|
2016-05-05 17:03:09 +03:00
|
|
|
expect(this.$('label input[type="checkbox"]').prop('checked')).to.be.true;
|
2016-01-19 17:25:36 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders correctly when flag is set to false', function () {
|
2016-05-05 17:03:09 +03:00
|
|
|
this.set('feature.testFlag', false);
|
2016-01-19 17:25:36 +03:00
|
|
|
|
|
|
|
this.render(hbs`{{gh-feature-flag "testFlag"}}`);
|
|
|
|
expect(this.$()).to.have.length(1);
|
|
|
|
|
2016-05-05 17:03:09 +03:00
|
|
|
expect(this.$('label input[type="checkbox"]').prop('checked')).to.be.false;
|
2016-01-19 17:25:36 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('updates to reflect changes in flag property', function () {
|
|
|
|
this.render(hbs`{{gh-feature-flag "testFlag"}}`);
|
|
|
|
expect(this.$()).to.have.length(1);
|
|
|
|
|
2016-05-05 17:03:09 +03:00
|
|
|
expect(this.$('label input[type="checkbox"]').prop('checked')).to.be.true;
|
2016-01-19 17:25:36 +03:00
|
|
|
|
2016-05-05 17:03:09 +03:00
|
|
|
this.$('label').click();
|
2016-01-19 17:25:36 +03:00
|
|
|
|
2016-05-05 17:03:09 +03:00
|
|
|
expect(this.$('label input[type="checkbox"]').prop('checked')).to.be.false;
|
2016-01-19 17:25:36 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|