github.com/sl1pm4t/consul@v1.4.5-0.20190325224627-74c31c540f9c/ui/tests/tests.js (about)

     1  // in order to see the app running inside the QUnit runner
     2  App.rootElement = '#ember-testing';
     3  
     4  // Common test setup
     5  App.setupForTesting();
     6  App.injectTestHelpers();
     7  
     8  // Test "fixtures". We populate these based on the running consul
     9  // on the machine where you run the tests.
    10  var fixtures = {
    11    dc: "dc1",
    12    node: null,
    13    service: null,
    14    key: "fake",
    15    value: "foobar"
    16  }
    17  
    18  module("Integration tests", {
    19    setup: function() {
    20      // before each test, ensure the application is ready to run.
    21      Ember.run(App, App.advanceReadiness);
    22  
    23      // Discover the service, node and dc info
    24      Ember.$.getJSON('/v1/catalog/datacenters').then(function(data) {
    25        fixtures.dc = data[0]
    26      }).then(function(){
    27        Ember.$.getJSON('/v1/internal/ui/nodes?dc=' + fixtures.dc).then(function(data) {
    28          fixtures.node = data[0].Node
    29        });
    30      }).then(function(){
    31        Ember.$.getJSON('/v1/internal/ui/services?dc=' + fixtures.dc).then(function(data) {
    32          fixtures.service = data[0].Name
    33        });
    34      });
    35      // Create a fake key
    36      Ember.$.ajax({
    37        url: ("/v1/kv/" + fixtures.key + '?dc=' + fixtures.dc),
    38        type: 'PUT',
    39        data: fixtures.value
    40      })
    41    },
    42  
    43    teardown: function() {
    44      // reset the application state between each test
    45      App.reset();
    46    }
    47  });
    48  
    49  test("services", function() {
    50    visit("/")
    51  
    52    andThen(function() {
    53      ok(find("a:contains('Services')").hasClass('active'), "highlights services in nav");
    54      equal(find(".ember-list-item-view").length, 1, "renders one service");
    55      ok(find(".ember-list-item-view .name:contains('"+ fixtures.service +"')"), "uses service name");
    56      ok(find(".ember-list-item-view .name:contains('passing')"), "shows passing check num");
    57    });
    58  });
    59  
    60  test("servicesShow", function() {
    61    visit("/");
    62    // First item in list
    63    click('.ember-list-item-view .list-group-item');
    64  
    65    andThen(function() {
    66      ok(find("a:contains('Services')").hasClass('active'), "highlights services in nav");
    67      equal(find(".ember-list-item-view").length, 1, "renders one service");
    68      ok(find(".ember-list-item-view .list-group-item").hasClass('active'), "highlights active service");
    69      ok(find(".ember-list-item-view .name:contains('"+ fixtures.service +"')"), "uses service name");
    70      ok(find(".ember-list-item-view .name:contains('passing')"), "shows passing check num");
    71      ok(find("h3:contains('"+ fixtures.service+"')"), "shows service name");
    72      equal(find("h5").text(), "Nodes", "shows node list");
    73      ok(find("h3.panel-title:contains('"+ fixtures.node +"')"), "shows node name");
    74    });
    75  });
    76  
    77  test("nodes", function() {
    78    visit("/");
    79    click("a:contains('Nodes')");
    80  
    81    andThen(function() {
    82      ok(find("a:contains('Nodes')").hasClass('active'), "highlights nodes in nav");
    83      equal(find(".ember-list-item-view").length, 1, "renders one node");
    84      ok(find(".ember-list-item-view .name:contains('"+ fixtures.node +"')"), "contains node name");
    85      ok(find(".ember-list-item-view .name:contains('services')"), "contains services num");
    86    });
    87  });
    88  
    89  test("nodesShow", function() {
    90    visit("/");
    91    click("a:contains('Nodes')");
    92    // First item in list
    93    click('.ember-list-item-view .list-group-item');
    94  
    95    andThen(function() {
    96      ok(find("a:contains('Nodes')").hasClass('active'), "highlights services in nav");
    97      equal(find(".ember-list-item-view").length, 1, "renders one service");
    98      ok(find(".ember-list-item-view .list-group-item").hasClass('active'), "highlights active node");
    99      ok(find(".ember-list-item-view .name:contains('"+ fixtures.node +"')"), "uses node name");
   100      ok(find(".ember-list-item-view .name:contains('passing')"), "shows passing check num");
   101    });
   102  });
   103  
   104  test("kv", function() {
   105    visit("/");
   106    click("a:contains('Key/Value')");
   107  
   108    andThen(function() {
   109      ok(find("a:contains('Key/Value')").hasClass('active'), "highlights kv in nav");
   110      equal(find(".list-group-item").length, 1, "renders one key");
   111      ok(find(".list-group-item:contains('"+ fixtures.key +"')"), "contains key name");
   112    });
   113  });