Commit 089a3fbb20e51e5d4f8d36ff59c20779e8dc8155
1 parent
1998d95a
Exists in
master
Adicionando Testes headless com mocha/chai/zombie
Showing
4 changed files
with
75 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,22 @@ |
1 | +var express = require("express"); | |
2 | + | |
3 | +var app = express(); | |
4 | + | |
5 | + | |
6 | + // read the port from the environment, else set to 3000 | |
7 | + app.set("port", process.env.PORT || 3000); | |
8 | + app.set('view engine', 'ejs'); | |
9 | + | |
10 | +app.get('/', function (req, res) | |
11 | +{ | |
12 | + res.render('index'); | |
13 | +}); | |
14 | + | |
15 | +app.get('/barra.js', function (req, res) | |
16 | +{ | |
17 | + res.render('barra'); | |
18 | +}); | |
19 | + | |
20 | +// instead of starting the application here, export the app so that it can | |
21 | +// be loaded differently based on the use case (running the app vs testing) | |
22 | +module.exports = app; | ... | ... |
... | ... | @@ -0,0 +1 @@ |
1 | +include ../../app/static/barra-brasil.js | ... | ... |
... | ... | @@ -0,0 +1 @@ |
1 | +include ../../app/templates/exemplo.html | ... | ... |
... | ... | @@ -0,0 +1,51 @@ |
1 | +var expect = require("chai").expect, assert = require("chai").assert, | |
2 | + Browser = require("zombie"), | |
3 | + app = require("./app"); | |
4 | + | |
5 | +describe("Testes de conteúdo de HTML da barra", function() { | |
6 | + var server, browser, barraUrl; | |
7 | + barraUrl = "http://localhost:3000/"; | |
8 | + before(function() { | |
9 | + // before ALL the tests, start our node server (on a test port, 3001) | |
10 | + | |
11 | + server = app.listen(3000); | |
12 | + }); | |
13 | + | |
14 | + beforeEach(function() { | |
15 | + // before EACH test, create a new zombie browser | |
16 | + // | |
17 | + // some useful options when things go wrong: | |
18 | + // debug: true = outputs debug information for zombie | |
19 | + // waitDuration: 500 = will only wait 500 milliseconds | |
20 | + // for the page to load before moving on | |
21 | + browser = new Browser(); | |
22 | + browser.runScripts = true; | |
23 | + }); | |
24 | + | |
25 | + after(function() { | |
26 | + // after ALL the tests, close the server | |
27 | + server.close(); | |
28 | + }); | |
29 | + | |
30 | + it("trocar o conteúdo do #barra-brasil pelo correto", function(done) { | |
31 | + browser.visit(barraUrl, function() { | |
32 | + | |
33 | + var inner_barra = browser.document.getElementById("barra-brasil"); | |
34 | + console.log(inner_barra.classList); | |
35 | + expect(inner_barra.innerHTML).to.equal("<div id=\"wrapper-barra-brasil\"><div class=\"brasil-flag\"><a href=\"http://brasil.gov.br\" class=\"link-barra\">Brasil</a></div><span class=\"acesso-info\"><a href=\"http://brasil.gov.br/barra#acesso-informacao\" class=\"link-barra\">Acesso à informação</a></span><nav><a href=\"#\" id=\"menu-icon\"></a><ul class=\"list\"><a href=\"http://brasil.gov.br/barra#participe\" class=\"link-barra\"><li class=\"list-item first\">Participe</li></a><a href=\"http://www.servicos.gov.br/?pk_campaign=barrabrasil\" class=\"link-barra\"><li class=\"list-item\">Serviços</li></a><a href=\"http://www.planalto.gov.br/legislacao\" class=\"link-barra\"><li class=\"list-item\">Legislação</li></a><a href=\"http://brasil.gov.br/barra#orgaos-atuacao-canais\" class=\"link-barra\"><li class=\"list-item last last-item\">Canais</li></a></ul></nav></div>"); | |
36 | + done(); | |
37 | + }); | |
38 | + }); | |
39 | + | |
40 | + it("trocar o conteúdo do #footer-brasil pelo correto", function(done) { | |
41 | + browser.visit(barraUrl, function() { | |
42 | + | |
43 | + var inner_barra = browser.document.getElementById("footer-brasil"); | |
44 | + assert(inner_barra.innerHTML === "<div id=\"wrapper-footer-brasil\"><a href=\"http://www.acessoainformacao.gov.br/\"><span class=\"logo-acesso-footer\"></span></a><a href=\"http://www.brasil.gov.br/\"><span class=\"logo-brasil-footer\"></span></a></div>", | |
45 | + "Conteúdo do#footer-brasil deve ser o provido pela barra.js"); | |
46 | + | |
47 | + done(); | |
48 | + }); | |
49 | + | |
50 | + }); | |
51 | +}); | ... | ... |