partey_workadventure/back/tests/PositionNotifierTest.ts

249 lines
7.1 KiB
TypeScript
Raw Normal View History

import "jasmine";
2022-01-13 10:44:06 +01:00
import { PositionNotifier } from "../src/Model/PositionNotifier";
import { User, UserSocket } from "../src/Model/User";
import { Zone } from "_Model/Zone";
import { Movable } from "_Model/Movable";
import { PositionInterface } from "_Model/PositionInterface";
import { ZoneSocket } from "../src/RoomManager";
describe("PositionNotifier", () => {
it("should receive notifications when player moves", () => {
let enterTriggered = false;
let moveTriggered = false;
let leaveTriggered = false;
2022-01-13 10:44:06 +01:00
const positionNotifier = new PositionNotifier(
300,
300,
(thing: Movable) => {
enterTriggered = true;
},
(thing: Movable, position: PositionInterface) => {
moveTriggered = true;
},
(thing: Movable) => {
leaveTriggered = true;
},
() => {},
Release 1.9.6 (#2021) * Change accès token with query privateAccessToken in the url Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Add play uri param Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * PlayUri parameter Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * removed unused imports * send group userIds to players * sending info about group lock state. wip * listening to lockGroupMessage on front * cleanup * Updating GroupDescriptors on LockGroupMessage * remove console logs * group circles with color fill * fix GameRoom text * remove obsolete check * cr fixes #1 wip * much cleaner approach to group lock update * fix compilation error * well-known values wip * Removing old unused images Just a bit of cleanup! * update with dan suggest Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Change roomId by playUri Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * hide voice indicator for player leaving still existing bubble conversation * Refactor access by token Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Refactor connexion manager Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Adds settings options and localUser functions * PrivacyShutdownStore modifies constraints according to the user's setting * switches dropdown for checkboxes and adjusts wording * Adds the todo about German translation * Adds test map * Makes the default setting: camera off and mic on * Add z-index on embeds screens and action menu * Fixes tileset import * Adds settings options and localUser functions * PrivacyShutdownStore modifies constraints according to the user's setting * switches dropdown for checkboxes and adjusts wording * Adds the todo about German translation * Adds test map * Makes the default setting: camera off and mic on * Fixes tileset import * Applying German translation, thanks to @Lurkars * removed obsolete console.log * fix linter issues * make use of proto well knows types * fixed types for RoomConnection * fix locking bubble when returning from away mode * Fix run pretty Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * prevent actions menu from appearing when inserting space key on chat * Bump ansi-regex from 4.1.0 to 4.1.1 in /maps Bumps [ansi-regex](https://github.com/chalk/ansi-regex) from 4.1.0 to 4.1.1. - [Release notes](https://github.com/chalk/ansi-regex/releases) - [Commits](https://github.com/chalk/ansi-regex/compare/v4.1.0...v4.1.1) --- updated-dependencies: - dependency-name: ansi-regex dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> * Bump minimist from 1.2.5 to 1.2.6 in /desktop/local-app Bumps [minimist](https://github.com/substack/minimist) from 1.2.5 to 1.2.6. - [Release notes](https://github.com/substack/minimist/releases) - [Commits](https://github.com/substack/minimist/compare/1.2.5...1.2.6) --- updated-dependencies: - dependency-name: minimist dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> * Bump ansi-regex from 4.1.0 to 4.1.1 in /desktop/electron Bumps [ansi-regex](https://github.com/chalk/ansi-regex) from 4.1.0 to 4.1.1. - [Release notes](https://github.com/chalk/ansi-regex/releases) - [Commits](https://github.com/chalk/ansi-regex/compare/v4.1.0...v4.1.1) --- updated-dependencies: - dependency-name: ansi-regex dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> * Bump ansi-regex from 4.1.0 to 4.1.1 in /uploader Bumps [ansi-regex](https://github.com/chalk/ansi-regex) from 4.1.0 to 4.1.1. - [Release notes](https://github.com/chalk/ansi-regex/releases) - [Commits](https://github.com/chalk/ansi-regex/compare/v4.1.0...v4.1.1) --- updated-dependencies: - dependency-name: ansi-regex dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> * Bump plist from 3.0.4 to 3.0.5 in /desktop/electron Bumps [plist](https://github.com/TooTallNate/node-plist) from 3.0.4 to 3.0.5. - [Release notes](https://github.com/TooTallNate/node-plist/releases) - [Changelog](https://github.com/TooTallNate/plist.js/blob/master/History.md) - [Commits](https://github.com/TooTallNate/node-plist/commits) --- updated-dependencies: - dependency-name: plist dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Hanusiak Piotr <piotr@ltmp.co> Co-authored-by: David Négrier <d.negrier@thecodingmachine.com> Co-authored-by: Piotr 'pwh' Hanusiak <p.hanusiak@workadventu.re> Co-authored-by: Benedicte Quimbert <b.quimbert@workadventu.re> Co-authored-by: Alexis Faizeau <a.faizeau@workadventu.re> Co-authored-by: Bénédicte Q <37311765+HimeShaman@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-03-30 11:13:27 +02:00
() => {},
2022-01-13 10:44:06 +01:00
() => {}
);
const user1 = new User(
1,
"test",
"10.0.0.2",
{
x: 500,
y: 500,
moving: false,
direction: "down",
},
false,
positionNotifier,
{} as UserSocket,
[],
null,
"foo",
[]
);
const user2 = new User(
2,
"test",
"10.0.0.2",
{
x: -9999,
y: -9999,
moving: false,
direction: "down",
},
false,
positionNotifier,
{} as UserSocket,
[],
null,
"foo",
[]
);
2020-12-08 18:37:15 +01:00
positionNotifier.addZoneListener({} as ZoneSocket, 0, 0);
positionNotifier.addZoneListener({} as ZoneSocket, 0, 1);
positionNotifier.addZoneListener({} as ZoneSocket, 1, 1);
positionNotifier.addZoneListener({} as ZoneSocket, 1, 0);
/*positionNotifier.setViewport(user1, {
left: 200,
right: 600,
top: 100,
bottom: 500
2020-12-08 18:37:15 +01:00
});*/
2022-01-13 10:44:06 +01:00
user2.setPosition({ x: 500, y: 500, direction: "down", moving: false });
expect(enterTriggered).toBe(true);
expect(moveTriggered).toBe(false);
enterTriggered = false;
// Move inside the zone
2022-01-13 10:44:06 +01:00
user2.setPosition({ x: 501, y: 500, direction: "down", moving: false });
expect(enterTriggered).toBe(false);
expect(moveTriggered).toBe(true);
moveTriggered = false;
// Move out of the zone in a zone that we don't track
2022-01-13 10:44:06 +01:00
user2.setPosition({ x: 901, y: 500, direction: "down", moving: false });
expect(enterTriggered).toBe(false);
expect(moveTriggered).toBe(false);
expect(leaveTriggered).toBe(true);
leaveTriggered = false;
// Move back in
2022-01-13 10:44:06 +01:00
user2.setPosition({ x: 500, y: 500, direction: "down", moving: false });
expect(enterTriggered).toBe(true);
expect(moveTriggered).toBe(false);
expect(leaveTriggered).toBe(false);
enterTriggered = false;
// Leave the room
positionNotifier.leave(user2);
2020-12-08 18:37:15 +01:00
//positionNotifier.removeViewport(user2);
expect(enterTriggered).toBe(false);
expect(moveTriggered).toBe(false);
expect(leaveTriggered).toBe(true);
leaveTriggered = false;
});
it("should receive notifications when camera moves", () => {
let enterTriggered = false;
let moveTriggered = false;
let leaveTriggered = false;
2022-01-13 10:44:06 +01:00
const positionNotifier = new PositionNotifier(
300,
300,
(thing: Movable, fromZone: Zone | null) => {
enterTriggered = true;
},
(thing: Movable, position: PositionInterface) => {
moveTriggered = true;
},
(thing: Movable) => {
leaveTriggered = true;
},
() => {},
Release 1.9.6 (#2021) * Change accès token with query privateAccessToken in the url Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Add play uri param Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * PlayUri parameter Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * removed unused imports * send group userIds to players * sending info about group lock state. wip * listening to lockGroupMessage on front * cleanup * Updating GroupDescriptors on LockGroupMessage * remove console logs * group circles with color fill * fix GameRoom text * remove obsolete check * cr fixes #1 wip * much cleaner approach to group lock update * fix compilation error * well-known values wip * Removing old unused images Just a bit of cleanup! * update with dan suggest Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Change roomId by playUri Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * hide voice indicator for player leaving still existing bubble conversation * Refactor access by token Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Refactor connexion manager Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Adds settings options and localUser functions * PrivacyShutdownStore modifies constraints according to the user's setting * switches dropdown for checkboxes and adjusts wording * Adds the todo about German translation * Adds test map * Makes the default setting: camera off and mic on * Add z-index on embeds screens and action menu * Fixes tileset import * Adds settings options and localUser functions * PrivacyShutdownStore modifies constraints according to the user's setting * switches dropdown for checkboxes and adjusts wording * Adds the todo about German translation * Adds test map * Makes the default setting: camera off and mic on * Fixes tileset import * Applying German translation, thanks to @Lurkars * removed obsolete console.log * fix linter issues * make use of proto well knows types * fixed types for RoomConnection * fix locking bubble when returning from away mode * Fix run pretty Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * prevent actions menu from appearing when inserting space key on chat * Bump ansi-regex from 4.1.0 to 4.1.1 in /maps Bumps [ansi-regex](https://github.com/chalk/ansi-regex) from 4.1.0 to 4.1.1. - [Release notes](https://github.com/chalk/ansi-regex/releases) - [Commits](https://github.com/chalk/ansi-regex/compare/v4.1.0...v4.1.1) --- updated-dependencies: - dependency-name: ansi-regex dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> * Bump minimist from 1.2.5 to 1.2.6 in /desktop/local-app Bumps [minimist](https://github.com/substack/minimist) from 1.2.5 to 1.2.6. - [Release notes](https://github.com/substack/minimist/releases) - [Commits](https://github.com/substack/minimist/compare/1.2.5...1.2.6) --- updated-dependencies: - dependency-name: minimist dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> * Bump ansi-regex from 4.1.0 to 4.1.1 in /desktop/electron Bumps [ansi-regex](https://github.com/chalk/ansi-regex) from 4.1.0 to 4.1.1. - [Release notes](https://github.com/chalk/ansi-regex/releases) - [Commits](https://github.com/chalk/ansi-regex/compare/v4.1.0...v4.1.1) --- updated-dependencies: - dependency-name: ansi-regex dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> * Bump ansi-regex from 4.1.0 to 4.1.1 in /uploader Bumps [ansi-regex](https://github.com/chalk/ansi-regex) from 4.1.0 to 4.1.1. - [Release notes](https://github.com/chalk/ansi-regex/releases) - [Commits](https://github.com/chalk/ansi-regex/compare/v4.1.0...v4.1.1) --- updated-dependencies: - dependency-name: ansi-regex dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> * Bump plist from 3.0.4 to 3.0.5 in /desktop/electron Bumps [plist](https://github.com/TooTallNate/node-plist) from 3.0.4 to 3.0.5. - [Release notes](https://github.com/TooTallNate/node-plist/releases) - [Changelog](https://github.com/TooTallNate/plist.js/blob/master/History.md) - [Commits](https://github.com/TooTallNate/node-plist/commits) --- updated-dependencies: - dependency-name: plist dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Hanusiak Piotr <piotr@ltmp.co> Co-authored-by: David Négrier <d.negrier@thecodingmachine.com> Co-authored-by: Piotr 'pwh' Hanusiak <p.hanusiak@workadventu.re> Co-authored-by: Benedicte Quimbert <b.quimbert@workadventu.re> Co-authored-by: Alexis Faizeau <a.faizeau@workadventu.re> Co-authored-by: Bénédicte Q <37311765+HimeShaman@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-03-30 11:13:27 +02:00
() => {},
2022-01-13 10:44:06 +01:00
() => {}
);
const user1 = new User(
1,
"test",
"10.0.0.2",
{
x: 500,
y: 500,
moving: false,
direction: "down",
},
false,
positionNotifier,
{} as UserSocket,
[],
null,
"foo",
[]
);
const user2 = new User(
2,
"test",
"10.0.0.2",
{
x: 0,
y: 0,
moving: false,
direction: "down",
},
false,
positionNotifier,
{} as UserSocket,
[],
null,
"foo",
[]
);
2020-12-08 18:37:15 +01:00
const listener = {} as ZoneSocket;
positionNotifier.addZoneListener(listener, 0, 0);
positionNotifier.addZoneListener(listener, 0, 1);
positionNotifier.addZoneListener(listener, 1, 1);
positionNotifier.addZoneListener(listener, 1, 0);
/*let newUsers = positionNotifier.setViewport(user1, {
left: 200,
right: 600,
top: 100,
bottom: 500
2020-12-08 18:37:15 +01:00
});*/
positionNotifier.enter(user1);
positionNotifier.enter(user2);
2020-12-08 18:37:15 +01:00
//expect(newUsers.length).toBe(2);
expect(enterTriggered).toBe(true);
enterTriggered = false;
2020-12-08 18:37:15 +01:00
//positionNotifier.updatePosition(user2, {x:500, y:500}, {x:0, y: 0})
2022-01-13 10:44:06 +01:00
user2.setPosition({ x: 500, y: 500, direction: "down", moving: false });
2020-12-08 18:37:15 +01:00
expect(enterTriggered).toBe(true);
expect(moveTriggered).toBe(false);
expect(leaveTriggered).toBe(true);
enterTriggered = false;
leaveTriggered = false;
// Add a listener, but the user in not in this zone.
positionNotifier.addZoneListener(listener, 10, 10);
2020-12-08 18:37:15 +01:00
/*positionNotifier.setViewport(user1, {
left: 201,
right: 601,
top: 100,
bottom: 500
2020-12-08 18:37:15 +01:00
});*/
expect(enterTriggered).toBe(false);
expect(moveTriggered).toBe(false);
expect(leaveTriggered).toBe(false);
2020-12-08 18:37:15 +01:00
// Stop listening to zone
positionNotifier.removeZoneListener(listener, 1, 1);
// Move the viewport out of the user.
2020-12-08 18:37:15 +01:00
/*positionNotifier.setViewport(user1, {
left: 901,
right: 1001,
top: 100,
bottom: 500
2020-12-08 18:37:15 +01:00
});*/
expect(enterTriggered).toBe(false);
expect(moveTriggered).toBe(false);
2020-12-08 18:37:15 +01:00
expect(leaveTriggered).toBe(false);
// Move the viewport back on the user.
2020-12-08 18:37:15 +01:00
positionNotifier.addZoneListener(listener, 1, 1);
/*newUsers = positionNotifier.setViewport(user1, {
left: 200,
right: 600,
top: 100,
bottom: 500
2020-12-08 18:37:15 +01:00
});*/
2020-12-08 18:37:15 +01:00
expect(enterTriggered).toBe(false);
expect(moveTriggered).toBe(false);
expect(leaveTriggered).toBe(false);
enterTriggered = false;
2020-12-08 18:37:15 +01:00
//expect(newUsers.length).toBe(2);
});
2022-01-13 10:44:06 +01:00
});