Commit 87696aa
Changed files (4)
app
commands
__tests__
components
infrastructure
screens
app/commands/__tests__/login-command_spec.js
@@ -2,15 +2,42 @@ import LoginCommand from '../login-command';
describe("LoginCommand", () => {
let subject = null;
+ let eventAggregator = null;
+ let api = null;
beforeEach(() => {
- subject = new LoginCommand();
+ api = { post: jest.fn() };
+ eventAggregator = { publish: jest.fn() };
+ subject = new LoginCommand(eventAggregator, api);
});
describe("#notify", () => {
it ("does something", () => {
- subject.notify({
- event: 'LOGIN',
+ const func = jest.fn();
+ func();
+ expect(func).toHaveBeenCalled();
+ });
+
+ it("posts data to the api", () => {
+ subject.notify({event: 'LOGIN', username: 'mokha', password: 'password'});
+ expect(api.post).toHaveBeenCalled();
+ });
+ });
+
+ describe("#onResponse", () => {
+ it("publishes an event", () => {
+ username = 'mokha';
+ token = 'token';
+
+ subject.onResponse({
+ username: username,
+ authentication_token: token,
+ });
+
+ expect(eventAggregator.publish).toHaveBeenCalledWith({
+ event: 'LOGGED_IN',
+ username: username,
+ authentication_token: token,
});
});
});
app/components/application-shell.js
@@ -10,7 +10,6 @@ export default class ApplicationShell extends Component {
super(props);
const eventAggregator = new EventAggregator();
this.router = new Router({eventAggregator});
-
this.registerCommands(eventAggregator);
}
app/infrastructure/event-aggregator.js
@@ -4,12 +4,10 @@ export default class EventAggregator {
}
subscribe(event, subscriber) {
- console.log(`subscribe to ${event}`);
this._subscriptionsFor(event).push(subscriber);
}
publish(event) {
- console.log(`publish ${event}`);
this._subscriptionsFor(event.event).forEach(x => x.notify(event));
}
app/screens/login-screen.js
@@ -54,16 +54,12 @@ export default class LoginScreen extends ApplicationComponent {
this.setState({account: account});
}
- openDashboard(username) {
- this.props.navigator.push({
- component: DashboardScreen, params: { username: username }
- });
- }
-
notify(event) {
console.log("IN LOGIN SCREEN");
console.log(event);
- this.openDashboard(event.username);
+ this.props.navigator.push({
+ component: DashboardScreen, params: { username: username }
+ });
}
}