Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

buncha new tests #545

Merged
merged 2 commits into from
Nov 11, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
39 changes: 38 additions & 1 deletion app/filters/filters.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ describe('filters', function() {

beforeEach(function() {
bard.appModule('topcoder');
bard.inject(this, 'CONSTANTS', 'roleFilter', 'percentageFilter', 'ordinalFilter', 'displayLocationFilter', 'listRolesFilter', 'trackFilter', 'challengeLinksFilter');
bard.inject(this, 'CONSTANTS', 'roleFilter', 'percentageFilter', 'ordinalFilter', 'displayLocationFilter', 'listRolesFilter', 'trackFilter', 'challengeLinksFilter', 'externalLinkColorFilter', 'emptyFilter', 'iifFilter');
domain = CONSTANTS.domain;
});

Expand Down Expand Up @@ -98,4 +98,41 @@ describe('filters', function() {
expect(challengeLinksFilter(_ch, 'registrants')).to.be.equal('https://community.'+domain+'/longcontest/?module=ViewStandings&rd=3');
});
});

describe('externalLinkColorFilter', function() {

it('should handle twitter and linkedin correctly', function() {
expect(externalLinkColorFilter('el-twitter')).to.be.equal('#62AADC');
expect(externalLinkColorFilter('el-linkedin')).to.be.equal('#127CB5');
});
});

describe('emptyFilter', function() {
it('should handle empty stuff correctly', function() {
var a = emptyFilter(0);
var b = emptyFilter(12);
var c = emptyFilter(false);
var d = emptyFilter(NaN);
var e = emptyFilter('NaN');
var f = emptyFilter('');
var g = emptyFilter('%');
expect(a).to.be.equal(0);
expect(b).to.be.equal(12);
expect(c).to.be.equal('-');
expect(d).to.be.equal('-');
expect(e).to.be.equal('-');
expect(f).to.be.equal('-');
expect(g).to.be.equal('-');
});
});

describe('iifFilter', function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took me a bit to figure out what iif meant. Should we name it something like ternary operator to avoid the acronym?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'll change it to ternary. good idea.

it('should function logically', function() {
expect(iifFilter(true, 1, 2)).to.be.equal(1);
expect(iifFilter(false, 1, 2)).to.be.equal(2);
expect(iifFilter(0, 1, 2)).to.be.equal(2);
console.log(jstz.determine().name());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftover console log :D

expect(iifFilter(true, 'm', 'n')).to.be.equal('m');
});
});
});
2 changes: 1 addition & 1 deletion app/services/profile.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
getSubTracks: getSubTracks,
getDivisions: getDivisions,

getUserHandleColor: getUserHandleColor,
getUserHandleColor: getUserHandleColor

};
return service;
Expand Down
14 changes: 14 additions & 0 deletions app/services/profile.service.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ describe('Profile Service', function() {
var subtracks = service.getSubTracks(mockStats, 'develop');
expect(subtracks.length).to.be.equal(11);
});

it('should return divisions', function() {
var divisions = service.getDivisions(mockStats);
var totalProblemsSuccessful = divisions.division1.total.problemsSuccessful;
var totalProblemsFailed = divisions.division1.total.problemsFailed;
expect(totalProblemsSuccessful).to.be.equal(2);
expect(totalProblemsFailed).to.be.equal(1);
});

it('should return user handle color', function() {
expect(service.getUserHandleColor(mockProfile.maxRating.rating)).to.be.equal('black');
});


});

});
1 change: 1 addition & 0 deletions app/settings/account-info/account-info.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
vm.saveAccountInfo = saveAccountInfo;
vm.updateCountry = updateCountry;
vm.submitNewPassword = submitNewPassword;
vm.getAddr = getAddr;

activate();

Expand Down
9 changes: 9 additions & 0 deletions app/settings/account-info/account-info.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,13 @@ describe('Account Info Controller', function() {
expect(fakeStateGo).to.have.been.calledWith('settings.profile');
});
});

describe('get address', function() {
it('should return a correct address', function() {
vm.homeAddress = {};
expect(vm.getAddr().length).to.be.equal(0);
vm.homeAddress = {streetAddr1: 'a', city: 'b', zip: 21};
expect(vm.getAddr().length).to.be.equal(1);
});
});
});
42 changes: 22 additions & 20 deletions tests/test-helpers/mock-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -1167,37 +1167,39 @@ var mockData = (function() {
function getMockProfile() {
return {
"updatedAt": null,
"createdAt": '2010-04-25T01:32:21.196+0600',
"createdAt": null,
"createdBy": null,
"updatedBy": null,
"userId": 10336829,
"firstName": "Albert",
"maxRating": {
"rating": 1616,
"track": "DEVELOP",
"subTrack": "DESIGN"
},
"lastName": "Wang",
"quote": "Competing since 2004, albertwang has achieved ratings in multiple data science, architecture, and devleopment challenge tracks. He is most skilled in component design and architecture",
"description": "Test description",
"description": null,
"otherLangName": "NIAL",
"handle": "albertwang",
"email": "[email protected]",
"addresses": [{
"updatedAt": null,
"createdAt": null,
"createdBy": null,
"updatedBy": null,
"addressId": 90263,
"streetAddr1": "123 Main Street",
"streetAddr2": "address_2",
"city": "Santa Clause",
"zip": "47579",
"stateCode": "IN",
"type": "HOME"
}],
"addresses": [
{
"streetAddr1": "123 Main Street",
"streetAddr2": "address_2",
"city": "Santa Clause",
"zip": "47579",
"stateCode": "IN",
"addressId": 90263,
"type": "Home"
}
],
"homeCountryCode": "USA",
"competitionCountryCode": "SXM",
"photo": {
"imageId": 20744540,
"photoUrl": "https://www.topcoder.com/i/m/albertwang.jpeg"
},
"competitionCountryCode": "CHN",
"photoURL": "https://topcoder-dev-media.s3.amazonaws.com/member/profile/albertwang-1440793843057.jpg",
"tracks": [
"DESIGN",
"DEVELOP",
"DATA_SCIENCE"
]
};
Expand Down