Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(util): add and test entity containment helpers (fixes #53)
- Loading branch information
Showing
4 changed files
with
267 additions
and
6 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
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,188 @@ | ||
import { expect } from 'chai'; | ||
import { ActorType, ACTOR_TYPE } from '../../../src/model/entity/Actor'; | ||
|
||
import { ITEM_TYPE } from '../../../src/model/entity/Item'; | ||
import { ROOM_TYPE } from '../../../src/model/entity/Room'; | ||
import { State } from '../../../src/model/State'; | ||
import { findContainer, findRoom, searchState } from '../../../src/util/state'; | ||
|
||
const TEST_STATE: State = { | ||
focus: { | ||
actor: '', | ||
room: '', | ||
}, | ||
meta: { | ||
desc: '', | ||
id: '', | ||
name: '', | ||
template: '', | ||
}, | ||
rooms: [{ | ||
actors: [{ | ||
actorType: ActorType.DEFAULT, | ||
items: [{ | ||
meta: { | ||
desc: 'bon', | ||
id: 'bon', | ||
name: 'bon', | ||
template: 'bon', | ||
}, | ||
slots: new Map(), | ||
stats: new Map(), | ||
type: ITEM_TYPE, | ||
verbs: new Map(), | ||
}], | ||
meta: { | ||
desc: 'bun', | ||
id: 'bun', | ||
name: 'bun', | ||
template: 'bun', | ||
}, | ||
skills: new Map(), | ||
slots: new Map(), | ||
stats: new Map(), | ||
type: ACTOR_TYPE, | ||
}], | ||
items: [], | ||
meta: { | ||
desc: 'foo', | ||
id: 'foo', | ||
name: 'foo', | ||
template: 'foo', | ||
}, | ||
portals: [], | ||
slots: new Map(), | ||
type: ROOM_TYPE, | ||
verbs: new Map(), | ||
}, { | ||
actors: [], | ||
items: [{ | ||
meta: { | ||
desc: 'bin', | ||
id: 'bin', | ||
name: 'bin', | ||
template: 'bin', | ||
}, | ||
slots: new Map(), | ||
stats: new Map(), | ||
type: ITEM_TYPE, | ||
verbs: new Map(), | ||
}], | ||
meta: { | ||
desc: 'bar', | ||
id: 'bar', | ||
name: 'bar', | ||
template: 'bar', | ||
}, | ||
portals: [], | ||
slots: new Map(), | ||
type: ROOM_TYPE, | ||
verbs: new Map(), | ||
}], | ||
start: { | ||
actor: '', | ||
room: '', | ||
}, | ||
step: { | ||
time: 0, | ||
turn: 0, | ||
}, | ||
world: { | ||
depth: 0, | ||
seed: '', | ||
}, | ||
}; | ||
|
||
describe('state search utils', () => { | ||
describe('search state helper', () => { | ||
it('should return matching entities', async () => { | ||
const results = searchState(TEST_STATE, { | ||
meta: { | ||
id: 'bar', | ||
}, | ||
type: ROOM_TYPE, | ||
}); | ||
|
||
expect(results).to.deep.equal([ | ||
TEST_STATE.rooms[1], | ||
]); | ||
}); | ||
|
||
it('should skip the contents of rooms that do not match the room filter', async () => { | ||
const results = searchState(TEST_STATE, { | ||
meta: { | ||
id: 'bin', | ||
}, | ||
room: { | ||
id: 'foo', | ||
}, | ||
type: ROOM_TYPE, | ||
}); | ||
|
||
expect(results).to.deep.equal([]); | ||
}); | ||
|
||
xit('should skip the inventory of actors that do not match the actor filter'); | ||
}); | ||
|
||
describe('find room helper', () => { | ||
it('should return the room containing an actor', async () => { | ||
const results = findRoom(TEST_STATE, { | ||
meta: { | ||
id: 'bun', | ||
}, | ||
}); | ||
expect(results).to.deep.equal([ | ||
TEST_STATE.rooms[0], | ||
]); | ||
}); | ||
|
||
it('should return the room containing an item', async () => { | ||
const results = findRoom(TEST_STATE, { | ||
meta: { | ||
id: 'bin', | ||
}, | ||
}); | ||
expect(results).to.deep.equal([ | ||
TEST_STATE.rooms[1], | ||
]); | ||
}); | ||
}); | ||
|
||
describe('find container helper', () => { | ||
it('should return the actor containing an item', async () => { | ||
const results = findContainer(TEST_STATE, { | ||
meta: { | ||
id: 'bon', | ||
}, | ||
}); | ||
expect(results).to.deep.equal([ | ||
TEST_STATE.rooms[0].actors[0], | ||
]); | ||
}); | ||
|
||
it('should return the room containing an actor', async () => { | ||
const results = findContainer(TEST_STATE, { | ||
meta: { | ||
id: 'bun', | ||
}, | ||
}); | ||
expect(results).to.deep.equal([ | ||
TEST_STATE.rooms[0], | ||
]); | ||
}); | ||
|
||
it('should return the room containing an item', async () => { | ||
const results = findContainer(TEST_STATE, { | ||
meta: { | ||
id: 'bin', | ||
}, | ||
}); | ||
expect(results).to.deep.equal([ | ||
TEST_STATE.rooms[1], | ||
]); | ||
}); | ||
}); | ||
}); | ||
|
||
|