-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
107 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import {Behavior} from './behavior'; | ||
import {addBehavior, Inject} from '../utils'; | ||
import {Action} from '../actions'; | ||
|
||
export class PaginatableActionsBehavior extends Behavior { | ||
@Inject('ApplicationDispatcher') dispatch | ||
constructor(instance) { | ||
super(...arguments); | ||
this.dispatchInstance = instance; | ||
} | ||
|
||
@Action('changeLimit', true) changeLimit() {} | ||
@Action('changePage', true) changePage() {} | ||
} | ||
|
||
export function PaginatableActions() { | ||
return cls => { | ||
addBehavior(cls, PaginatableActionsBehavior, { | ||
property: 'paginatableActions', | ||
proxy: ['changeLimit', 'changePage'] | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/*eslint-env node, jasmine*//*global module inject*/ | ||
/*eslint-disable max-statements, max-params*/ | ||
import angular from 'angular'; | ||
import 'angular-mocks'; | ||
import 'luxyflux/ng-luxyflux'; | ||
|
||
import { | ||
Annotations, | ||
Actions, | ||
PaginatableActions, | ||
PaginatableActionsBehavior | ||
} from 'anglue/anglue'; | ||
|
||
describe('PaginatableActions', () => { | ||
// Clear the AnnotationCache for unit tests to ensure we create new annotations for each class. | ||
beforeEach(() => { | ||
Annotations.clear(); | ||
}); | ||
|
||
describe('PaginatableActionsBehavior', () => { | ||
let mockInstance, behavior; | ||
|
||
beforeEach(() => { | ||
behavior = new PaginatableActionsBehavior(mockInstance); | ||
}); | ||
|
||
it('should have a changeLimit function', () => { | ||
expect(behavior.changeLimit).toBeDefined(); | ||
}); | ||
|
||
it('should have a changePage function', () => { | ||
expect(behavior.changePage).toBeDefined(); | ||
}); | ||
}); | ||
|
||
describe('@PaginatableActions() decorator', () => { | ||
@Actions() | ||
@PaginatableActions() | ||
class PaginatableTestActions {} | ||
|
||
let testActions; | ||
let appDispatcher; | ||
|
||
class MockApplicationDispatcher { | ||
dispatch() {} | ||
} | ||
|
||
angular | ||
.module('paginatableActionsApp', [ | ||
'luxyflux', | ||
PaginatableTestActions.annotation.module.name | ||
]) | ||
.service('ApplicationDispatcher', [ | ||
function () { | ||
return new MockApplicationDispatcher(); | ||
} | ||
]); | ||
|
||
beforeEach(module('paginatableActionsApp')); | ||
beforeEach(inject((_PaginatableTestActions_, _ApplicationDispatcher_) => { | ||
testActions = _PaginatableTestActions_; | ||
appDispatcher = _ApplicationDispatcher_; | ||
|
||
spyOn(appDispatcher, 'dispatch'); | ||
})); | ||
|
||
|
||
it('should dispatch an action', () => { | ||
expect(testActions.changeLimit(1)); | ||
expect(appDispatcher.dispatch).toHaveBeenCalledWith('CHANGELIMIT', 1); | ||
}); | ||
|
||
}); | ||
}); |