From 5f98fccf727af511b31599c6d98ce42be25f6caf Mon Sep 17 00:00:00 2001 From: Jack Pearkes Date: Mon, 9 Jun 2014 17:29:35 -0400 Subject: [PATCH 1/2] ui: add some basic tests --- ui/tests/tests.js | 82 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 74 insertions(+), 8 deletions(-) diff --git a/ui/tests/tests.js b/ui/tests/tests.js index 3f3b8ed49..3349800ba 100755 --- a/ui/tests/tests.js +++ b/ui/tests/tests.js @@ -5,11 +5,39 @@ App.rootElement = '#ember-testing'; App.setupForTesting(); App.injectTestHelpers(); -// common QUnit module declaration +// Test "fixtures". We populate these based on the running consul +// on the machine where you run the tests. +var fixtures = { + dc: "dc1", + node: null, + service: null, + key: "fake", + value: "foobar" +} + module("Integration tests", { setup: function() { // before each test, ensure the application is ready to run. Ember.run(App, App.advanceReadiness); + + // Discover the service, node and dc info + Ember.$.getJSON('/v1/catalog/datacenters').then(function(data) { + fixtures.dc = data[0] + }).then(function(){ + Ember.$.getJSON('/v1/internal/ui/nodes?dc=' + fixtures.dc).then(function(data) { + fixtures.node = data[0].Node + }); + }).then(function(){ + Ember.$.getJSON('/v1/internal/ui/services?dc=' + fixtures.dc).then(function(data) { + fixtures.service = data[0].Name + }); + }); + // Create a fake key + Ember.$.ajax({ + url: ("/v1/kv/" + fixtures.key + '?dc=' + fixtures.dc), + type: 'PUT', + data: fixtures.value + }) }, teardown: function() { @@ -18,14 +46,52 @@ module("Integration tests", { } }); -// QUnit test case -test("/", function() { - // async helper telling the application to go to the '/' route - visit("/"); +test("services", function() { + visit("/") - // helper waiting the application is idle before running the callback andThen(function() { - equal(find("h1").text(), "Base", "Application header is rendered"); - equal(find("li").length, 3, "There are three items in the list"); + ok(find("a:contains('Services')").hasClass('active'), "highlights services in nav"); + equal(find(".ember-list-item-view").length, 1, "renders one service"); + ok(find(".ember-list-item-view .name:contains('"+ fixtures.service +"')"), "uses service name"); + ok(find(".ember-list-item-view .name:contains('passing')"), "shows passing check num"); + }); +}); + +test("servicesShow", function() { + visit("/"); + // First item in list + click('.ember-list-item-view .list-group-item'); + + andThen(function() { + ok(find("a:contains('Services')").hasClass('active'), "highlights services in nav"); + equal(find(".ember-list-item-view").length, 1, "renders one service"); + ok(find(".ember-list-item-view .list-group-item").hasClass('active'), "highlights active service"); + ok(find(".ember-list-item-view .name:contains('"+ fixtures.service +"')"), "uses service name"); + ok(find(".ember-list-item-view .name:contains('passing')"), "shows passing check num"); + equal(find("h5").text(), "Nodes", "Shows node list"); + ok(find("h3.panel-title:contains('"+ fixtures.node +"')"), "Shows node name"); + }); +}); + +test("nodes", function() { + visit("/"); + click("a:contains('Nodes')"); + + andThen(function() { + ok(find("a:contains('Nodes')").hasClass('active'), "highlights nodes in nav"); + equal(find(".ember-list-item-view").length, 1, "renders one node"); + ok(find(".ember-list-item-view .name:contains('"+ fixtures.node +"')"), "contains node name"); + ok(find(".ember-list-item-view .name:contains('services')"), "contains services num"); + }); +}); + +test("kv", function() { + visit("/"); + click("a:contains('Key/Value')"); + + andThen(function() { + ok(find("a:contains('Key/Value')").hasClass('active'), "highlights kv in nav"); + equal(find(".list-group-item").length, 1, "renders one key"); + ok(find(".list-group-item:contains('"+ fixtures.key +"')"), "contains key name"); }); }); From 48eaada3ae9ca2046aa42870c05b753223d42233 Mon Sep 17 00:00:00 2001 From: Jack Pearkes Date: Tue, 10 Jun 2014 11:02:21 -0400 Subject: [PATCH 2/2] ui: add nodeShow test --- ui/tests/tests.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/ui/tests/tests.js b/ui/tests/tests.js index 3349800ba..8ee1ecfab 100755 --- a/ui/tests/tests.js +++ b/ui/tests/tests.js @@ -68,8 +68,9 @@ test("servicesShow", function() { ok(find(".ember-list-item-view .list-group-item").hasClass('active'), "highlights active service"); ok(find(".ember-list-item-view .name:contains('"+ fixtures.service +"')"), "uses service name"); ok(find(".ember-list-item-view .name:contains('passing')"), "shows passing check num"); - equal(find("h5").text(), "Nodes", "Shows node list"); - ok(find("h3.panel-title:contains('"+ fixtures.node +"')"), "Shows node name"); + ok(find("h3:contains('"+ fixtures.service+"')"), "shows service name"); + equal(find("h5").text(), "Nodes", "shows node list"); + ok(find("h3.panel-title:contains('"+ fixtures.node +"')"), "shows node name"); }); }); @@ -85,6 +86,21 @@ test("nodes", function() { }); }); +test("nodesShow", function() { + visit("/"); + click("a:contains('Nodes')"); + // First item in list + click('.ember-list-item-view .list-group-item'); + + andThen(function() { + ok(find("a:contains('Nodes')").hasClass('active'), "highlights services in nav"); + equal(find(".ember-list-item-view").length, 1, "renders one service"); + ok(find(".ember-list-item-view .list-group-item").hasClass('active'), "highlights active node"); + ok(find(".ember-list-item-view .name:contains('"+ fixtures.node +"')"), "uses node name"); + ok(find(".ember-list-item-view .name:contains('passing')"), "shows passing check num"); + }); +}); + test("kv", function() { visit("/"); click("a:contains('Key/Value')");