Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't export private normalize.ts function & refactor tests #171

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions ember-can/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@
"app-js": {
"./helpers/can.js": "./dist/_app_/helpers/can.js",
"./helpers/cannot.js": "./dist/_app_/helpers/cannot.js",
"./services/abilities.js": "./dist/_app_/services/abilities.js",
"./utils/normalize.js": "./dist/_app_/utils/normalize.js"
"./services/abilities.js": "./dist/_app_/services/abilities.js"
}
},
"peerDependencies": {
Expand Down
8 changes: 1 addition & 7 deletions ember-can/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,15 @@ export default {
// See https://github.com/embroider-build/embroider/blob/main/docs/v2-faq.md#how-can-i-define-the-public-exports-of-my-addon
addon.publicEntrypoints([
'index.js',
'computed.js',
'ability.ts',
'helpers/**/*.js',
'services/**/*.js',
'utils/**/*.js',
]),

// These are the modules that should get reexported into the traditional
// "app" tree. Things in here should also be in publicEntrypoints above, but
// not everything in publicEntrypoints necessarily needs to go here.
addon.appReexports([
'helpers/**/*.js',
'services/**/*.js',
'utils/**/*.js',
]),
addon.appReexports(['helpers/**/*.js', 'services/**/*.js']),

// Follow the V2 Addon rules about dependencies. Your code can import from
// `dependencies` and `peerDependencies` as well as standard Ember-provided
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion ember-can/src/services/abilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Service from '@ember/service';
import Ability, { type Model } from '../ability.ts';
import { assert } from '@ember/debug';
import { getOwner } from '@ember/application';
import normalizeAbilityString from '../utils/normalize.ts';
import normalizeAbilityString from '../-private/normalize.ts';

export default class AbilitiesService extends Service {
/**
Expand Down
23 changes: 14 additions & 9 deletions test-app/tests/addon/utils/normalize-test.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import { test, module } from 'qunit';
import { setupTest } from 'ember-qunit';
import normalize from 'ember-can/utils/normalize';

module('Addon | Util | normalize', function (hooks) {
setupTest(hooks);

test('normalizes basic combined string', function (assert) {
let norm = normalize('edit post');
const ability = this.owner.lookup('service:abilities');

let norm = ability.parse('edit post');

assert.strictEqual(norm.propertyName, 'edit');
assert.strictEqual(norm.abilityName, 'post');
});

test('always singularize abilityName', function (assert) {
let norm = normalize('edit posts');
const ability = this.owner.lookup('service:abilities');

let norm = ability.parse('edit posts');

assert.strictEqual(norm.propertyName, 'edit');
assert.strictEqual(norm.abilityName, 'post');
Expand All @@ -22,27 +25,29 @@ module('Addon | Util | normalize', function (hooks) {
test('removes stopwords from combined string', function (assert) {
let norm;

norm = normalize('manage members in project');
const ability = this.owner.lookup('service:abilities');

norm = ability.parse('manage members in project');
assert.strictEqual(norm.propertyName, 'manageMembers');
assert.strictEqual(norm.abilityName, 'project');

norm = normalize('add tags to post');
norm = ability.parse('add tags to post');
assert.strictEqual(norm.propertyName, 'addTags');
assert.strictEqual(norm.abilityName, 'post');

norm = normalize('remove tags from post');
norm = ability.parse('remove tags from post');
assert.strictEqual(norm.propertyName, 'removeTags');
assert.strictEqual(norm.abilityName, 'post');

norm = normalize('change colour of door');
norm = ability.parse('change colour of door');
assert.strictEqual(norm.propertyName, 'changeColour');
assert.strictEqual(norm.abilityName, 'door');

norm = normalize('set timezone for account');
norm = ability.parse('set timezone for account');
assert.strictEqual(norm.propertyName, 'setTimezone');
assert.strictEqual(norm.abilityName, 'account');

norm = normalize('comment on issues');
norm = ability.parse('comment on issues');
assert.strictEqual(norm.propertyName, 'comment');
assert.strictEqual(norm.abilityName, 'issue');
});
Expand Down