From d7aaadea2b8beda40200b4e53cf29840477398a3 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sun, 14 May 2017 16:16:12 +0200 Subject: [PATCH 1/3] Only show conributors with Kredits in list --- app/controllers/index.js | 8 ++++- tests/unit/controllers/index-test.js | 48 ++++++++++++++++++++++------ 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/app/controllers/index.js b/app/controllers/index.js index e609095..627c78c 100644 --- a/app/controllers/index.js +++ b/app/controllers/index.js @@ -43,8 +43,14 @@ export default Ember.Controller.extend({ proposalsClosedSorted: Ember.computed.sort('proposalsClosed', 'proposalsSorting'), proposalsOpenSorted: Ember.computed.sort('proposalsOpen', 'proposalsSorting'), + contributorsWithKredits: function() { + return this.get('model.contributors').filter(c => { + return c.get('kredits') !== 0; + }); + }.property('model.contributors.[]'), + contributorsSorting: ['kredits:desc'], - contributorsSorted: Ember.computed.sort('model.contributors', 'contributorsSorting'), + contributorsSorted: Ember.computed.sort('contributorsWithKredits', 'contributorsSorting'), watchContractEvents: function() { let events = this.get('kredits.kreditsContract') diff --git a/tests/unit/controllers/index-test.js b/tests/unit/controllers/index-test.js index eaa06c8..6bd8af9 100644 --- a/tests/unit/controllers/index-test.js +++ b/tests/unit/controllers/index-test.js @@ -1,11 +1,39 @@ -// import { moduleFor, test } from 'ember-qunit'; -// -// moduleFor('controller:index', 'Unit | Controller | index'); +import Ember from 'ember'; +import Contributor from 'kredits-web/models/contributor'; +import { moduleFor, test } from 'ember-qunit'; -// let addFixtures = function(controller) { -// controller.set('model', { contributors: [ -// { github_username: "neo", github_uid: "318", kredits: 10000 }, -// { github_username: "morpheus", github_uid: "843", kredits: 15000 }, -// { github_username: "mouse", github_uid: "842", kredits: 5000 }, -// ]}); -// }; +const { + isPresent, + isEmpty +} = Ember; + +moduleFor('controller:index', 'Unit | Controller | index', { + needs: ['service:ipfs', 'service:kredits'] +}); + +let addFixtures = function(controller) { + controller.set('model', { + contributors: [], + proposals: [] + }); + + [ + { github_username: "neo", github_uid: "318", kredits: 10000 }, + { github_username: "morpheus", github_uid: "843", kredits: 15000 }, + { github_username: "trinity", github_uid: "123", kredits: 5000 }, + { github_username: "mouse", github_uid: "696", kredits: 0 } + ].forEach(fixture => { + controller.get('model.contributors').push(Contributor.create(fixture)); + }); +}; + +test('doesn\'t contain people with 0 kredits', function(assert) { + let controller = this.subject(); + addFixtures(controller); + + let contributorsSorted = controller.get('contributorsSorted'); + console.log(controller.get('contributorsSorted')); + + assert.ok(isPresent(contributorsSorted.findBy('github_username', 'neo'))); + assert.ok(isEmpty(contributorsSorted.findBy('github_username', 'mouse'))); +}); -- 2.50.1 From 2405e3e118c3a4881bc9f18d7cee2afece259f7a Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sun, 14 May 2017 16:25:02 +0200 Subject: [PATCH 2/3] Show correct number for kredits distribution --- app/routes/index.js | 1 - app/templates/index.hbs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/routes/index.js b/app/routes/index.js index df8da39..ada98a1 100644 --- a/app/routes/index.js +++ b/app/routes/index.js @@ -10,7 +10,6 @@ export default Ember.Route.extend({ return Ember.RSVP.hash({ contributors: kredits.getContributors(), totalSupply: kredits.getValueFromContract('tokenContract', 'totalSupply'), - contributorsCount: kredits.getValueFromContract('kreditsContract', 'contributorsCount'), proposals: kredits.getProposals() }); } diff --git a/app/templates/index.hbs b/app/templates/index.hbs index d995bbf..18a524d 100644 --- a/app/templates/index.hbs +++ b/app/templates/index.hbs @@ -8,7 +8,7 @@

{{model.totalSupply}} kredits issued and distributed among - {{model.contributorsCount}} contributors. + {{contributorsWithKredits.length}} contributors.

-- 2.50.1 From 4f57ceaee9699fa473bd3e110465371879b27c3a Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sun, 14 May 2017 16:27:43 +0200 Subject: [PATCH 3/3] Remove debug log statement --- tests/unit/controllers/index-test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/unit/controllers/index-test.js b/tests/unit/controllers/index-test.js index 6bd8af9..ca30faa 100644 --- a/tests/unit/controllers/index-test.js +++ b/tests/unit/controllers/index-test.js @@ -32,7 +32,6 @@ test('doesn\'t contain people with 0 kredits', function(assert) { addFixtures(controller); let contributorsSorted = controller.get('contributorsSorted'); - console.log(controller.get('contributorsSorted')); assert.ok(isPresent(contributorsSorted.findBy('github_username', 'neo'))); assert.ok(isEmpty(contributorsSorted.findBy('github_username', 'mouse'))); -- 2.50.1