-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
108 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,63 @@ | ||
/* eslint-disable ember/no-classic-classes */ | ||
import EmberObject from '@ember/object'; | ||
import Service from '@ember/service'; | ||
import { module, test } from 'qunit'; | ||
import { setupTest } from 'ember-qunit'; | ||
|
||
module('Unit | Controller | submissions/index', (hooks) => { | ||
class MockConfigService extends Service { | ||
getStaticConfig() { | ||
return Promise.resolve({ branding: { stylesheet: '', pages: { faqUrl: '' } } }); | ||
} | ||
addCss() {} | ||
} | ||
|
||
module('Unit | Controller | submissions/index', function (hooks) { | ||
setupTest(hooks); | ||
|
||
hooks.beforeEach(function () { | ||
const mockStaticConfig = Service.extend({ | ||
getStaticConfig: () => | ||
Promise.resolve({ | ||
branding: { | ||
stylesheet: '', | ||
pages: { | ||
faqUrl: '', | ||
}, | ||
}, | ||
}), | ||
addCss: () => {}, | ||
}); | ||
|
||
this.owner.register('service:app-static-config', mockStaticConfig); | ||
}); | ||
this.owner.register('service:app-static-config', MockConfigService); | ||
|
||
// Replace this with your real tests. | ||
test('it exists', function (assert) { | ||
let controller = this.owner.lookup('controller:submissions/index'); | ||
assert.ok(controller); | ||
this.controller = this.owner.lookup('controller:submissions/index'); | ||
this.controller.currentUser = { user: { id: 0, isAdmin: false, isSubmitter: true } }; | ||
}); | ||
|
||
test('properly returns admin roles', function (assert) { | ||
let controller = this.owner.lookup('controller:submissions/index'); | ||
controller.set( | ||
'currentUser.user', | ||
EmberObject.create({ | ||
isAdmin: true, | ||
}) | ||
); | ||
assert.strictEqual(controller.get('columns.length'), 6); | ||
this.controller.currentUser = { user: { id: 0, isAdmin: true, isSubmitter: true } }; | ||
assert.strictEqual(this.controller.columns.length, 6, 'Should get admin columns (with 6 cols)'); | ||
}); | ||
|
||
test('properly returns submitter roles', function (assert) { | ||
let controller = this.owner.lookup('controller:submissions/index'); | ||
controller.set( | ||
'currentUser.user', | ||
EmberObject.create({ | ||
isSubmitter: true, | ||
}) | ||
); | ||
assert.strictEqual(controller.get('columns.length'), 7); | ||
assert.strictEqual(this.controller.get('columns.length'), 7, 'Should get submitter columns (with 7 cols)'); | ||
}); | ||
|
||
/** | ||
* Would be more helpful in an Acceptance test in order to check | ||
* that URL query params are also updated | ||
*/ | ||
test('displayAction updates tracked query params', function (assert) { | ||
assert.equal(this.controller.page, 1, 'Page param should have default value'); | ||
assert.equal(this.controller.pageSize, 10, 'Page size param should have default value'); | ||
|
||
this.controller.send('displayAction', { currentPageNumber: 10, pageSize: 2 }); | ||
|
||
assert.equal(this.controller.page, 10, 'Page param should be updated'); | ||
assert.equal(this.controller.pageSize, 2, 'Page size param should be updated'); | ||
}); | ||
|
||
test('doQuery makes a store query', async function (assert) { | ||
assert.expect(4); | ||
|
||
this.controller.store = { | ||
query: (model, query) => { | ||
assert.equal(model, 'submission', 'Only submissions should be queried'); | ||
assert.ok(query.page, 'Query should have pagination info'); | ||
return Promise.resolve({}); | ||
}, | ||
}; | ||
|
||
// Not called from a route's model hook, so no queued model | ||
assert.notOk(this.controller.queuedModel, 'Queued model undefined'); | ||
// Don't actually need any params sent | ||
await this.controller.doQuery({}); | ||
|
||
assert.deepEqual(this.controller.queuedModel, { submissions: {}, meta: undefined }, 'Queued model updated'); | ||
}); | ||
}); |