Fixing tests
This commit is contained in:
parent
432b4a0e85
commit
a37557dd4b
@ -8,6 +8,7 @@ import {PointInterface} from "../src/Model/Websocket/PointInterface";
|
|||||||
import {Zone} from "_Model/Zone";
|
import {Zone} from "_Model/Zone";
|
||||||
import {Movable} from "_Model/Movable";
|
import {Movable} from "_Model/Movable";
|
||||||
import {PositionInterface} from "_Model/PositionInterface";
|
import {PositionInterface} from "_Model/PositionInterface";
|
||||||
|
import {ExSocketInterface} from "_Model/Websocket/ExSocketInterface";
|
||||||
|
|
||||||
|
|
||||||
describe("PositionNotifier", () => {
|
describe("PositionNotifier", () => {
|
||||||
@ -29,14 +30,14 @@ describe("PositionNotifier", () => {
|
|||||||
y: 500,
|
y: 500,
|
||||||
moving: false,
|
moving: false,
|
||||||
direction: 'down'
|
direction: 'down'
|
||||||
}, false, positionNotifier);
|
}, false, positionNotifier, {} as ExSocketInterface);
|
||||||
|
|
||||||
const user2 = new User(2, {
|
const user2 = new User(2, {
|
||||||
x: -9999,
|
x: -9999,
|
||||||
y: -9999,
|
y: -9999,
|
||||||
moving: false,
|
moving: false,
|
||||||
direction: 'down'
|
direction: 'down'
|
||||||
}, false, positionNotifier);
|
}, false, positionNotifier, {} as ExSocketInterface);
|
||||||
|
|
||||||
positionNotifier.setViewport(user1, {
|
positionNotifier.setViewport(user1, {
|
||||||
left: 200,
|
left: 200,
|
||||||
@ -107,14 +108,14 @@ describe("PositionNotifier", () => {
|
|||||||
y: 500,
|
y: 500,
|
||||||
moving: false,
|
moving: false,
|
||||||
direction: 'down'
|
direction: 'down'
|
||||||
}, false, positionNotifier);
|
}, false, positionNotifier, {} as ExSocketInterface);
|
||||||
|
|
||||||
const user2 = new User(2, {
|
const user2 = new User(2, {
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
moving: false,
|
moving: false,
|
||||||
direction: 'down'
|
direction: 'down'
|
||||||
}, false, positionNotifier);
|
}, false, positionNotifier, {} as ExSocketInterface);
|
||||||
|
|
||||||
let newUsers = positionNotifier.setViewport(user1, {
|
let newUsers = positionNotifier.setViewport(user1, {
|
||||||
left: 200,
|
left: 200,
|
||||||
|
@ -2,22 +2,30 @@ import "jasmine";
|
|||||||
import {World, ConnectCallback, DisconnectCallback } from "../src/Model/World";
|
import {World, ConnectCallback, DisconnectCallback } from "../src/Model/World";
|
||||||
import {Point} from "../src/Model/Websocket/MessageUserPosition";
|
import {Point} from "../src/Model/Websocket/MessageUserPosition";
|
||||||
import { Group } from "../src/Model/Group";
|
import { Group } from "../src/Model/Group";
|
||||||
|
import {ExSocketInterface} from "_Model/Websocket/ExSocketInterface";
|
||||||
|
import {User} from "_Model/User";
|
||||||
|
|
||||||
|
function createMockUser(userId: number): ExSocketInterface {
|
||||||
|
return {
|
||||||
|
userId
|
||||||
|
} as ExSocketInterface;
|
||||||
|
}
|
||||||
|
|
||||||
describe("World", () => {
|
describe("World", () => {
|
||||||
it("should connect user1 and user2", () => {
|
it("should connect user1 and user2", () => {
|
||||||
let connectCalledNumber: number = 0;
|
let connectCalledNumber: number = 0;
|
||||||
const connect: ConnectCallback = (user: number, group: Group): void => {
|
const connect: ConnectCallback = (user: User, group: Group): void => {
|
||||||
connectCalledNumber++;
|
connectCalledNumber++;
|
||||||
}
|
}
|
||||||
const disconnect: DisconnectCallback = (user: number, group: Group): void => {
|
const disconnect: DisconnectCallback = (user: User, group: Group): void => {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const world = new World(connect, disconnect, 160, 160, () => {}, () => {}, () => {});
|
const world = new World(connect, disconnect, 160, 160, () => {}, () => {}, () => {});
|
||||||
|
|
||||||
world.join({ userId: 1 }, new Point(100, 100));
|
world.join(createMockUser(1), new Point(100, 100));
|
||||||
|
|
||||||
world.join({ userId: 2 }, new Point(500, 100));
|
world.join(createMockUser(2), new Point(500, 100));
|
||||||
|
|
||||||
world.updatePosition({ userId: 2 }, new Point(261, 100));
|
world.updatePosition({ userId: 2 }, new Point(261, 100));
|
||||||
|
|
||||||
@ -33,24 +41,24 @@ describe("World", () => {
|
|||||||
|
|
||||||
it("should connect 3 users", () => {
|
it("should connect 3 users", () => {
|
||||||
let connectCalled: boolean = false;
|
let connectCalled: boolean = false;
|
||||||
const connect: ConnectCallback = (user: number, group: Group): void => {
|
const connect: ConnectCallback = (user: User, group: Group): void => {
|
||||||
connectCalled = true;
|
connectCalled = true;
|
||||||
}
|
}
|
||||||
const disconnect: DisconnectCallback = (user: number, group: Group): void => {
|
const disconnect: DisconnectCallback = (user: User, group: Group): void => {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const world = new World(connect, disconnect, 160, 160, () => {}, () => {}, () => {});
|
const world = new World(connect, disconnect, 160, 160, () => {}, () => {}, () => {});
|
||||||
|
|
||||||
world.join({ userId: 1 }, new Point(100, 100));
|
world.join(createMockUser(1), new Point(100, 100));
|
||||||
|
|
||||||
world.join({ userId: 2 }, new Point(200, 100));
|
world.join(createMockUser(2), new Point(200, 100));
|
||||||
|
|
||||||
expect(connectCalled).toBe(true);
|
expect(connectCalled).toBe(true);
|
||||||
connectCalled = false;
|
connectCalled = false;
|
||||||
|
|
||||||
// baz joins at the outer limit of the group
|
// baz joins at the outer limit of the group
|
||||||
world.join({ userId: 3 }, new Point(311, 100));
|
world.join(createMockUser(3), new Point(311, 100));
|
||||||
|
|
||||||
expect(connectCalled).toBe(false);
|
expect(connectCalled).toBe(false);
|
||||||
|
|
||||||
@ -62,18 +70,18 @@ describe("World", () => {
|
|||||||
it("should disconnect user1 and user2", () => {
|
it("should disconnect user1 and user2", () => {
|
||||||
let connectCalled: boolean = false;
|
let connectCalled: boolean = false;
|
||||||
let disconnectCallNumber: number = 0;
|
let disconnectCallNumber: number = 0;
|
||||||
const connect: ConnectCallback = (user: number, group: Group): void => {
|
const connect: ConnectCallback = (user: User, group: Group): void => {
|
||||||
connectCalled = true;
|
connectCalled = true;
|
||||||
}
|
}
|
||||||
const disconnect: DisconnectCallback = (user: number, group: Group): void => {
|
const disconnect: DisconnectCallback = (user: User, group: Group): void => {
|
||||||
disconnectCallNumber++;
|
disconnectCallNumber++;
|
||||||
}
|
}
|
||||||
|
|
||||||
const world = new World(connect, disconnect, 160, 160, () => {}, () => {}, () => {});
|
const world = new World(connect, disconnect, 160, 160, () => {}, () => {}, () => {});
|
||||||
|
|
||||||
world.join({ userId: 1 }, new Point(100, 100));
|
world.join(createMockUser(1), new Point(100, 100));
|
||||||
|
|
||||||
world.join({ userId: 2 }, new Point(259, 100));
|
world.join(createMockUser(2), new Point(259, 100));
|
||||||
|
|
||||||
expect(connectCalled).toBe(true);
|
expect(connectCalled).toBe(true);
|
||||||
expect(disconnectCallNumber).toBe(0);
|
expect(disconnectCallNumber).toBe(0);
|
||||||
|
Loading…
Reference in New Issue
Block a user