Skip to content
Snippets Groups Projects
Commit 33312ef0 authored by Eugen Ciur's avatar Eugen Ciur
Browse files

refactor code for testing

parent 8a2cf7ba
Branches
No related tags found
Loading
import Component from '@glimmer/component';
import group_perms_by_model from 'papermerge/utils';
class PermissionsComponent extends Component {
get permission_groups() {
let groups = this.args.permissions.map(item => item.content_type.get('model')),
result = [];
groups = new Set(groups);
groups.forEach(model => {
let perms = this.args.permissions.filter(item => item.content_type.get('model') === model);
result.push({model, perms}); // same as result.push({mode: model, perms: perms})
});
return result;
return group_perms_by_model(this.args.permissions);
}
}
......
function group_perms_by_model(permissions) {
/*
Groups permission objects by model.
`permissions` is an array of objects, each of which containas `content_type` attribute
which in turn has a `model` attribute.
Example:
Input: [
{attr_1x, attr_2x, content_type: {model: m1}},
{attr_1y, attr_2y, content_type: {model: m1}},
{attr_1z, attr_2z, content_type: {model: m1}},
{attr_1w, attr_2w, content_type: {model: m2}}
]
Output:
[
{
model: m1,
perms: [
{attr_1x, attr_2x, content_type: {model: m1}},
{attr_1y, attr_2y, content_type: {model: m1}},
{attr_1z, attr_2z, content_type: {model: m1}},
]
},
{
model: m2,
perms: [
{attr_1w, attr_2w, content_type: {model: m2}},
]
},
]
*/
let groups = permissions.map(item => item.content_type.get('model')),
result = [];
groups = new Set(groups);
groups.forEach(model => {
let perms = permissions.filter(item => item.content_type.get('model') === model);
result.push({model, perms}); // same as result.push({mode: model, perms: perms})
});
return result;
}
export default group_perms_by_model;
\ No newline at end of file
import { module, test } from 'qunit';
import { click, visit, currentURL } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
module('Acceptance | papermerge', function (hooks) {
setupApplicationTest(hooks);
test('visiting /', async function (assert) {
await visit('/');
assert.dom('nav').exists();
assert.dom('h1').hasText('Papermerge');
assert.equal(currentURL(), '/');
assert.dom('h2').hasText('Welcome to Papermerge!');
assert.dom('.jumbo a.button').hasText('About Us');
await click('.jumbo a.button');
assert.equal(currentURL(), '/about');
});
test('visiting /about', async function (assert) {
await visit('/about');
assert.dom('nav').exists();
assert.dom('h1').hasText('Papermerge');
assert.equal(currentURL(), '/about');
assert.dom('h2').hasText('About Papermerge');
assert.dom('.jumbo a.button').hasText('Contact Us');
await click('.jumbo a.button');
assert.equal(currentURL(), '/getting-in-touch');
});
test('visiting /getting-in-touch', async function (assert) {
await visit('/getting-in-touch');
assert.dom('nav').exists();
assert.dom('h1').hasText('Papermerge');
assert.equal(currentURL(), '/getting-in-touch');
assert.dom('h2').hasText('Contact Us');
assert.dom('.jumbo a.button').hasText('About');
await click('.jumbo a.button');
assert.equal(currentURL(), '/about');
});
test('navigating using the nav-bar', async function (assert) {
await visit('/');
assert.dom('nav').exists();
assert.dom('nav a.menu-index').hasText('Papermerge');
assert.dom('nav a.menu-about').hasText('About');
assert.dom('nav a.menu-contact').hasText('Contact');
await click('nav a.menu-about');
assert.equal(currentURL(), '/about');
await click('nav a.menu-contact');
assert.equal(currentURL(), '/getting-in-touch');
await click('nav a.menu-index');
assert.equal(currentURL(), '/');
});
});
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
module('Integration | Component | document', function (hooks) {
setupRenderingTest(hooks);
test('it renders', async function (assert) {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.set('myAction', function(val) { ... });
await render(hbs`<Document />`);
assert.dom(this.element).hasText('');
// Template block usage:
await render(hbs`
<Document>
template block text
</Document>
`);
assert.dom(this.element).hasText('template block text');
});
});
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
module('Integration | Component | document/detailed', function (hooks) {
setupRenderingTest(hooks);
test('it renders', async function (assert) {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.set('myAction', function(val) { ... });
await render(hbs`<Document::Detailed />`);
assert.dom(this.element).hasText('');
// Template block usage:
await render(hbs`
<Document::Detailed>
template block text
</Document::Detailed>
`);
assert.dom(this.element).hasText('template block text');
});
});
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
module('Integration | Component | document/image', function (hooks) {
setupRenderingTest(hooks);
test('it renders', async function (assert) {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.set('myAction', function(val) { ... });
await render(hbs`<Document::Image />`);
assert.dom(this.element).hasText('');
// Template block usage:
await render(hbs`
<Document::Image>
template block text
</Document::Image>
`);
assert.dom(this.element).hasText('template block text');
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment