Add tests for the sortUsers method
This commit is contained in:
parent
e54409b3dd
commit
6495f1769e
@ -41,13 +41,14 @@
|
||||
"socket.io": "1.4.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"stylelint": "4.3.3",
|
||||
"chai": "3.5.0",
|
||||
"eslint": "2.3.0",
|
||||
"grunt": "0.4.5",
|
||||
"grunt-cli": "0.1.13",
|
||||
"grunt-contrib-uglify": "0.11.1",
|
||||
"grunt-contrib-watch": "0.6.1",
|
||||
"handlebars": "4.0.5",
|
||||
"mocha": "2.4.5"
|
||||
"mocha": "2.4.5",
|
||||
"stylelint": "4.3.3"
|
||||
}
|
||||
}
|
||||
|
80
test/models/chan.js
Normal file
80
test/models/chan.js
Normal file
@ -0,0 +1,80 @@
|
||||
"use strict";
|
||||
|
||||
var expect = require("chai").expect;
|
||||
|
||||
var Chan = require("../../src/models/chan");
|
||||
var User = require("../../src/models/user");
|
||||
|
||||
function makeUser(name, mode) {
|
||||
return new User({name: name, mode: mode});
|
||||
}
|
||||
|
||||
function getUserNames(chan) {
|
||||
return chan.users.map(function(u) { return u.name; });
|
||||
}
|
||||
|
||||
describe("Chan", function() {
|
||||
describe("#sortUsers()", function() {
|
||||
|
||||
it("should sort a simple user list", function() {
|
||||
var chan = new Chan({users: [
|
||||
"JocelynD", "YaManicKill", "astorije", "xPaw", "Max-P"
|
||||
].map(makeUser)});
|
||||
chan.sortUsers();
|
||||
|
||||
expect(getUserNames(chan)).to.deep.equal([
|
||||
"astorije", "JocelynD", "Max-P", "xPaw", "YaManicKill"
|
||||
]);
|
||||
});
|
||||
|
||||
it("should group users by modes", function() {
|
||||
var chan = new Chan({users: [
|
||||
new User({name: "JocelynD", mode: "&"}),
|
||||
new User({name: "YaManicKill", mode: "+"}),
|
||||
new User({name: "astorije", mode: "%"}),
|
||||
new User({name: "xPaw", mode: "~"}),
|
||||
new User({name: "Max-P", mode: "@"}),
|
||||
]});
|
||||
chan.sortUsers();
|
||||
|
||||
expect(getUserNames(chan)).to.deep.equal([
|
||||
"xPaw", "JocelynD", "Max-P", "astorije", "YaManicKill"
|
||||
]);
|
||||
});
|
||||
|
||||
it("should sort a mix of users and modes", function() {
|
||||
var chan = new Chan({users: [
|
||||
new User({name: "JocelynD"}),
|
||||
new User({name: "YaManicKill", mode: "@"}),
|
||||
new User({name: "astorije"}),
|
||||
new User({name: "xPaw"}),
|
||||
new User({name: "Max-P", mode: "@"}),
|
||||
]});
|
||||
chan.sortUsers();
|
||||
|
||||
expect(getUserNames(chan)).to.deep.equal(
|
||||
["Max-P", "YaManicKill", "astorije", "JocelynD", "xPaw"]
|
||||
);
|
||||
});
|
||||
|
||||
it("should be case-insensitive", function() {
|
||||
var chan = new Chan({users: ["aB", "Ad", "AA", "ac"].map(makeUser)});
|
||||
chan.sortUsers();
|
||||
|
||||
expect(getUserNames(chan)).to.deep.equal(["AA", "aB", "ac", "Ad"]);
|
||||
});
|
||||
|
||||
it("should parse special characters successfully", function() {
|
||||
var chan = new Chan({users: [
|
||||
"[foo", "]foo", "(foo)", "{foo}", "<foo>", "_foo", "@foo", "^foo",
|
||||
"&foo", "!foo", "+foo", "Foo"
|
||||
].map(makeUser)});
|
||||
chan.sortUsers();
|
||||
|
||||
expect(getUserNames(chan)).to.deep.equal([
|
||||
"!foo", "&foo", "(foo)", "+foo", "<foo>", "@foo", "[foo", "]foo",
|
||||
"^foo", "_foo", "Foo", "{foo}"
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user