Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Commit

Permalink
fix(cart): add all on page displays size warning
Browse files Browse the repository at this point in the history
Closes #2409
  • Loading branch information
Christine Yu committed May 17, 2016
1 parent e80697d commit b261f5c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
6 changes: 3 additions & 3 deletions app/scripts/cart/cart.controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,10 @@ module ngApp.cart.controllers {
}

addAll(): void {
if ((this.files || []).length) {
this.CartService.addFiles(this.files, false);
} else if (this.size > this.CartService.getCartVacancySize()) {
if (this.files.length > this.CartService.getCartVacancySize()) {
this.CartService.sizeWarning();
} else if ((this.files || []).length) {
this.CartService.addFiles(this.files, false);
} else {
var addingMsgPromise = this.$timeout(() => {
this.notify({
Expand Down
12 changes: 7 additions & 5 deletions app/scripts/cart/templates/add-to-cart-all-dropdown.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
type="button"
class="btn btn-success fa fa-shopping-cart"
data-ng-click="ctrl.CartService.remove(ctrl.files)">
<span class="icon-btn-label">Add to Cart</span>
<span class="icon-btn-label">Remove from Cart</span>
</button>
<button data-ng-if="!ctrl.CartService.areInCart(ctrl.files)"
type="button"
class="btn btn-primary fa fa-shopping-cart"
data-ng-click="ctrl.CartService.addFiles(ctrl.files)"
data-ng-disabled="(ctrl.CartService.getFiles().length + ctrl.files.length) > CartService.getMaxSize()">
data-ng-click="ctrl.addAll()"
data-ng-disabled="ctrl.CartService.getCartVacancySize() < ctrl.files.length">
<span class="icon-btn-label">Add to Cart</span>
</button>
<button type="button"
Expand All @@ -20,15 +20,17 @@
</button>
<ul class="dropdown-menu" role="menu">
<li>
<a data-ng-click="ctrl.addAll()">
<a data-ng-click="ctrl.addAll()"
data-ng-if="!ctrl.CartService.areInCart(ctrl.files)"
>
<span class="fa-stack">
<i class="fa fa-shopping-cart fa-stack-1x"></i>
</span>
<span data-translate>Add all files to the Cart</span>
</a>
</li>
<li>
<a data-ng-click="ctrl.removeAll()"
<a data-ng-click="ctrl.CartService.remove(ctrl.files)"
data-ng-if="ctrl.CartService.getFiles().length">
<span class="fa-stack">
<i class="fa fa-trash fa-stack-1x"></i>
Expand Down
13 changes: 11 additions & 2 deletions app/scripts/cart/tests/cart.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,22 @@ describe('Cart:', function () {
CartService.add(fileA);
expect(addCallback).to.have.been.calledOnce;
expect(CartService).to.have.property('files').to.have.length(1);
expect(CartService.isInCart(fileA.file_id));
}));

it('should list of files in cart', inject(function (CartService) {
it('should check if an array of files are in the cart', inject(function (CartService) {
var addCallback = sinon.spy(CartService, 'add');
CartService.add(fileA);
CartService.add(fileB);
expect(CartService.areInCart([fileA, fileB]));
}));

it('should get list of files in cart', inject(function (CartService) {
var addCallback = sinon.spy(CartService, 'add');
CartService.add(fileA);
expect(addCallback).to.have.been.calledOnce;
expect(CartService).to.have.property('files').to.have.length(1);
expect(CartService.getFiles().length).to.eq(1);
expect(CartService.getFiles()[0]).to.eq(fileA);
}));

it('should add a file to the cart', inject(function (CartService) {
Expand Down

0 comments on commit b261f5c

Please sign in to comment.