Skip to content

Commit

Permalink
test(rxApp): More basic properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
Droogans committed Apr 25, 2014
1 parent be0dc86 commit ca755d7
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 28 deletions.
38 changes: 35 additions & 3 deletions src/rxApp/docs/rxApp.midway.js
Expand Up @@ -13,16 +13,48 @@ describe('rxApp', function () {
});

it('should show element', function () {
expect(rxApp.rootElement.isDisplayed()).to.eventually.eq.true;
expect(rxApp.rootElement.isDisplayed()).to.eventually.be.true;
});

describe('Collapsible Navigation', function () {
it('should have a title', function () {
expect(rxApp.title).to.eventually.equal('My App');
});

it('should have a section title', function () {
expect(rxApp.sectionTitle).to.eventually.equal('Example Menu');
});

it('should have a logout link', function () {
expect(rxApp.lnkLogout.isDisplayed()).to.eventually.be.true;
});

it('should not support a toggle show/hide button', function () {
expect(rxApp.isCollapsible()).to.eventually.be.false;
});

it('should throw an error if you attempt to expand and unsupported', function () {
expect(rxApp.expand()).to.be.rejectedWith('My App');
});

describe('with collapsible navigation', function () {
before(function () {
rxApp = rxAppPage.initialize($('#collapsible-rxApp'));
});

it('should have a title', function () {
expect(rxApp.title).to.eventually.equal('Encore');
});

it('should have a section title', function () {
expect(rxApp.sectionTitle).to.eventually.equal('All Tools');
});

it('should have a logout link', function () {
expect(rxApp.lnkLogout.isDisplayed()).to.eventually.be.true;
});

it('should have a collapsible navigation menu', function () {
expect(rxApp.isCollapsible()).to.be.true;
expect(rxApp.isCollapsible()).to.eventually.be.true;
});

it('should be expanded by default', function () {
Expand Down
64 changes: 39 additions & 25 deletions src/rxApp/rxApp.page.js
Expand Up @@ -3,34 +3,46 @@ var Page = require('astrolabe').Page;

var rxApp = {

lblSiteTitle: {
get: function () { return this.rootElement.$('.rx-app .site-title'); }
cssCollapseButtonSelector: {
// Keep just the css string available for both the button element
// and the check made in `isCollapsible()`, which uses findAllBy.
get: function () { return '.collapsible-toggle'; }
},

lblNavTitle: {
get: function () { return this.rootElement.$('.site-title'); }
},

lblNavSectionTitle: {
get: function () { return this.rootElement.$('.nav-section-title'); }
},

eleSiteNav: {
get: function () { return this.rootElement.$('.rx-app-nav'); }
},

btnCollapseToggle: {
get: function () { return this.rootElement.$('.collapsible-toggle'); }
get: function () { return this.rootElement.$(this.cssCollapseButtonSelector); }
},

toggleCollapse: {
value: function () {
if (!this.isCollapsible()) {
this.NotCollapsibleException.thro();
}
lnkLogout: {
get: function () { return this.rootElement.$('.site-logout'); }
},

this.btnCollapseToggle.click();
}
title: {
get: function () { return this.lblNavTitle.getText(); }
},

sectionTitle: {
get: function () { return this.lblNavSectionTitle.getText(); }
},

expand: {
value: function () {
var page = this;
return this.isCollapsed().then(function (collapsed) {
if (collapsed) {
page.toggleCollapse();
page.btnCollapseToggle.click();
}
});
}
Expand All @@ -41,20 +53,25 @@ var rxApp = {
var page = this;
return this.isExpanded().then(function (expanded) {
if (expanded) {
page.toggleCollapse();
page.btnCollapseToggle.click();
}
});
}
},

isCollapsed: {
value: function () {
if (!this.isCollapsible()) {
this.NotCollapsibleException.thro();
}
var page = this;
return this.isCollapsible().then(function (isCollapsible) {
if (!isCollapsible) {
return page.title.then(function (siteTitle) {
page.NotCollapsibleException.thro(siteTitle);
});
}

return this.rootElement.$('.rx-app').getAttribute('class').then(function (classNames) {
return (classNames.indexOf('collapsed') >= 0);
return page.rootElement.$('.rx-app').getAttribute('class').then(function (classNames) {
return (classNames.indexOf('collapsed') >= 0);
});
});
}
},
Expand All @@ -69,21 +86,18 @@ var rxApp = {

isCollapsible: {
value: function () {
try {
this.btnCollapseToggle.isDisplayed();
} catch (err) {
return false;
}

return true;
return this.rootElement.$$(this.cssCollapseButtonSelector).then(function (exists) {
return exists.length ? true : false;
});
}
},

NotCollapsibleException: {
get: function () {
return this.exception('The navigation menu is not collapsible');
return this.exception('Navigation menu not collapsible');
}
}

};

exports.rxApp = {
Expand Down

0 comments on commit ca755d7

Please sign in to comment.