Ghost/ghost/admin/tests/integration/components/gh-feature-flag-test.js

45 lines
1.6 KiB
JavaScript
Raw Normal View History

import Service from '@ember/service';
import hbs from 'htmlbars-inline-precompile';
import {click, find, render} from '@ember/test-helpers';
2016-11-24 01:50:57 +03:00
import {describe, it} from 'mocha';
import {expect} from 'chai';
import {setupRenderingTest} from 'ember-mocha';
const featureStub = Service.extend({
testFlag: true
});
describe('Integration: Component: gh-feature-flag', function () {
setupRenderingTest();
2016-11-24 01:50:57 +03:00
beforeEach(function () {
this.owner.register('service:feature', featureStub);
2016-11-24 01:50:57 +03:00
});
it('renders properties correctly', async function () {
await render(hbs`<GhFeatureFlag @flag="testFlag" />`);
expect(find('label').getAttribute('for')).to.equal(find('input[type="checkbox"]').id);
2016-11-24 01:50:57 +03:00
});
it('renders correctly when flag is set to true', async function () {
await render(hbs`<GhFeatureFlag @flag="testFlag" />`);
expect(find('label input[type="checkbox"]').checked).to.be.true;
2016-11-24 01:50:57 +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
await render(hbs`<GhFeatureFlag @flag="testFlag" />`);
expect(find('label input[type="checkbox"]').checked).to.be.false;
2016-11-24 01:50:57 +03:00
});
it('updates to reflect changes in flag property', async function () {
await render(hbs`<GhFeatureFlag @flag="testFlag" />`);
expect(find('label input[type="checkbox"]').checked).to.be.true;
2016-11-24 01:50:57 +03:00
await click('label');
expect(find('label input[type="checkbox"]').checked).to.be.false;
2016-11-24 01:50:57 +03:00
});
});