Skip to content

Commit

Permalink
Added test and mock for checking on the image formcontroller
Browse files Browse the repository at this point in the history
  • Loading branch information
zakhenry committed Sep 18, 2015
1 parent 772ccc7 commit a0ad669
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
6 changes: 4 additions & 2 deletions app/src/app/admin/media/media.spec.ts
Expand Up @@ -35,6 +35,9 @@ namespace app.admin.media {
initialImages: images,
$stateParams: $stateParams
});

MediaController.imageUploadForm = global.FormControllerMock.getMock();

});

});
Expand Down Expand Up @@ -98,10 +101,9 @@ namespace app.admin.media {

$scope.$apply();


expect(MediaController.images.length).to.equal(imageViewCount); //length should not have changed
expect(MediaController.images[0].title).to.equal(image.title); //first image should have been pushed on

expect(MediaController.imageUploadForm.$setPristine).to.have.been.called;

});

Expand Down
2 changes: 1 addition & 1 deletion app/src/common/services/region/regionInterceptor.ts
@@ -1,6 +1,6 @@
namespace common.services.region {

type IRequestConfig = /*ng.IRequestConfig |*/ NgRestAdapter.INgRestAdapterRequestConfig;
type IRequestConfig = ng.IRequestConfig & NgRestAdapter.INgRestAdapterRequestConfig;

export class RegionInterceptor {

Expand Down
31 changes: 31 additions & 0 deletions app/src/global.mock.ts
@@ -0,0 +1,31 @@
namespace global {

export class FormControllerMock{

public static getMock(overrides:Object = {}):ng.IFormController {

let defaults = {
$pristine: false,
$dirty: true,
$valid: true,
$invalid: false,
$submitted: false,
$error: {},
$addControl: sinon.stub(),
$removeControl: sinon.stub(),
$setValidity:sinon.stub(),
$setDirty: sinon.stub(),
$setPristine: sinon.stub(),
$commitViewValue: sinon.stub(),
$rollbackViewValue: sinon.stub(),
$setSubmitted: sinon.stub(),
$setUntouched: sinon.stub(),
};

return <ng.IFormController>_.merge(defaults, overrides);

}

}

}

0 comments on commit a0ad669

Please sign in to comment.