769 lines
28 KiB
JavaScript
769 lines
28 KiB
JavaScript
//////////////////////////////////////////////////
|
|
// DateUtil
|
|
|
|
QUnit.test( "DateUtil", function( assert ) {
|
|
var datetime = new Date("2019-06-04T16:15:00");
|
|
var date = datetime.getFullYear() + "-"
|
|
+ ("0" + (datetime.getMonth() + 1)).slice(-2) + "-"
|
|
+ ("0" + datetime.getDate()).slice(-2);
|
|
var time = ("0" + datetime.getHours()).slice(-2) + ":"
|
|
+ ("0" + datetime.getMinutes()).slice(-2) + ":"
|
|
+ ("0" + datetime.getSeconds()).slice(-2);
|
|
|
|
assert.equal(DateUtil.getYYYYMMDD(datetime), date, "DateUtil - getYYYYMMDD");
|
|
assert.equal(DateUtil.getHHMMSS(datetime), time, "DateUtil - getHHMMSS");
|
|
});
|
|
|
|
|
|
//////////////////////////////////////////////////
|
|
// App ranking
|
|
|
|
QUnit.test( "App ranking", function( assert ) {
|
|
sessionStorageManager.setMaestroID(3); // jisangs
|
|
sessionStorageManager.setPlayingAppID(1);
|
|
|
|
var dbConnectManager = new DBConnectManager();
|
|
|
|
// #1 Hour 15:00
|
|
let date = "2018-08-23";
|
|
let time = "15:53:00";
|
|
|
|
let done = assert.async();
|
|
setTimeout(function() {
|
|
dbConnectManager.requestRanking(
|
|
DBConnectManager.TYPE_MY_RANKING_HOUR,
|
|
sessionStorageManager.getMaestroID(),
|
|
date,
|
|
time,
|
|
(type, rankingRecordManager) => {
|
|
assert.equal(rankingRecordManager.getRankAt(0), 1, "hour - rank #1");
|
|
assert.equal(rankingRecordManager.getBestRecordAt(0), 97.33, "hour - best record");
|
|
assert.equal(rankingRecordManager.getPlayerIDAt(0), 49, "hour - player ID");
|
|
assert.equal(rankingRecordManager.getPlayerNameAt(0), "마가연", "hour - player name");
|
|
|
|
assert.equal(rankingRecordManager.getRankAt(5), 6, "hour - rank");
|
|
assert.equal(rankingRecordManager.getBestRecordAt(5), 85.44, "hour - best record");
|
|
assert.equal(rankingRecordManager.getPlayerIDAt(5), 79, "hour - player ID");
|
|
assert.equal(rankingRecordManager.getPlayerNameAt(5), "박선수", "hour - player name");
|
|
|
|
done();
|
|
}
|
|
);
|
|
});
|
|
|
|
// #2 Hour 16:00
|
|
let date2 = "2018-08-23";
|
|
let time2 = "16:53:00";
|
|
|
|
let done2 = assert.async();
|
|
setTimeout(function() {
|
|
dbConnectManager.requestRanking(
|
|
DBConnectManager.TYPE_MY_RANKING_HOUR,
|
|
sessionStorageManager.getMaestroID(),
|
|
date2,
|
|
time2,
|
|
(type, rankingRecordManager) => {
|
|
assert.equal(rankingRecordManager.getRankAt(0), 1, "hour - rank #2");
|
|
assert.equal(rankingRecordManager.getBestRecordAt(0), 97.87, "hour - best record");
|
|
assert.equal(rankingRecordManager.getPlayerIDAt(0), 51, "hour - player ID");
|
|
assert.equal(rankingRecordManager.getPlayerNameAt(0), "김민재", "hour - player name");
|
|
|
|
assert.equal(rankingRecordManager.getRankAt(5), 6, "hour - rank");
|
|
assert.equal(rankingRecordManager.getBestRecordAt(5), 87.64, "hour - best record");
|
|
assert.equal(rankingRecordManager.getPlayerIDAt(5), 60, "hour - player ID");
|
|
assert.equal(rankingRecordManager.getPlayerNameAt(5), "이서영", "hour - player name");
|
|
|
|
done2();
|
|
}
|
|
);
|
|
});
|
|
|
|
|
|
// #3 Day 2018-08-23
|
|
let date3 = "2018-08-23";
|
|
let time3 = "16:53:00";
|
|
|
|
let done3 = assert.async();
|
|
setTimeout(function() {
|
|
dbConnectManager.requestRanking(
|
|
DBConnectManager.TYPE_MY_RANKING_DAY,
|
|
sessionStorageManager.getMaestroID(),
|
|
date3,
|
|
time3,
|
|
(type, rankingRecordManager) => {
|
|
assert.equal(rankingRecordManager.getRankAt(0), 1, "day - rank #3");
|
|
assert.equal(rankingRecordManager.getBestRecordAt(0), 99.18, "day - best record");
|
|
assert.equal(rankingRecordManager.getPlayerIDAt(0), 46, "day - player ID");
|
|
assert.equal(rankingRecordManager.getPlayerNameAt(0), "강예원", "day - player name");
|
|
|
|
assert.equal(rankingRecordManager.getRankAt(5), 6, "day - rank");
|
|
assert.equal(rankingRecordManager.getBestRecordAt(5), 94.48, "day - best record");
|
|
assert.equal(rankingRecordManager.getPlayerIDAt(5), 57, "day - player ID");
|
|
assert.equal(rankingRecordManager.getPlayerNameAt(5), "고울", "day - player name");
|
|
|
|
done3();
|
|
}
|
|
);
|
|
});
|
|
});
|
|
|
|
|
|
//////////////////////////////////////////////////
|
|
// AccountValidator
|
|
|
|
let accountValidator = new AccountValidator();
|
|
|
|
QUnit.test( "AccountValidator - isValidMaestroID", function( assert ) {
|
|
let text = "";
|
|
assert.equal(accountValidator.isValidMaestroID(text), false, "isValidMaestroID - no text");
|
|
text = "1abcde";
|
|
assert.equal(accountValidator.isValidMaestroID(text), false, "isValidMaestroID - " + text);
|
|
text = "abc";
|
|
assert.equal(accountValidator.isValidMaestroID(text), false, "isValidMaestroID - " + text);
|
|
text = "a1b";
|
|
assert.equal(accountValidator.isValidMaestroID(text), false, "isValidMaestroID - " + text);
|
|
text = "abcdeabcdeabcdeabcdea";
|
|
assert.equal(accountValidator.isValidMaestroID(text), false, "isValidMaestroID - " + text);
|
|
|
|
text = "abcd";
|
|
assert.equal(accountValidator.isValidMaestroID(text), true, "isValidMaestroID - " + text);
|
|
text = "aA1Bccd";
|
|
assert.equal(accountValidator.isValidMaestroID(text), true, "isValidMaestroID - " + text);
|
|
text = "abcdeabcdeabcdeabcde";
|
|
assert.equal(accountValidator.isValidMaestroID(text), true, "isValidMaestroID - " + text);
|
|
});
|
|
|
|
QUnit.test( "AccountValidator - isValidMaestroPW", function( assert ) {
|
|
let text = "";
|
|
assert.equal(accountValidator.isValidMaestroPW(text), false, "isValidMaestroPW - " + text);
|
|
text = "1";
|
|
assert.equal(accountValidator.isValidMaestroPW(text), false, "isValidMaestroPW - " + text);
|
|
text = "12";
|
|
assert.equal(accountValidator.isValidMaestroPW(text), false, "isValidMaestroPW - " + text);
|
|
text = "123";
|
|
assert.equal(accountValidator.isValidMaestroPW(text), false, "isValidMaestroPW - " + text);
|
|
text = "1234";
|
|
assert.equal(accountValidator.isValidMaestroPW(text), true, "isValidMaestroPW - " + text);
|
|
text = "12345";
|
|
assert.equal(accountValidator.isValidMaestroPW(text), true, "isValidMaestroPW - " + text);
|
|
text = "123456";
|
|
assert.equal(accountValidator.isValidMaestroPW(text), true, "isValidMaestroPW - " + text);
|
|
text = "1234567891234567";
|
|
assert.equal(accountValidator.isValidMaestroPW(text), true, "isValidMaestroPW - " + text);
|
|
text = "12345678912345678";
|
|
assert.equal(accountValidator.isValidMaestroPW(text), false, "isValidMaestroPW - " + text);
|
|
|
|
text = "1abcde";
|
|
assert.equal(accountValidator.isValidMaestroPW(text), true, "isValidMaestroPW - " + text);
|
|
text = "abc";
|
|
assert.equal(accountValidator.isValidMaestroPW(text), false, "isValidMaestroPW - " + text);
|
|
text = "a1b";
|
|
assert.equal(accountValidator.isValidMaestroPW(text), false, "isValidMaestroPW - " + text);
|
|
text = "abcdeabcdeabcdeabcdea";
|
|
assert.equal(accountValidator.isValidMaestroPW(text), false, "isValidMaestroPW - " + text);
|
|
text = "abcdeabcdeabcdeabcde";
|
|
assert.equal(accountValidator.isValidMaestroPW(text), false, "isValidMaestroPW - " + text);
|
|
});
|
|
|
|
|
|
QUnit.test( "AccountValidator - isValidPlayerID", function( assert ) {
|
|
let text = "";
|
|
assert.equal(accountValidator.isValidPlayerID(text), false, "isValidPlayerID - no text");
|
|
text = "1abcde";
|
|
assert.equal(accountValidator.isValidPlayerID(text), true, "isValidPlayerID - " + text);
|
|
text = "abc";
|
|
assert.equal(accountValidator.isValidPlayerID(text), true, "isValidPlayerID - " + text);
|
|
text = "a1b";
|
|
assert.equal(accountValidator.isValidPlayerID(text), true, "isValidPlayerID - " + text);
|
|
text = "abcdeabcdeabcdeabcdea";
|
|
assert.equal(accountValidator.isValidPlayerID(text), false, "isValidPlayerID - " + text);
|
|
|
|
text = "abcd";
|
|
assert.equal(accountValidator.isValidPlayerID(text), true, "isValidPlayerID - " + text);
|
|
text = "aA1Bccd";
|
|
assert.equal(accountValidator.isValidPlayerID(text), true, "isValidPlayerID - " + text);
|
|
text = "abcdeabcdeabcdeabcde";
|
|
assert.equal(accountValidator.isValidPlayerID(text), false, "isValidPlayerID - " + text);
|
|
|
|
text = "박지상";
|
|
assert.equal(accountValidator.isValidPlayerID(text), true, "isValidPlayerID - " + text);
|
|
text = "박지상76";
|
|
assert.equal(accountValidator.isValidPlayerID(text), true, "isValidPlayerID - " + text);
|
|
text = "박";
|
|
assert.equal(accountValidator.isValidPlayerID(text), true, "isValidPlayerID - " + text);
|
|
text = "ㅂ";
|
|
assert.equal(accountValidator.isValidPlayerID(text), false, "isValidPlayerID - " + text);
|
|
|
|
text = "박지상박세나";
|
|
assert.equal(accountValidator.isValidPlayerID(text), true, "isValidPlayerID - " + text);
|
|
text = "박지상박세나신현";
|
|
assert.equal(accountValidator.isValidPlayerID(text), true, "isValidPlayerID - " + text);
|
|
text = "박지상박세나ab";
|
|
assert.equal(accountValidator.isValidPlayerID(text), true, "isValidPlayerID - " + text);
|
|
text = "박지상박세나abc";
|
|
assert.equal(accountValidator.isValidPlayerID(text), false, "isValidPlayerID - " + text);
|
|
text = "박지상박세나신현주";
|
|
assert.equal(accountValidator.isValidPlayerID(text), false, "isValidPlayerID - " + text);
|
|
text = "박지상박세나123";
|
|
assert.equal(accountValidator.isValidPlayerID(text), false, "isValidPlayerID - " + text);
|
|
|
|
text = "1-3박세나";
|
|
assert.equal(accountValidator.isValidPlayerID(text), true, "isValidPlayerID - " + text);
|
|
text = "1-4 박지상";
|
|
assert.equal(accountValidator.isValidPlayerID(text), false, "isValidPlayerID - " + text);
|
|
});
|
|
|
|
QUnit.test( "AccountValidator - isValidPlayerPW", function( assert ) {
|
|
let text = "";
|
|
assert.equal(accountValidator.isValidPlayerPW(text), false, "isValidPlayerPW - " + text);
|
|
text = "1";
|
|
assert.equal(accountValidator.isValidPlayerPW(text), false, "isValidPlayerPW - " + text);
|
|
text = "12";
|
|
assert.equal(accountValidator.isValidPlayerPW(text), true, "isValidPlayerPW - " + text);
|
|
text = "123";
|
|
assert.equal(accountValidator.isValidPlayerPW(text), true, "isValidPlayerPW - " + text);
|
|
text = "1234";
|
|
assert.equal(accountValidator.isValidPlayerPW(text), true, "isValidPlayerPW - " + text);
|
|
text = "12345";
|
|
assert.equal(accountValidator.isValidPlayerPW(text), true, "isValidPlayerPW - " + text);
|
|
text = "123456";
|
|
assert.equal(accountValidator.isValidPlayerPW(text), true, "isValidPlayerPW - " + text);
|
|
text = "1234567";
|
|
assert.equal(accountValidator.isValidPlayerPW(text), true, "isValidPlayerPW - " + text);
|
|
text = "12345678";
|
|
assert.equal(accountValidator.isValidPlayerPW(text), true, "isValidPlayerPW - " + text);
|
|
text = "123456789";
|
|
assert.equal(accountValidator.isValidPlayerPW(text), false, "isValidPlayerPW - " + text);
|
|
|
|
assert.equal(accountValidator.isValidPlayerPW(text), false, "isValidPlayerPW - no text");
|
|
text = "1abcde";
|
|
assert.equal(accountValidator.isValidPlayerPW(text), false, "isValidPlayerPW - " + text);
|
|
text = "abc";
|
|
assert.equal(accountValidator.isValidPlayerPW(text), false, "isValidPlayerPW - " + text);
|
|
text = "a1b";
|
|
assert.equal(accountValidator.isValidPlayerPW(text), false, "isValidPlayerPW - " + text);
|
|
text = "abcdeabcdeabcdeabcdea";
|
|
assert.equal(accountValidator.isValidPlayerPW(text), false, "isValidPlayerPW - " + text);
|
|
|
|
text = "abcd";
|
|
assert.equal(accountValidator.isValidPlayerPW(text), false, "isValidPlayerPW - " + text);
|
|
text = "aA1Bccd";
|
|
assert.equal(accountValidator.isValidPlayerPW(text), false, "isValidPlayerPW - " + text);
|
|
text = "abcdeabcdeabcdeabcde";
|
|
assert.equal(accountValidator.isValidPlayerPW(text), false, "isValidPlayerPW - " + text);
|
|
});
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////
|
|
// TypingTextManager
|
|
|
|
let typingTextMan = new TypingTextManager();
|
|
let testContent = [ "ㅃ", "ㅂ", "ㅈ", "ㅉ", "ㄸ", "ㄷ", "ㄱ", "ㄲ", "ㅅ" ];
|
|
|
|
QUnit.test( "TypingTextManager - add", function( assert ) {
|
|
typingTextMan.init();
|
|
typingTextMan.add(testContent);
|
|
let contents = typingTextMan.getContents();
|
|
|
|
assert.equal(contents[0], "ㅃ", "addTextArray - ㅃ");
|
|
assert.equal(contents[8], "ㅅ", "addTextArray - ㅅ");
|
|
|
|
typingTextMan.add([ "k", "l" ]);
|
|
contents = typingTextMan.getContents();
|
|
|
|
assert.equal(contents[9], "k", "addTextArray - k");
|
|
assert.equal(contents[10], "l", "addTextArray - l");
|
|
});
|
|
|
|
QUnit.test( "TypingTextManager - slice", function( assert ) {
|
|
typingTextMan.init();
|
|
typingTextMan.add(testContent);
|
|
typingTextMan.slice(0, 3);
|
|
let contents = typingTextMan.getContents();
|
|
|
|
assert.equal(contents[0], "ㅃ", "slice - ㅃ");
|
|
assert.equal(contents[2], "ㅈ", "slice - ㅈ");
|
|
assert.equal(contents[3], undefined, "slice - ㅉ");
|
|
});
|
|
|
|
QUnit.test( "TypingTextManager - makePracticeContents", function( assert ) {
|
|
var repeatCount = 2;
|
|
typingTextMan.makePracticeContents(testContent, repeatCount);
|
|
let contents = typingTextMan.getContents();
|
|
|
|
var countTestContent = testContent.length * (repeatCount + 1) * 2;
|
|
// repeatCount + 1 : original list + (shuffled list * 2)
|
|
// *2 : chosung + jungsung
|
|
|
|
assert.equal(contents[0], "ㅃ", "makePracticeContents - ㅃ");
|
|
assert.equal(contents[1], "ㅓ", "makePracticeContents - ㅓ");
|
|
assert.equal(contents[(testContent.length - 1) * 2], "ㅅ", "makePracticeContents - ㅅ");
|
|
assert.equal(contents.length, countTestContent, "makePracticeContents - length");
|
|
});
|
|
|
|
QUnit.test( "TypingTextManager - makeTestContents", function( assert ) {
|
|
typingTextMan.makeTestContents(testContent);
|
|
let contents = typingTextMan.getContents();
|
|
|
|
assert.equal(contents.length, testContent.length, "makeTestContents - length");
|
|
});
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////
|
|
// KeyMapper
|
|
|
|
let keyMapper = new KeyMapper();
|
|
|
|
QUnit.test( "KeyMapper - getNormalText", function( assert ) {
|
|
assert.equal(keyMapper.getNormalText("Backquote"), "`", "getNormalText - `");
|
|
assert.equal(keyMapper.getNormalText("Slash"), "/", "getNormalText - /");
|
|
|
|
assert.equal(keyMapper.getNormalText("KeyQ", Keyboard.ENGLISH), "q", "getNormalText - q");
|
|
assert.equal(keyMapper.getNormalText("KeyM", Keyboard.ENGLISH), "m", "getNormalText - m");
|
|
|
|
assert.equal(keyMapper.getNormalText("KeyQ", Keyboard.KOREAN), "ㅂ", "getNormalText - ㅂ");
|
|
assert.equal(keyMapper.getNormalText("KeyM", Keyboard.KOREAN), "ㅡ", "getNormalText - ㅡ");
|
|
});
|
|
|
|
QUnit.test( "KeyMapper - getShiftText", function( assert ) {
|
|
assert.equal(keyMapper.getShiftText("Backquote"), "~", "getShiftText - ~");
|
|
assert.equal(keyMapper.getShiftText("Slash"), "?", "getShiftText - ?");
|
|
|
|
assert.equal(keyMapper.getShiftText("KeyQ", Keyboard.ENGLISH), "Q", "getShiftText - Q");
|
|
assert.equal(keyMapper.getShiftText("KeyM", Keyboard.ENGLISH), "M", "getShiftText - M");
|
|
|
|
assert.equal(keyMapper.getShiftText("KeyQ", Keyboard.KOREAN), "ㅃ", "getShiftText - ㅃ");
|
|
assert.equal(keyMapper.getShiftText("KeyM", Keyboard.KOREAN), "ㅡ", "getShiftText - ㅡ");
|
|
});
|
|
|
|
/*
|
|
QUnit.test( "KeyMapper - getShiftHandSide", function( assert ) {
|
|
assert.equal(keyMapper.getShiftHandSide("Backquote"), KeyTextData.RIGHT_HAND, "getShiftHandSide - `");
|
|
assert.equal(keyMapper.getShiftHandSide("Slash"), KeyTextData.LEFT_HAND, "getShiftHandSide - /");
|
|
|
|
assert.equal(keyMapper.getShiftHandSide("Space"), KeyTextData.BOTH_HAND, "getShiftHandSide - space");
|
|
|
|
assert.equal(keyMapper.getShiftHandSide("KeyQ"), KeyTextData.RIGHT_HAND, "getShiftHandSide - q");
|
|
assert.equal(keyMapper.getShiftHandSide("KeyM"), KeyTextData.LEFT_HAND, "getShiftHandSide - m");
|
|
|
|
assert.equal(keyMapper.getShiftHandSide("KeyQ", Keyboard.KOREAN), KeyTextData.RIGHT_HAND, "getShiftHandSide - q");
|
|
assert.equal(keyMapper.getShiftHandSide("KeyM", Keyboard.KOREAN), KeyTextData.LEFT_HAND, "getShiftHandSide - m");
|
|
});
|
|
*/
|
|
|
|
|
|
|
|
QUnit.test( "KeyMapper - getKeyIDOfText", function( assert ) {
|
|
assert.equal(keyMapper.getKeyIDOfText("`"), "Backquote", "getKeyIDOfText - `");
|
|
assert.equal(keyMapper.getKeyIDOfText("~"), "Backquote", "getKeyIDOfText - ~");
|
|
assert.equal(keyMapper.getKeyIDOfText("/"), "Slash", "getKeyIDOfText - /");
|
|
assert.equal(keyMapper.getKeyIDOfText("?"), "Slash", "getKeyIDOfText - ?");
|
|
|
|
assert.equal(keyMapper.getKeyIDOfText("q"), "KeyQ", "getKeyIDOfText - q");
|
|
assert.equal(keyMapper.getKeyIDOfText("Q"), "KeyQ", "getKeyIDOfText - Q");
|
|
assert.equal(keyMapper.getKeyIDOfText("m"), "KeyM", "getKeyIDOfText - m");
|
|
assert.equal(keyMapper.getKeyIDOfText("M"), "KeyM", "getKeyIDOfText - M");
|
|
|
|
assert.equal(keyMapper.getKeyIDOfText("ㅂ"), "KeyQ", "getKeyIDOfText - ㅂ");
|
|
assert.equal(keyMapper.getKeyIDOfText("ㅃ"), "KeyQ", "getKeyIDOfText - ㅃ");
|
|
assert.equal(keyMapper.getKeyIDOfText("ㅡ"), "KeyM", "getKeyIDOfText - ㅡ");
|
|
|
|
assert.equal(keyMapper.getKeyIDOfText("Backspace"), "Backspace", "getKeyIDOfText - ㅂ");
|
|
});
|
|
|
|
QUnit.test( "KeyMapper - isShiftText", function( assert ) {
|
|
assert.equal(keyMapper.isShiftText("`"), false, "isShiftText - `");
|
|
assert.equal(keyMapper.isShiftText("~"), true, "isShiftText - ~");
|
|
assert.equal(keyMapper.isShiftText("/"), false, "isShiftText - /");
|
|
assert.equal(keyMapper.isShiftText("?"), true, "isShiftText - ?");
|
|
|
|
assert.equal(keyMapper.isShiftText("q"), false, "isShiftText - q");
|
|
assert.equal(keyMapper.isShiftText("Q"), true, "isShiftText - Q");
|
|
assert.equal(keyMapper.isShiftText("m"), false, "isShiftText - m");
|
|
assert.equal(keyMapper.isShiftText("M"), true, "isShiftText - M");
|
|
|
|
assert.equal(keyMapper.isShiftText("ㅁ"), false, "isShiftText - ㅁ");
|
|
assert.equal(keyMapper.isShiftText("ㄴ"), false, "isShiftText - ㄴ");
|
|
assert.equal(keyMapper.isShiftText("ㅇ"), false, "isShiftText - ㅇ");
|
|
|
|
assert.equal(keyMapper.isShiftText("ㅂ"), false, "isShiftText - ㅂ");
|
|
assert.equal(keyMapper.isShiftText("ㅃ"), true, "isShiftText - ㅃ");
|
|
assert.equal(keyMapper.isShiftText("ㅡ"), false, "isShiftText - ㅡ");
|
|
});
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////
|
|
// DBConnectManager
|
|
|
|
let dbConnectManager = new DBConnectManager();
|
|
dbConnectManager.setMaestroID(0);
|
|
dbConnectManager.setPlayerID(0);
|
|
dbConnectManager.setDateTime("2018-05-16", "14:50:00");
|
|
|
|
QUnit.test( "DBConnectManager - Player login", function( assert ) {
|
|
let returnPlayerID = -1;
|
|
|
|
let done = assert.async();
|
|
setTimeout(function() {
|
|
dbConnectManager.requestCheckPlayerLogin(
|
|
"jisangs", "test", "111111",
|
|
(jsonData) => {
|
|
returnPlayerID = jsonData["PlayerID"];
|
|
assert.equal(returnPlayerID, 300);
|
|
done();
|
|
},
|
|
(jsonData) => {
|
|
console.log(jsonData);
|
|
done();
|
|
}
|
|
);
|
|
});
|
|
});
|
|
|
|
// DB data is not prepared
|
|
/*
|
|
QUnit.test( "DBConnectManager - Player history", function( assert ) {
|
|
sessionStorageManager.maestroID = 1; // jisangs
|
|
sessionStorageManager.playerID = "8"; // 부현율
|
|
sessionStorageManager.playingAppID = 29;
|
|
let date = "2018-05-16";
|
|
|
|
let done = assert.async();
|
|
setTimeout(function() {
|
|
dbConnectManager.requestPlayerHistory(
|
|
1, // maestroID for jisangs
|
|
date,
|
|
(historyRecordManager) => {
|
|
// console.log(historyRecordManager);
|
|
|
|
assert.equal(historyRecordManager.getAppNameAt(0), "test_korean_word");
|
|
assert.equal(historyRecordManager.getDateAt(0), "2018-05-16");
|
|
assert.equal(historyRecordManager.getBestRecordAt(0), 108.248);
|
|
|
|
assert.equal(historyRecordManager.getAppNameAt(4), "test_korean_word");
|
|
assert.equal(historyRecordManager.getDateAt(4), "2018-04-23");
|
|
assert.equal(historyRecordManager.getBestRecordAt(4), 74.2234);
|
|
|
|
done();
|
|
}
|
|
);
|
|
});
|
|
});
|
|
*/
|
|
|
|
QUnit.test( "DBConnectManager - HowToPlay", function( assert ) {
|
|
let howToPlayForSpaceInvaders = "외계인이 나타났다!\\n마우스 왼쪽 버튼을 클릭해서\\n외계인이 사라지기 전에 물리쳐 주세요.";
|
|
var howToPlayForTyping = "왼손 검지를 [F] 자판위에,\\n오른손 검지를 [J] 자판위에 올린채\\n손을 움직이지 말고 글자를 입력하세요.";
|
|
|
|
let done = assert.async(2);
|
|
|
|
setTimeout(function() {
|
|
dbConnectManager.requestHowToPlay(
|
|
101, // space_invaders app ID
|
|
(jsonData) => {
|
|
let howToPlay = jsonData["HowToPlay"];
|
|
assert.equal(howToPlay, howToPlayForSpaceInvaders);
|
|
done();
|
|
},
|
|
(jsonData) => {
|
|
console.log(jsonData);
|
|
done();
|
|
}
|
|
);
|
|
|
|
dbConnectManager.requestHowToPlay(
|
|
1, // korean basic typing
|
|
(jsonData) => {
|
|
let howToPlay = jsonData["HowToPlay"];
|
|
assert.equal(howToPlay, howToPlayForTyping);
|
|
done();
|
|
},
|
|
(jsonData) => {
|
|
console.log(jsonData);
|
|
done();
|
|
}
|
|
);
|
|
});
|
|
});
|
|
|
|
// DB data is not prepared
|
|
/*
|
|
QUnit.test( "DBConnectManager - UpdateRecord", function( assert ) {
|
|
let todayBestRecord = 0;
|
|
|
|
let done = assert.async();
|
|
|
|
setTimeout(function() {
|
|
dbConnectManager.requestTodayBestRecord(
|
|
1, // maestro ID for "jisangs"
|
|
1, // Player ID for jisangs
|
|
101, // space_invaders app ID
|
|
(jsonData) => {
|
|
todayBestRecord = jsonData["BestRecord"];
|
|
},
|
|
(jsonData) => {
|
|
console.log(jsonData);
|
|
todayBestRecord = 0;
|
|
}
|
|
);
|
|
});
|
|
|
|
setTimeout(function() {
|
|
dbConnectManager.updateTodayBestRecord(
|
|
1, // maestro ID for "jisangs"
|
|
1, // Player ID for jisangs
|
|
101, // space_invaders app ID
|
|
todayBestRecord + 1000 // new record
|
|
);
|
|
}, 100);
|
|
|
|
setTimeout(function() {
|
|
dbConnectManager.requestTodayBestRecord(
|
|
1, // maestro ID for "jisangs"
|
|
1, // Player ID for jisangs
|
|
101, // space_invaders app ID
|
|
(jsonData) => {
|
|
let bestRecord = jsonData["BestRecord"];
|
|
assert.equal(bestRecord, todayBestRecord + 1000);
|
|
done();
|
|
},
|
|
(jsonData) => {
|
|
console.log(jsonData);
|
|
done();
|
|
}
|
|
);
|
|
}, 200);
|
|
});
|
|
*/
|
|
|
|
|
|
//////////////////////////////////////////////////
|
|
// HeartManager
|
|
|
|
let heartManager = new HeartManager();
|
|
|
|
QUnit.test( "HeartManager - MaxCount", function( assert ) {
|
|
heartManager.setCount(3);
|
|
assert.equal(heartManager.getCount(), 3);
|
|
|
|
heartManager.setMaxCount(5);
|
|
assert.equal(heartManager.getCount(), 3);
|
|
|
|
heartManager.setMaxCount(3);
|
|
assert.equal(heartManager.getCount(), 3);
|
|
|
|
heartManager.setMaxCount(2);
|
|
assert.equal(heartManager.getCount(), 2);
|
|
});
|
|
|
|
|
|
QUnit.test( "HeartManager - setCount", function( assert ) {
|
|
heartManager.setMaxCount(3);
|
|
|
|
heartManager.setCount(3);
|
|
assert.equal(heartManager.getCount(), 3);
|
|
|
|
heartManager.setCount(2);
|
|
assert.equal(heartManager.getCount(), 2);
|
|
});
|
|
|
|
|
|
QUnit.test( "HeartManager - addHearts", function( assert ) {
|
|
heartManager.setMaxCount(3);
|
|
|
|
heartManager.setCount(1);
|
|
assert.equal(heartManager.getCount(), 1);
|
|
|
|
heartManager.addHearts(1);
|
|
assert.equal(heartManager.getCount(), 2);
|
|
|
|
heartManager.setCount(1);
|
|
assert.equal(heartManager.getCount(), 1);
|
|
|
|
heartManager.addHearts(2);
|
|
assert.equal(heartManager.getCount(), 3);
|
|
|
|
heartManager.setCount(1);
|
|
assert.equal(heartManager.getCount(), 1);
|
|
|
|
heartManager.addHearts(3);
|
|
assert.equal(heartManager.getCount(), 3);
|
|
});
|
|
|
|
|
|
QUnit.test( "HeartManager - breakHearts", function( assert ) {
|
|
heartManager.setMaxCount(3);
|
|
|
|
heartManager.setCount(3);
|
|
assert.equal(heartManager.getCount(), 3);
|
|
|
|
heartManager.breakHearts(1);
|
|
assert.equal(heartManager.getCount(), 2);
|
|
|
|
heartManager.breakHearts(2);
|
|
assert.equal(heartManager.getCount(), 0);
|
|
});
|
|
|
|
|
|
//////////////////////////////////////////////////
|
|
// HistoryRecordManager
|
|
|
|
let historyRecordManager = new HistoryRecordManager();
|
|
|
|
historyRecordManager.push(new HistoryRecord("05/10", "space_invaders", 1000));
|
|
historyRecordManager.push(new HistoryRecord("05/11", "typing_korean_basic", 100));
|
|
historyRecordManager.push(new HistoryRecord("05/12", "cooking_meats", 200));
|
|
historyRecordManager.push(new HistoryRecord("05/13", "typing_english_basic", 2000));
|
|
historyRecordManager.push(new HistoryRecord("05/14", "test", 10000));
|
|
|
|
QUnit.test( "HistoryRecordManager - push", function( assert ) {
|
|
assert.equal(historyRecordManager.historyRecords.length, 5);
|
|
});
|
|
|
|
QUnit.test( "HistoryRecordManager - getAt", function( assert ) {
|
|
assert.equal(historyRecordManager.getDateAt(0), "05/10");
|
|
assert.equal(historyRecordManager.getDateAt(4), "05/14");
|
|
|
|
assert.equal(historyRecordManager.getAppNameAt(0), "space_invaders");
|
|
assert.equal(historyRecordManager.getAppNameAt(4), "test");
|
|
});
|
|
|
|
QUnit.test( "HistoryRecordManager - clear", function( assert ) {
|
|
let historyRecordManagerForClear = new HistoryRecordManager();
|
|
historyRecordManagerForClear.push(new HistoryRecord("05/10", "space_invaders", 1));
|
|
historyRecordManagerForClear.clear();
|
|
|
|
assert.equal(historyRecordManagerForClear.historyRecords.length, 0);
|
|
});
|
|
|
|
QUnit.test( "HistoryRecordManager - underValueForGraph", function( assert ) {
|
|
assert.equal(historyRecordManager.underValueForGraph(), 100);
|
|
});
|
|
|
|
QUnit.test( "HistoryRecordManager - upperValueForGraph", function( assert ) {
|
|
assert.equal(historyRecordManager.upperValueForGraph(), 10000);
|
|
});
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////
|
|
// NumberUtil
|
|
|
|
QUnit.test( "NumberUtil - NumberWithCommas", function( assert ) {
|
|
assert.equal(NumberUtil.numberWithCommas(1), "1", "NumberWithCommas");
|
|
assert.equal(NumberUtil.numberWithCommas(1000), "1,000", "NumberWithCommas");
|
|
assert.equal(NumberUtil.numberWithCommas(100000), "100,000", "NumberWithCommas");
|
|
assert.equal(NumberUtil.numberWithCommas(1000000), "1,000,000", "NumberWithCommas");
|
|
});
|
|
|
|
QUnit.test( "NumberUtil - NumberOfDigits", function( assert ) {
|
|
assert.equal(NumberUtil.numberOfDigits(1), 1);
|
|
assert.equal(NumberUtil.numberOfDigits(10), 2);
|
|
assert.equal(NumberUtil.numberOfDigits(100), 3);
|
|
assert.equal(NumberUtil.numberOfDigits(999), 3);
|
|
assert.equal(NumberUtil.numberOfDigits(1000), 4);
|
|
assert.equal(NumberUtil.numberOfDigits(9999), 4);
|
|
assert.equal(NumberUtil.numberOfDigits(10000), 5);
|
|
assert.equal(NumberUtil.numberOfDigits(99999), 5);
|
|
});
|
|
|
|
|
|
//////////////////////////////////////////////////
|
|
// RankingRecordManager
|
|
|
|
let rankingRecordManager = new RankingRecordManager();
|
|
|
|
rankingRecordManager.push(new RankingRecord(4, 1, "김남희", 1400));
|
|
rankingRecordManager.push(new RankingRecord(5, 2, "고봉순", 900));
|
|
rankingRecordManager.push(new RankingRecord(6, 3, "파르마", 800));
|
|
rankingRecordManager.push(new RankingRecord(7, 4, "박지상", 700));
|
|
rankingRecordManager.push(new RankingRecord(8, 5, "신현주", 600));
|
|
|
|
QUnit.test( "RankingRecordManager - push", function( assert ) {
|
|
assert.equal(rankingRecordManager.rankingRecords.length, 5);
|
|
});
|
|
|
|
QUnit.test( "RankingRecordManager - getAt", function( assert ) {
|
|
assert.equal(rankingRecordManager.getRankAt(0), 4);
|
|
assert.equal(rankingRecordManager.getRankAt(4), 8);
|
|
|
|
assert.equal(rankingRecordManager.getPlayerIDAt(0), 1);
|
|
assert.equal(rankingRecordManager.getPlayerIDAt(4), 5);
|
|
|
|
assert.equal(rankingRecordManager.getPlayerNameAt(0), "김남희");
|
|
assert.equal(rankingRecordManager.getPlayerNameAt(4), "신현주");
|
|
|
|
assert.equal(rankingRecordManager.getBestRecordAt(0), 1400);
|
|
assert.equal(rankingRecordManager.getBestRecordAt(4), 600);
|
|
});
|
|
|
|
QUnit.test( "RankingRecordManager - clear", function( assert ) {
|
|
let rankingRecordManagerForClear = new RankingRecordManager();
|
|
rankingRecordManagerForClear.push(new RankingRecord(8, "신현주", 600));
|
|
rankingRecordManagerForClear.clear();
|
|
|
|
assert.equal(rankingRecordManagerForClear.rankingRecords.length, 0);
|
|
});
|
|
|
|
|
|
//////////////////////////////////////////////////
|
|
// ScoreManager
|
|
|
|
let scoreManager = new ScoreManager();
|
|
|
|
QUnit.test( "ScoreManager - plusScore", function( assert ) {
|
|
assert.equal(scoreManager.score, 0);
|
|
scoreManager.plusScore(10);
|
|
assert.equal(scoreManager.score, 10);
|
|
scoreManager.minusScore(10);
|
|
assert.equal(scoreManager.score, 0);
|
|
});
|
|
|
|
|
|
//////////////////////////////////////////////////
|
|
// SessionStorageManager
|
|
|
|
QUnit.test( "SessionStorageManager - PlayerName", function( assert ) {
|
|
sessionStorageManager.clear();
|
|
assert.equal(sessionStorageManager.getPlayerName(), null, "playerName");
|
|
|
|
sessionStorageManager.setPlayerName("박지상");
|
|
assert.equal(sessionStorageManager.getPlayerName(), "박지상", "playerName");
|
|
|
|
sessionStorageManager.removeItem("playerName");
|
|
assert.equal(sessionStorageManager.getPlayerName(), null, "playerName");
|
|
});
|
|
|
|
QUnit.test( "SessionStorageManager - playerPlayerID", function( assert ) {
|
|
sessionStorageManager.clear();
|
|
assert.equal(sessionStorageManager.getPlayerID(), null, "playerID");
|
|
|
|
sessionStorageManager.setPlayerID(1);
|
|
assert.equal(sessionStorageManager.getPlayerID(), 1, "playerID");
|
|
|
|
sessionStorageManager.removeItem("playerID");
|
|
assert.equal(sessionStorageManager.getPlayerID(), null, "playerID");
|
|
});
|
|
|
|
QUnit.test( "SessionStorageManager - playingAppName", function( assert ) {
|
|
sessionStorageManager.clear();
|
|
assert.equal(sessionStorageManager.getPlayingAppName(), null, "playingAppName");
|
|
|
|
sessionStorageManager.setPlayingAppName("space_invaders");
|
|
assert.equal(sessionStorageManager.getPlayingAppName(), "space_invaders", "playingAppName");
|
|
|
|
sessionStorageManager.removeItem("playingAppName");
|
|
assert.equal(sessionStorageManager.getPlayingAppName(), null, "playingAppName");
|
|
});
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////
|
|
// test
|
|
|
|
QUnit.test( "hello test", function( assert ) {
|
|
assert.ok( 1 == "1", "Passed!" );
|
|
}); |