From 8ece18fcc747c2ee6d56ec1512261293c9e444bd Mon Sep 17 00:00:00 2001 From: Eugen Ciur <eugen@papermerge.com> Date: Mon, 11 Oct 2021 07:56:27 +0200 Subject: [PATCH] add basic acceptance test for tags. Linting. --- app/adapters/application.js | 2 +- app/components/automates/add.js | 32 +++--- app/components/button/cancel.js | 5 +- app/components/button/link.hbs | 3 +- app/components/button/new.js | 5 +- app/components/button/submit.js | 5 +- app/components/group/new.js | 16 +-- app/components/group/table_row.js | 9 +- app/components/permission.js | 1 - app/components/permissions/index.js | 3 - app/components/role/add.js | 3 +- app/components/select/index.js | 4 +- app/components/tag/new.js | 30 +++--- app/components/tag/table_row.hbs | 6 +- app/components/tag/table_row.js | 13 +-- app/helpers/is_equal.js | 3 +- app/models/automate.js | 1 - app/models/content_type.js | 1 - app/models/group.js | 1 - app/models/node.js | 1 - app/models/permission.js | 1 - app/models/role.js | 1 - app/models/tag.js | 1 - app/router.js | 8 +- app/routes/automates/index.js | 1 - app/routes/groups.js | 1 - app/routes/roles/add.js | 1 - app/routes/roles/index.js | 1 - app/routes/tags.js | 1 - app/templates/automates/index.hbs | 4 +- app/templates/roles/index.hbs | 4 +- app/utils/index.js | 16 ++- ember-cli-build.js | 2 +- tests/acceptance/tags-test.js | 13 +++ tests/unit/utils-test.js | 160 +++++++++++++--------------- 35 files changed, 161 insertions(+), 198 deletions(-) create mode 100644 tests/acceptance/tags-test.js diff --git a/app/adapters/application.js b/app/adapters/application.js index debb34f..58e2f79 100644 --- a/app/adapters/application.js +++ b/app/adapters/application.js @@ -2,7 +2,7 @@ import JSONAPIAdapter from '@ember-data/adapter/json-api'; export default class ApplicationAdapter extends JSONAPIAdapter { namespace = 'api'; - host = "http://127.0.0.1:8000" + host = 'http://127.0.0.1:8000'; buildURL(...args) { return `${super.buildURL(...args)}/`; diff --git a/app/components/automates/add.js b/app/components/automates/add.js index 9c3ff25..31891dc 100644 --- a/app/components/automates/add.js +++ b/app/components/automates/add.js @@ -3,7 +3,6 @@ import { action } from '@ember/object'; import { tracked } from '@glimmer/tracking'; import { inject as service } from '@ember/service'; - class AddAutomateComponent extends Component { /* Form like component to create new automate. @@ -20,21 +19,21 @@ class AddAutomateComponent extends Component { get dst_folder_options() { return [ - {'key': '---', 'value': '---'}, - {'key': '1', 'value': 'My Documents'}, - {'key': '2', 'value': 'XXX Some Folder'}, - {'key': '3', 'value': 'Invoices'} - ] + { key: '---', value: '---' }, + { key: '1', value: 'My Documents' }, + { key: '2', value: 'XXX Some Folder' }, + { key: '3', value: 'Invoices' }, + ]; } get matching_alg_options() { return [ - {'key': '---', 'value': '---'}, - {'key': '1', 'value': 'Any'}, - {'key': '2', 'value': 'All'}, - {'key': '3', 'value': 'Literal'}, - {'key': '4', 'value': 'Regular Expression'} - ] + { key: '---', value: '---' }, + { key: '1', value: 'Any' }, + { key: '2', value: 'All' }, + { key: '3', value: 'Literal' }, + { key: '4', value: 'Regular Expression' }, + ]; } @action @@ -50,13 +49,10 @@ class AddAutomateComponent extends Component { match: this.match, dst_folder: this.dst_folder, is_case_sensitive: this.is_case_sensitive, - matching_algorithm: this.matching_alg + matching_algorithm: this.matching_alg, }; - this.store.createRecord( - 'automate', - automate - ).save(); + this.store.createRecord('automate', automate).save(); this.router.transitionTo('automates'); } @@ -72,4 +68,4 @@ class AddAutomateComponent extends Component { } } -export default AddAutomateComponent; \ No newline at end of file +export default AddAutomateComponent; diff --git a/app/components/button/cancel.js b/app/components/button/cancel.js index 625e4c8..c29dfc7 100644 --- a/app/components/button/cancel.js +++ b/app/components/button/cancel.js @@ -1,6 +1,5 @@ import Component from '@glimmer/component'; - class ButtonCancelComponent extends Component { /* "Cancel Button" component. Renders a button as either @@ -25,8 +24,8 @@ class ButtonCancelComponent extends Component { */ get text() { - return this.args.text || "Cancel"; + return this.args.text || 'Cancel'; } } -export default ButtonCancelComponent; \ No newline at end of file +export default ButtonCancelComponent; diff --git a/app/components/button/link.hbs b/app/components/button/link.hbs index fb69410..77bb773 100644 --- a/app/components/button/link.hbs +++ b/app/components/button/link.hbs @@ -1,5 +1,4 @@ <button - class="btn btn-link" - {{on "click" @onClick}}> + class="btn btn-link" type="button" {{on "click" @onClick}}> {{@text}} </button> \ No newline at end of file diff --git a/app/components/button/new.js b/app/components/button/new.js index 5804c4d..d21328c 100644 --- a/app/components/button/new.js +++ b/app/components/button/new.js @@ -1,6 +1,5 @@ import Component from '@glimmer/component'; - class ButtonNewComponent extends Component { /* "New Button" component. Renders a button as either @@ -25,8 +24,8 @@ class ButtonNewComponent extends Component { */ get text() { - return this.args.text || "New"; + return this.args.text || 'New'; } } -export default ButtonNewComponent; \ No newline at end of file +export default ButtonNewComponent; diff --git a/app/components/button/submit.js b/app/components/button/submit.js index ca3bdad..3c0e045 100644 --- a/app/components/button/submit.js +++ b/app/components/button/submit.js @@ -33,9 +33,8 @@ class ButtonSubmitComponent extends Component { */ get text() { - return this.args.text || "Submit"; + return this.args.text || 'Submit'; } - } -export default ButtonSubmitComponent; \ No newline at end of file +export default ButtonSubmitComponent; diff --git a/app/components/group/new.js b/app/components/group/new.js index ef3c497..2d2c36e 100644 --- a/app/components/group/new.js +++ b/app/components/group/new.js @@ -3,23 +3,23 @@ import { action } from '@ember/object'; import { tracked } from '@glimmer/tracking'; import { inject as service } from '@ember/service'; - export default class NewGroupComponent extends Component { - @service store; @tracked form_visible = false; - @tracked new_name = ""; + @tracked new_name = ''; @action onToggleNew() { - this.form_visible = !this.form_visible; + this.form_visible = !this.form_visible; } @action onCreate() { - this.store.createRecord('group', { + this.store + .createRecord('group', { name: this.new_name, - }).save(); + }) + .save(); this._empty_form(); } @@ -33,7 +33,7 @@ export default class NewGroupComponent extends Component { /* Resets the form to initial state */ - this.new_name = ""; + this.new_name = ''; this.form_visible = false; } -} \ No newline at end of file +} diff --git a/app/components/group/table_row.js b/app/components/group/table_row.js index 8bc19e2..b2197d3 100644 --- a/app/components/group/table_row.js +++ b/app/components/group/table_row.js @@ -3,7 +3,6 @@ import { tracked } from '@glimmer/tracking'; import { action } from '@ember/object'; import { inject as service } from '@ember/service'; - class TableRowComponent extends Component { // keeps track of the ID of the group currently // being edited i.e. in edit mode @@ -30,16 +29,14 @@ class TableRowComponent extends Component { let that = this; if (!group) { - console.warn( - "onSaveChanges received an undefined group object" - ); + console.warn('onSaveChanges received an undefined group object'); return; } this.edit_mode_id = undefined; if (group.id) { - this.store.findRecord('group', group.id).then(found_group => { + this.store.findRecord('group', group.id).then((found_group) => { found_group.name = group.name; found_group.save(); }); @@ -52,4 +49,4 @@ class TableRowComponent extends Component { } } -export default TableRowComponent; \ No newline at end of file +export default TableRowComponent; diff --git a/app/components/permission.js b/app/components/permission.js index d4b86ce..acda60d 100644 --- a/app/components/permission.js +++ b/app/components/permission.js @@ -3,7 +3,6 @@ import { tracked } from '@glimmer/tracking'; import { action } from '@ember/object'; import { inject as service } from '@ember/service'; - class PermissionComponent extends Component { @service store; diff --git a/app/components/permissions/index.js b/app/components/permissions/index.js index fae46f5..99f5681 100644 --- a/app/components/permissions/index.js +++ b/app/components/permissions/index.js @@ -1,10 +1,7 @@ import Component from '@glimmer/component'; import { group_perms_by_model } from 'papermerge/utils'; - - class PermissionsComponent extends Component { - get permission_groups() { return group_perms_by_model(this.args.permissions); } diff --git a/app/components/role/add.js b/app/components/role/add.js index 6ac4b87..f0be54b 100644 --- a/app/components/role/add.js +++ b/app/components/role/add.js @@ -4,12 +4,11 @@ import { tracked } from '@glimmer/tracking'; import { A } from '@ember/array'; import { inject as service } from '@ember/service'; - class AddRoleComponent extends Component { @service store; @service router; - @tracked name = ""; + @tracked name = ''; permissions = A([]); @action diff --git a/app/components/select/index.js b/app/components/select/index.js index 173b5da..cbdc857 100644 --- a/app/components/select/index.js +++ b/app/components/select/index.js @@ -7,9 +7,9 @@ class SelectComponent extends Component { @action onChange(event) { - console.log("On change!"); + console.log('On change!'); this.args.onChange(event); } } -export default SelectComponent; \ No newline at end of file +export default SelectComponent; diff --git a/app/components/tag/new.js b/app/components/tag/new.js index 27b8cdb..a4e7bd0 100644 --- a/app/components/tag/new.js +++ b/app/components/tag/new.js @@ -3,7 +3,6 @@ import { action } from '@ember/object'; import { tracked } from '@glimmer/tracking'; import { inject as service } from '@ember/service'; - const COLORS = [ '#ff0000', '#0000ff', @@ -21,14 +20,11 @@ function _random_color() { Color strings are RGB strings like for example "#ff0000", "#ff7892", "#ffffff" */ - let index = Math.floor( - Math.random() * COLORS.length - ); + let index = Math.floor(Math.random() * COLORS.length); return COLORS[index]; } - export default class NewTagComponent extends Component { /* Component to create new tag. @@ -41,26 +37,28 @@ export default class NewTagComponent extends Component { // initially only 'new' button is visible @tracked form_visible = false; - @tracked new_name = ""; - @tracked new_description = ""; + @tracked new_name = ''; + @tracked new_description = ''; @tracked new_pinned = false; - @tracked new_fg_color = "#ffffff"; + @tracked new_fg_color = '#ffffff'; @tracked new_bg_color = _random_color(); @action onToggleNew() { - this.form_visible = !this.form_visible; + this.form_visible = !this.form_visible; } @action onCreate() { - this.store.createRecord('tag', { + this.store + .createRecord('tag', { name: this.new_name, description: this.new_description, pinned: this.new_pinned, bg_color: this.new_bg_color, - fg_color: this.new_fg_color - }).save(); + fg_color: this.new_fg_color, + }) + .save(); this._empty_form(); } @@ -74,11 +72,11 @@ export default class NewTagComponent extends Component { /* Resets the form to initial state */ - this.new_name = ""; - this.new_description = ""; - this.new_fg_color = "#ffffff"; + this.new_name = ''; + this.new_description = ''; + this.new_fg_color = '#ffffff'; this.new_bg_color = _random_color(); this.new_pinned = false; this.form_visible = false; } -} \ No newline at end of file +} diff --git a/app/components/tag/table_row.hbs b/app/components/tag/table_row.hbs index f6ba15f..339e21a 100644 --- a/app/components/tag/table_row.hbs +++ b/app/components/tag/table_row.hbs @@ -29,7 +29,7 @@ class="form-control" /> </td> <td> - <button class="btn btn-secondary" {{on "click" (fn this.onCancel)}}> + <button class="btn btn-secondary" type="button" {{on "click" this.onCancel}}> Cancel </button> <button @@ -51,10 +51,10 @@ </td> <td>{{@tag.description}}</td> <td> - <button class="btn btn-link" {{on "click" (fn this.onEdit @tag)}}> + <button class="btn btn-link" type="button" {{on "click" (fn this.onEdit @tag)}}> Edit </button> - <button class="btn btn-link" {{on "click" (fn this.onRemove @tag)}}> + <button class="btn btn-link" type="button" {{on "click" (fn this.onRemove @tag)}}> Remove </button> </td> diff --git a/app/components/tag/table_row.js b/app/components/tag/table_row.js index c93ec7d..5c97148 100644 --- a/app/components/tag/table_row.js +++ b/app/components/tag/table_row.js @@ -3,7 +3,6 @@ import { tracked } from '@glimmer/tracking'; import { action } from '@ember/object'; import { inject as service } from '@ember/service'; - export default class TableRowComponent extends Component { // keeps track of the ID of the tag currently // being edited i.e. in edit mode @@ -30,25 +29,21 @@ export default class TableRowComponent extends Component { let that = this; if (!tag) { - console.warn( - "onSaveChanges received an undefined tag object" - ); + console.warn('onSaveChanges received an undefined tag object'); return; } this.edit_mode_id = undefined; if (tag.id) { - this.store.findRecord('tag', tag.id).then(found_tag => { + this.store.findRecord('tag', tag.id).then((found_tag) => { found_tag.name = tag.name; found_tag.description = tag.description; found_tag.save(); }); } else { - console.warn( - `onSaveChanges received tag=${tag} object without tag ID` - ); + console.warn(`onSaveChanges received tag=${tag} object without tag ID`); return; } } -} \ No newline at end of file +} diff --git a/app/helpers/is_equal.js b/app/helpers/is_equal.js index 697cfdd..84c9bad 100644 --- a/app/helpers/is_equal.js +++ b/app/helpers/is_equal.js @@ -1,9 +1,8 @@ import { helper } from '@ember/component/helper'; import { isEqual as emberIsEqual } from '@ember/utils'; - export function is_equal([a, b]) { return emberIsEqual(a, b); } -export default helper(is_equal); \ No newline at end of file +export default helper(is_equal); diff --git a/app/models/automate.js b/app/models/automate.js index e908b67..6ed85b1 100644 --- a/app/models/automate.js +++ b/app/models/automate.js @@ -1,6 +1,5 @@ import Model, { attr, hasMany } from '@ember-data/model'; - export default class AutomateModel extends Model { @attr name; @attr match; diff --git a/app/models/content_type.js b/app/models/content_type.js index b0a1f60..c5b500e 100644 --- a/app/models/content_type.js +++ b/app/models/content_type.js @@ -1,6 +1,5 @@ import Model, { attr, hasMany } from '@ember-data/model'; - class ContentTypeModel extends Model { @attr model; @hasMany('permission') permissions; diff --git a/app/models/group.js b/app/models/group.js index 1ea5b29..5e1589c 100644 --- a/app/models/group.js +++ b/app/models/group.js @@ -1,6 +1,5 @@ import Model, { attr } from '@ember-data/model'; - class GroupModel extends Model { @attr name; } diff --git a/app/models/node.js b/app/models/node.js index e0650b5..031dac3 100644 --- a/app/models/node.js +++ b/app/models/node.js @@ -1,6 +1,5 @@ import Model, { attr, hasMany, belongsTo } from '@ember-data/model'; - export default class NodeModel extends Model { @attr title; @attr model; diff --git a/app/models/permission.js b/app/models/permission.js index 8340fa6..259e088 100644 --- a/app/models/permission.js +++ b/app/models/permission.js @@ -1,6 +1,5 @@ import Model, { attr, belongsTo } from '@ember-data/model'; - class PermissionModel extends Model { @attr name; @attr codename; diff --git a/app/models/role.js b/app/models/role.js index dad505e..2e6d6f4 100644 --- a/app/models/role.js +++ b/app/models/role.js @@ -1,6 +1,5 @@ import Model, { attr, hasMany } from '@ember-data/model'; - class RoleModel extends Model { @attr name; @hasMany('permissions') permissions; diff --git a/app/models/tag.js b/app/models/tag.js index 599e57e..771ce73 100644 --- a/app/models/tag.js +++ b/app/models/tag.js @@ -1,6 +1,5 @@ import Model, { attr } from '@ember-data/model'; - class TagModel extends Model { @attr name; @attr fg_color; diff --git a/app/router.js b/app/router.js index 0434fa7..e3b1d65 100644 --- a/app/router.js +++ b/app/router.js @@ -1,13 +1,11 @@ import EmberRouter from '@ember/routing/router'; import config from 'papermerge/config/environment'; - export default class Router extends EmberRouter { location = config.locationType; rootURL = config.rootURL; } - Router.map(function () { this.route('documents'); this.route('inbox'); @@ -17,19 +15,19 @@ Router.map(function () { this.route('tags'); - this.route('users', function() { + this.route('users', function () { this.route('add'); this.route('edit', { path: '/:user_id/edit' }); this.route('index', { path: '/' }); }); - this.route('roles', function() { + this.route('roles', function () { this.route('add'); this.route('edit', { path: '/:role_id/edit' }); this.route('index', { path: '/' }); }); - this.route('groups', function() { + this.route('groups', function () { this.route('index', { path: '/' }); }); diff --git a/app/routes/automates/index.js b/app/routes/automates/index.js index bb83b1c..fabb802 100644 --- a/app/routes/automates/index.js +++ b/app/routes/automates/index.js @@ -1,7 +1,6 @@ import Route from '@ember/routing/route'; import { inject as service } from '@ember/service'; - export default class AutomatesRoute extends Route { @service store; diff --git a/app/routes/groups.js b/app/routes/groups.js index db71a0e..258df0b 100644 --- a/app/routes/groups.js +++ b/app/routes/groups.js @@ -1,7 +1,6 @@ import Route from '@ember/routing/route'; import { inject as service } from '@ember/service'; - export default class GroupsRoute extends Route { @service store; diff --git a/app/routes/roles/add.js b/app/routes/roles/add.js index 9a16567..50b38dd 100644 --- a/app/routes/roles/add.js +++ b/app/routes/roles/add.js @@ -1,7 +1,6 @@ import Route from '@ember/routing/route'; import { inject as service } from '@ember/service'; - class AddRoleRoute extends Route { @service store; diff --git a/app/routes/roles/index.js b/app/routes/roles/index.js index 11a62c6..757a7d6 100644 --- a/app/routes/roles/index.js +++ b/app/routes/roles/index.js @@ -1,7 +1,6 @@ import Route from '@ember/routing/route'; import { inject as service } from '@ember/service'; - class RolesRoute extends Route { @service store; diff --git a/app/routes/tags.js b/app/routes/tags.js index f4518b6..615910e 100644 --- a/app/routes/tags.js +++ b/app/routes/tags.js @@ -1,7 +1,6 @@ import Route from '@ember/routing/route'; import { inject as service } from '@ember/service'; - export default class TagsRoute extends Route { @service store; diff --git a/app/templates/automates/index.hbs b/app/templates/automates/index.hbs index 4c77266..5a00ea4 100644 --- a/app/templates/automates/index.hbs +++ b/app/templates/automates/index.hbs @@ -27,9 +27,9 @@ ... </td> <td> - <button class="btn btn-link"> Edit + <button class="btn btn-link" type="button"> Edit </button> - <button class="btn btn-link">Remove</button> + <button class="btn btn-link" type="button">Remove</button> </td> </tr> {{/each}} diff --git a/app/templates/roles/index.hbs b/app/templates/roles/index.hbs index 21a9c15..c8c3ed6 100644 --- a/app/templates/roles/index.hbs +++ b/app/templates/roles/index.hbs @@ -23,9 +23,9 @@ {{role.updated_at}} </td> <td> - <button class="btn btn-link"> Edit + <button class="btn btn-link" type="button"> Edit </button> - <button class="btn btn-link">Remove</button> + <button class="btn btn-link" type="button">Remove</button> </td> </tr> {{/each}} diff --git a/app/utils/index.js b/app/utils/index.js index a81c844..9a61eb6 100644 --- a/app/utils/index.js +++ b/app/utils/index.js @@ -1,4 +1,3 @@ - function group_perms_by_model(permissions) { /* Groups an array of permissions objects by model. @@ -31,16 +30,16 @@ function group_perms_by_model(permissions) { }, ] */ - let groups = permissions.map(item => item.content_type.get('model')), + let groups = permissions.map((item) => item.content_type.get('model')), result = []; groups = new Set(groups); - groups.forEach(model => { + groups.forEach((model) => { let perms = permissions.filter( - item => item.content_type.get('model') === model + (item) => item.content_type.get('model') === model ); - result.push({model, perms}); // same as result.push({mode: model, perms: perms}) + result.push({ model, perms }); // same as result.push({mode: model, perms: perms}) }); return result; @@ -56,12 +55,9 @@ function are_sets_equal(set1, set2) { let same_size, same_values; same_size = (a, b) => a.size === b.size; - same_values = (a, b) => [...a].every(value => b.has(value)); + same_values = (a, b) => [...a].every((value) => b.has(value)); return same_size(set1, set2) && same_values(set1, set2); } -export { - group_perms_by_model, - are_sets_equal -}; \ No newline at end of file +export { group_perms_by_model, are_sets_equal }; diff --git a/ember-cli-build.js b/ember-cli-build.js index 3cbb475..62d593a 100644 --- a/ember-cli-build.js +++ b/ember-cli-build.js @@ -11,7 +11,7 @@ module.exports = function (defaults) { app.import('node_modules/bootstrap-icons/font/bootstrap-icons.css'); // There is a type in fontawesome NPM's namespace. // It is '@fortawesome' instead of '@fontawesome'! - app.import("node_modules/@fortawesome/fontawesome-free/css/all.css"); + app.import('node_modules/@fortawesome/fontawesome-free/css/all.css'); // If you need to use different assets in different // environments, specify an object as the first parameter. That // object's keys should be the environment name and the values diff --git a/tests/acceptance/tags-test.js b/tests/acceptance/tags-test.js new file mode 100644 index 0000000..9220702 --- /dev/null +++ b/tests/acceptance/tags-test.js @@ -0,0 +1,13 @@ +import { module, test } from 'qunit'; +import { visit, currentURL } from '@ember/test-helpers'; +import { setupApplicationTest } from 'ember-qunit'; + +module('Acceptance | tags', function (hooks) { + setupApplicationTest(hooks); + + test('visiting /tags', async function (assert) { + await visit('/tags'); + + assert.equal(currentURL(), '/tags'); + }); +}); diff --git a/tests/unit/utils-test.js b/tests/unit/utils-test.js index b52ab04..91a15db 100644 --- a/tests/unit/utils-test.js +++ b/tests/unit/utils-test.js @@ -1,8 +1,5 @@ import { module, test } from 'qunit'; -import { - are_sets_equal, - group_perms_by_model -} from 'papermerge/utils'; +import { are_sets_equal, group_perms_by_model } from 'papermerge/utils'; class FakeContentType { constructor(name) { @@ -14,10 +11,8 @@ class FakeContentType { } } - -module('Unit | Utility', function() { - - test('are_sets_qual', function(assert) { +module('Unit | Utility', function () { + test('are_sets_qual', function (assert) { let set1, set2; set1 = new Set([8, 1]); @@ -37,80 +32,77 @@ module('Unit | Utility', function() { ); }); - test('group_perms_by_model', function(assert) { - let grouped_permissions, - permissions, - expected_result, - models, - expected_models, - areSetsEqual; - - permissions = [ - { - attr_1x: 'attr_1x', - attr_2x: 'attr_2x', - content_type: new FakeContentType('m1') - }, - { - attr_1y: 'attr_1y', - attr_2y: 'attr_2y', - content_type: new FakeContentType('m1') - }, - { - attr_1z: 'attr_1z', - attr_2z: 'attr_2z', - content_type: new FakeContentType('m1') - }, - { - attr_1w: 'attr_1w', - attr_2w: 'attr_2w', - content_type: new FakeContentType('m2') - }, - ]; - - expected_result = [ - { - model: new FakeContentType('m1'), - perms: [ - { - attr_1x: 'attr_1x', - attr_2x: 'attr_2x', - content_type: new FakeContentType('m1') - }, - { - attr_1y: 'attr_1y', - attr_2y: 'attr_2y', - content_type: new FakeContentType('m1') - }, - { - attr_1z: 'attr_1z', - attr_2z: 'attr_2z', - content_type: new FakeContentType('m1') - }, - ] - }, - { - model: new FakeContentType('m2'), - perms: [ - { - attr_1w: 'attr_1w', - attr_2w: 'attr_2w', - content_type: new FakeContentType('m2') - }, - ] - } - ]; - - grouped_permissions = group_perms_by_model(permissions); - - assert.strictEqual( - grouped_permissions.length, expected_result.length - ); - - models = new Set(grouped_permissions.map(item => item.model)); - expected_models = new Set(['m1', 'm2']); - - assert.true(are_sets_equal(models, expected_models)); - + test('group_perms_by_model', function (assert) { + let grouped_permissions, + permissions, + expected_result, + models, + expected_models, + areSetsEqual; + + permissions = [ + { + attr_1x: 'attr_1x', + attr_2x: 'attr_2x', + content_type: new FakeContentType('m1'), + }, + { + attr_1y: 'attr_1y', + attr_2y: 'attr_2y', + content_type: new FakeContentType('m1'), + }, + { + attr_1z: 'attr_1z', + attr_2z: 'attr_2z', + content_type: new FakeContentType('m1'), + }, + { + attr_1w: 'attr_1w', + attr_2w: 'attr_2w', + content_type: new FakeContentType('m2'), + }, + ]; + + expected_result = [ + { + model: new FakeContentType('m1'), + perms: [ + { + attr_1x: 'attr_1x', + attr_2x: 'attr_2x', + content_type: new FakeContentType('m1'), + }, + { + attr_1y: 'attr_1y', + attr_2y: 'attr_2y', + content_type: new FakeContentType('m1'), + }, + { + attr_1z: 'attr_1z', + attr_2z: 'attr_2z', + content_type: new FakeContentType('m1'), + }, + ], + }, + { + model: new FakeContentType('m2'), + perms: [ + { + attr_1w: 'attr_1w', + attr_2w: 'attr_2w', + content_type: new FakeContentType('m2'), + }, + ], + }, + ]; + + grouped_permissions = group_perms_by_model(permissions); + + assert.strictEqual(grouped_permissions.length, expected_result.length); + + models = new Set(grouped_permissions.map((item) => item.model)); + expected_models = new Set(['m1', 'm2']); + + assert.true(are_sets_equal(models, expected_models)); }); -}); \ No newline at end of file +}); -- GitLab