Skip to content

Commit

Permalink
Write tests for empty groups
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierluigi Cau committed Mar 2, 2016
1 parent 6e7884a commit 5df5f73
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 2 deletions.
60 changes: 58 additions & 2 deletions src/test/scenarios/requestApplications.test.js
Expand Up @@ -10,7 +10,10 @@ import AppsEvents from "../../js/events/AppsEvents";
import HealthStatus from "../../js/constants/HealthStatus";
import AppTypes from "../../js/constants/AppTypes";

describe("request applications", function () {
var server = config.localTestserverURI;
config.apiURL = "http://" + server.address + ":" + server.port + "/";

describe("request applications and groups", function () {

before(function (done) {
var nockResponse = {
Expand All @@ -21,6 +24,9 @@ describe("request applications", function () {
cpus: 4
}, {
id: "/app-2"
}],
groups: [{
id: "/group"
}]
};

Expand All @@ -34,7 +40,7 @@ describe("request applications", function () {
});

it("updates the AppsStore on success", function () {
expect(AppsStore.apps).to.have.length(2);
expect(AppsStore.apps).to.have.length(3);
});

it("calculate total resources", function () {
Expand Down Expand Up @@ -279,6 +285,56 @@ describe("request applications", function () {
});
});

describe("application groups", function () {
before(function (done) {
var nockResponse = {
id: "/",
apps: [{
id: "/app-1",
tasksHealthy: 0,
tasksUnhealthy: 0,
tasksRunning: 1,
tasksStaged: 0,
instances: 0
}],
groups: [{
id: "/empty-group",
apps: [],
groups: []
}, {
id: "/non-empty-group",
apps: [{
id: "/non-empty-group/app-2",
tasksHealthy: 0,
tasksUnhealthy: 0,
tasksRunning: 1,
tasksStaged: 0,
instances: 0
}],
groups: []
}]
};

nock(config.apiURL)
.get("/v2/groups")
.query(true)
.reply(200, nockResponse);

AppsStore.once(AppsEvents.CHANGE, done);
AppsActions.requestApps();
});

it("handles emtpy groups", function () {
var emptyGroup = AppsStore.apps[1];
expect(emptyGroup.id).to.eql("/empty-group");
expect(emptyGroup.isGroup).to.be.true;
});

it("handles nested applications", function () {
var nestedApp = AppsStore.apps[2];
expect(nestedApp.id).to.eql("/non-empty-group/app-2");
});
});
});

describe("on single app request", function () {
Expand Down
32 changes: 32 additions & 0 deletions src/test/units/AppListComponent.test.js
Expand Up @@ -70,6 +70,13 @@ describe("AppListComponent", function () {
instances: 1,
mem: 16,
cpus: 1
},
{
id: "/empty-group",
instances: 0,
mem: 0,
cpus: 0,
isGroup: true
}
];

Expand All @@ -92,6 +99,7 @@ describe("AppListComponent", function () {

expect(appNames).to.deep.equal([
"apps",
"empty-group",
"fuzzy",
"group-alpha",
"group-with-long-name",
Expand Down Expand Up @@ -329,6 +337,30 @@ describe("AppListComponent", function () {
expect(appNames).to.have.length(0);
this.component.instance().componentWillUnmount();
});

it("shows no items for empty groups", function () {
var context = {
router: {
getCurrentQuery: function () {
return {
filterText: "nope"
};
}
}
};

this.component = shallow(
<AppListComponent currentGroup="/empty-group" />,
{context}
);

var appNames = this.component
.find(AppListItemComponent)
.map(app => app.props().model.id);

expect(appNames).to.have.length(0);
this.component.instance().componentWillUnmount();
});
});

});

0 comments on commit 5df5f73

Please sign in to comment.