@aller/blink
Version:
A library for tracking user behaviour.
158 lines • 4.95 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var player_1 = __importDefault(require("../player"));
var actions_1 = require("../../actions");
describe('Player reducer', function () {
it('should add a new entry if playerId not in state', function () {
var action = {
type: actions_1.PLAYER_SHOWN,
payload: {
playerId: '112',
reason: 'viewable',
time: new Date(0),
muted: true,
position: 50,
volume: 50,
},
};
var events = {
'111': [
{
type: 'shown',
reason: 'viewable',
time: new Date(0),
muted: true,
position: 50,
volume: 50,
},
],
};
expect(player_1.default(events, action)).toEqual({
'111': [
{
type: 'shown',
reason: 'viewable',
time: new Date(0),
muted: true,
position: 50,
volume: 50,
},
],
'112': [
{
type: 'shown',
reason: 'viewable',
time: new Date(0),
muted: true,
position: 50,
volume: 50,
},
],
});
});
it('should append to existing entry if playerId already in state', function () {
var action = {
type: actions_1.PLAYER_SHOWN,
payload: {
playerId: '111',
reason: 'viewable',
time: new Date(0),
muted: true,
position: 50,
volume: 50,
},
};
var events = {
'111': [
{
type: 'shown',
reason: 'viewable',
time: new Date(0),
muted: true,
position: 50,
volume: 50,
},
],
};
expect(player_1.default(events, action)).toEqual({
'111': [
{
type: 'shown',
reason: 'viewable',
time: new Date(0),
muted: true,
position: 50,
volume: 50,
},
{
type: 'shown',
reason: 'viewable',
time: new Date(0),
muted: true,
position: 50,
volume: 50,
},
],
});
});
describe('PLAYER_SHOWN', function () {
it('should add a player shown event to existing state', function () {
var action = {
type: actions_1.PLAYER_SHOWN,
payload: {
playerId: '111',
reason: 'viewable',
time: new Date(0),
muted: true,
position: 50,
volume: 50,
},
};
var expectedEvents = {
'111': [
{
type: 'shown',
reason: 'viewable',
time: new Date(0),
muted: true,
position: 50,
volume: 50,
},
],
};
expect(player_1.default({}, action)).toEqual(expectedEvents);
});
});
describe('PLAYER_HIDDEN', function () {
it('should add a player hidden event to existing state', function () {
var action = {
type: actions_1.PLAYER_HIDDEN,
payload: {
playerId: '111',
reason: 'tabhide',
time: new Date(1),
muted: true,
position: 50,
volume: 50,
},
};
var expectedEvents = {
'111': [
{
time: new Date(1),
reason: 'tabhide',
type: 'hidden',
muted: true,
position: 50,
volume: 50,
},
],
};
expect(player_1.default({}, action)).toEqual(expectedEvents);
});
});
});
//# sourceMappingURL=player.test.js.map
;