Created
April 28, 2011 14:43
-
-
Save thelinuxlich/946478 to your computer and use it in GitHub Desktop.
Como eu testo meu client side
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" | |
"http://www.w3.org/TR/html4/loose.dtd"> | |
<html> | |
<head> | |
<link rel="stylesheet" href="../../css/qunit.css" type="text/css" media="screen" /> | |
<script type="text/javascript"> var TEST_ENV = true;</script> | |
<script src="../../js/jquery.js"></script> | |
<script src="../../js/knockout.js"></script> | |
<script src="../../js/reqman.js"></script> | |
<script src="../js/fale_conosco.js"></script> | |
<script src="../../js/qunit.js"></script> | |
<script src="../../js/jquery.mockjax.js"></script> | |
<script> | |
$(function(){ | |
module("Testes Offline"); | |
test("Regex de e-mail deve aceitar e-mails válidos", function() { | |
ok(REGEX_EMAIL.test("alisson@umc.br"),"testando para alisson@umc.br"); | |
ok(REGEX_EMAIL.test("thelinuxlich@gmail.com"),"testando para thelinuxlich@gmail.com"); | |
ok(REGEX_EMAIL.test("123_2@teste.com"),"testando para 123_2@teste.com"); | |
ok(REGEX_EMAIL.test("teste.t@teste.com"),"testando para teste.t@teste.com"); | |
}); | |
test("Regex de e-mail deve recusar e-mails inválidos", function() { | |
equal(false, REGEX_EMAIL.test("alissonumc..br"),"testando para alissonumc..br"); | |
equal(false, REGEX_EMAIL.test("@umc..br"),"testando para @umc..br"); | |
equal(false, REGEX_EMAIL.test("alisson@umc"),"testando para alisson@umc"); | |
equal(false, REGEX_EMAIL.test("alisson@u.r"),"testando para alisson@u.r"); | |
}); | |
test("A pergunta deve ser válida se tiver todos os campos preenchidos", function() { | |
viewModel.pergunta().email("alisson@umc.br"); | |
viewModel.pergunta().nome("Alisson"); | |
viewModel.pergunta().nivel("0"); | |
viewModel.pergunta().assunto("0"); | |
viewModel.pergunta().texto("abc"); | |
viewModel.pergunta().tipo_assunto("N"); | |
ok(viewModel.pergunta().valido); | |
}); | |
test("A pergunta deve ser inválida se não tiver todos os campos preenchidos", function() { | |
viewModel.resetar(); | |
equal(false,viewModel.pergunta().valido()); | |
}); | |
test("O texto da pergunta não pode passar da quantidade máxima de caracteres", function() { | |
viewModel.pergunta().maxChars = 10; | |
viewModel.pergunta().texto("mais de 10 caracteres."); | |
ok(viewModel.pergunta().texto().length === 10); | |
}); | |
test("O IdentityMap deve retornar um objeto de seu container se ele for semelhante ao necessário", function() { | |
var I = new IdentityMap(); | |
var params = {arg1: "A", arg2: "B"}; | |
I.push({id: "teste", params: params, data: "123456"}); | |
var obj = I.find("teste",params); | |
ok(obj); | |
}); | |
/** Mocks para simular AJAX */ | |
$.mockjax({url: URL+"/get/busca_cursos.php*",contentType: 'text/json', | |
responseText: [{id: "100_1", nome: "Sistemas de Informação"}, | |
{id: "101_1", nome: "Medicina"},{id: "102_2",nome: "Direito"} | |
] | |
}); | |
$.mockjax({url: URL+"/get/busca_niveis_assunto.php*",contentType: 'text/json', | |
responseText: [{id:0, nome: "Graduação"},{id:1,nome:"Pós-Graduação"}] | |
}); | |
$.mockjax({url: URL+"/get/busca_assuntos.php*",contentType: 'text/json', | |
responseText: [{id: "0",nome: "Reclamações",tipo: "N"}, | |
{id: "1",nome: "Elogios",tipo: "N"}, | |
{id: "2",nome: "Fale com o Coordenador de Curso",tipo: "C"} | |
] | |
}); | |
$.mockjax({url: URL+"/post/gravar_pergunta.php*", contentType: 'text/json', | |
responseText: {status: "OK"} | |
}); | |
asyncTest("Durante a inicialização os níveis e assuntos devem ser carregados para seleção", function() { | |
viewModel.init(function() { | |
setTimeout(function() { | |
ok(viewModel.niveis().length === 2); | |
ok(viewModel.assuntos().length === 3); | |
start(); | |
},1000); | |
}); | |
}); | |
asyncTest("A seleção de cursos deve ser exibida se o assunto selecionado for do tipo 'C' (Curso)", function() { | |
viewModel.init(function() { | |
viewModel.pergunta().assunto("2"); | |
setTimeout(function() { | |
ok(viewModel.pergunta().tipo_assunto() === "C"); | |
ok(viewModel.cursos().length === 3); | |
start(); | |
},1000); | |
}); | |
}); | |
test("Quando o curso for selecionado, seu código deve ser dividido entre 2 variáveis", function() { | |
viewModel.pergunta().codigoCursoCentro("100_1"); | |
ok(viewModel.pergunta().codigoCurso() === "100"); | |
ok(viewModel.pergunta().codigoCentro() === "1"); | |
}); | |
asyncTest("A pergunta deve ser resetada se gravada com sucesso", function() { | |
viewModel.pergunta().texto("aaaaaa"); | |
viewModel.enviarPergunta(function() { | |
ok(viewModel.pergunta().texto() === ""); | |
start(); | |
}); | |
}); | |
module("Testes Online"); | |
asyncTest("Testando se as selects de nível e assunto estão sendo populadas por chamadas remotas", function() { | |
$.mockjaxClear(); | |
viewModel.cache = new IdentityMap(); | |
viewModel.carrega_niveis(function() { | |
setTimeout(function() { | |
ok(viewModel.niveis().length > 0,"Lista de niveis maior que 0"); | |
ok(viewModel.assuntos().length > 0,"Lista de assuntos maior que 0"); | |
start(); | |
},1000); | |
}); | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<h1 id="qunit-header">Suíte de testes Fale Conosco Externo</h1> | |
<h2 id="qunit-banner"></h2> | |
<div id="qunit-testrunner-toolbar"></div> | |
<h2 id="qunit-userAgent"></h2> | |
<ol id="qunit-tests"></ol> | |
<div id="qunit-fixture">test markup, will be hidden</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment