github.com/sl1pm4t/consul@v1.4.5-0.20190325224627-74c31c540f9c/ui-v2/tests/unit/mixins/acl/with-actions-test.js (about) 1 import { moduleFor } from 'ember-qunit'; 2 import test from 'ember-sinon-qunit/test-support/test'; 3 import { getOwner } from '@ember/application'; 4 import Service from '@ember/service'; 5 import Route from 'consul-ui/routes/dc/acls/index'; 6 7 import Mixin from 'consul-ui/mixins/acl/with-actions'; 8 9 moduleFor('mixin:acl/with-actions', 'Unit | Mixin | acl/with actions', { 10 // Specify the other units that are required for this test. 11 needs: [ 12 'mixin:with-blocking-actions', 13 'service:feedback', 14 'service:flashMessages', 15 'service:logger', 16 'service:settings', 17 'service:repository/acl', 18 ], 19 subject: function() { 20 const MixedIn = Route.extend(Mixin); 21 this.register('test-container:acl/with-actions-object', MixedIn); 22 return getOwner(this).lookup('test-container:acl/with-actions-object'); 23 }, 24 }); 25 26 // Replace this with your real tests. 27 test('it works', function(assert) { 28 const subject = this.subject(); 29 assert.ok(subject); 30 }); 31 test('use persists the token and calls transitionTo correctly', function(assert) { 32 assert.expect(4); 33 this.register( 34 'service:feedback', 35 Service.extend({ 36 execute: function(cb, name) { 37 assert.equal(name, 'use'); 38 return cb(); 39 }, 40 }) 41 ); 42 const item = { ID: 'id' }; 43 const expectedToken = { AccessorID: null, SecretID: item.ID }; 44 this.register( 45 'service:settings', 46 Service.extend({ 47 persist: function(actual) { 48 assert.deepEqual(actual.token, expectedToken); 49 return Promise.resolve(actual); 50 }, 51 }) 52 ); 53 const subject = this.subject(); 54 const expected = 'dc.services'; 55 const transitionTo = this.stub(subject, 'transitionTo').returnsArg(0); 56 return subject.actions.use 57 .bind(subject)(item) 58 .then(function(actual) { 59 assert.ok(transitionTo.calledOnce); 60 assert.equal(actual, expected); 61 }); 62 }); 63 test('clone clones the token and calls afterDelete correctly', function(assert) { 64 assert.expect(4); 65 this.register( 66 'service:feedback', 67 Service.extend({ 68 execute: function(cb, name) { 69 assert.equal(name, 'clone'); 70 return cb(); 71 }, 72 }) 73 ); 74 const expected = { ID: 'id' }; 75 this.register( 76 'service:repository/acl', 77 Service.extend({ 78 clone: function(actual) { 79 assert.deepEqual(actual, expected); 80 return Promise.resolve(actual); 81 }, 82 }) 83 ); 84 const subject = this.subject(); 85 const afterDelete = this.stub(subject, 'afterDelete').returnsArg(0); 86 return subject.actions.clone 87 .bind(subject)(expected) 88 .then(function(actual) { 89 assert.ok(afterDelete.calledOnce); 90 assert.equal(actual, expected); 91 }); 92 });