open-vault/ui/tests/integration/components/config-pki-test.js

102 lines
3.1 KiB
JavaScript
Raw Normal View History

import { resolve } from 'rsvp';
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
2018-04-03 14:16:57 +00:00
import hbs from 'htmlbars-inline-precompile';
import { create } from 'ember-cli-page-object';
import configPki from '../../pages/components/config-pki';
const component = create(configPki);
module('Integration | Component | config pki', function(hooks) {
setupRenderingTest(hooks);
hooks.beforeEach(function() {
this.owner.lookup('service:flash-messages').registerTypes(['success']);
});
2018-04-03 14:16:57 +00:00
const config = function(saveFn) {
return {
save: saveFn,
rollbackAttributes: () => {},
tidyAttrs: [
{
type: 'boolean',
name: 'tidyCertStore',
},
{
type: 'string',
name: 'anotherAttr',
},
],
crlAttrs: [
{
type: 'string',
name: 'crl',
},
],
urlsAttrs: [
{
type: 'string',
name: 'urls',
},
],
};
2018-04-03 14:16:57 +00:00
};
const setupAndRender = async function(context, section = 'tidy') {
context.set('config', config());
context.set('section', section);
await context.render(hbs`{{config-pki section=section config=config}}`);
};
2018-04-03 14:16:57 +00:00
test('it renders tidy section', async function(assert) {
await setupAndRender(this);
assert.ok(component.text.startsWith('You can tidy up the backend'));
assert.notOk(component.hasTitle, 'No title for tidy section');
assert.equal(component.fields.length, 2);
assert.ok(component.fields.objectAt(0).labelText, 'Tidy cert store');
assert.ok(component.fields.objectAt(1).labelText, 'Another attr');
});
2018-04-03 14:16:57 +00:00
test('it renders crl section', async function(assert) {
await setupAndRender(this, 'crl');
assert.ok(component.hasTitle, 'renders the title');
2019-03-30 17:07:52 +00:00
assert.equal(component.title, 'Certificate Revocation List (CRL) config');
assert.ok(component.text.startsWith('Set the duration for which the generated CRL'));
assert.equal(component.fields.length, 1);
assert.ok(component.fields.objectAt(0).labelText, 'Crl');
});
2018-04-03 14:16:57 +00:00
test('it renders urls section', async function(assert) {
await setupAndRender(this, 'urls');
assert.notOk(component.hasTitle, 'No title for urls section');
assert.equal(component.fields.length, 1);
assert.ok(component.fields.objectAt(0).labelText, 'urls');
2018-04-03 14:16:57 +00:00
});
test('it calls save with the correct arguments', async function(assert) {
assert.expect(3);
const section = 'tidy';
this.set('onRefresh', () => {
assert.ok(true, 'refresh called');
});
this.set(
'config',
config(options => {
assert.equal(options.adapterOptions.method, section, 'method passed to save');
assert.deepEqual(
options.adapterOptions.fields,
['tidyCertStore', 'anotherAttr'],
'fields passed to save'
);
return resolve();
})
);
this.set('section', section);
await render(hbs`{{config-pki section=section config=config onRefresh=onRefresh}}`);
component.submit();
});
2018-04-03 14:16:57 +00:00
});