Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(test): cover i18next locale, local script services
- Loading branch information
Showing
11 changed files
with
257 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import { BaseError } from 'noicejs'; | ||
|
||
export class AbortEventError extends BaseError { /* noop */ } | ||
export class AbortEventError extends BaseError { /* noop */ } |
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 |
---|---|---|
@@ -1,6 +1,72 @@ | ||
import { NotFoundError } from '@apextoaster/js-utils'; | ||
import { expect } from 'chai'; | ||
import { Container, NullLogger } from 'noicejs'; | ||
|
||
import { LocalModule } from '../../../src/module/LocalModule'; | ||
import { NextLocaleService } from '../../../src/service/locale/NextLocale'; | ||
|
||
describe('next locale service', () => { | ||
xit('should have an i18next instance after being started'); | ||
xit('should translate keys with context'); | ||
it('should have an i18next instance after being started', async () => { | ||
const container = Container.from(new LocalModule()); | ||
await container.configure({ | ||
logger: NullLogger.global, | ||
}); | ||
|
||
const locale = await container.create(NextLocaleService); | ||
|
||
expect(() => locale.getInstance()).to.throw(NotFoundError); | ||
|
||
await locale.start(); | ||
|
||
expect(locale.getInstance()).not.to.equal(undefined); | ||
}); | ||
|
||
it('should prefer the world bundle', async () => { | ||
const container = Container.from(new LocalModule()); | ||
await container.configure({ | ||
logger: NullLogger.global, | ||
}); | ||
|
||
const locale = await container.create(NextLocaleService); | ||
await locale.start(); | ||
|
||
locale.addBundle('common', { | ||
bundles: { | ||
en: { | ||
foo: 'bar', | ||
}, | ||
}, | ||
}); | ||
locale.addBundle('world', { | ||
bundles: { | ||
en: { | ||
foo: 'bin', | ||
}, | ||
}, | ||
}); | ||
|
||
expect(locale.translate('foo')).to.equal('bin'); | ||
}); | ||
|
||
it('should translate keys with context', async () => { | ||
const container = Container.from(new LocalModule()); | ||
await container.configure({ | ||
logger: NullLogger.global, | ||
}); | ||
|
||
const locale = await container.create(NextLocaleService); | ||
await locale.start(); | ||
|
||
locale.addBundle('common', { | ||
bundles: { | ||
en: { | ||
foo: '{{size}} bar', | ||
}, | ||
}, | ||
}); | ||
|
||
expect(locale.translate('foo', { size: 4 })).to.equal('4 bar'); | ||
}); | ||
|
||
xit('should remove language bundles'); | ||
xit('should prefer the world bundle'); | ||
}); |
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 |
---|---|---|
@@ -1,5 +1,161 @@ | ||
import { expect } from 'chai'; | ||
import { Container, NullLogger } from 'noicejs'; | ||
import { spy } from 'sinon'; | ||
|
||
import { Item } from '../../../src/model/entity/Item'; | ||
import { State } from '../../../src/model/State'; | ||
import { LocalModule } from '../../../src/module/LocalModule'; | ||
import { LocalScriptService } from '../../../src/service/script/LocalScript'; | ||
import { StateEntityTransfer } from '../../../src/util/state/EntityTransfer'; | ||
import { StateFocusResolver } from '../../../src/util/state/FocusResolver'; | ||
|
||
const TEST_STATE: State = { | ||
focus: { | ||
actor: '', | ||
room: '', | ||
}, | ||
meta: { | ||
desc: '', | ||
id: '', | ||
name: '', | ||
template: '', | ||
}, | ||
rooms: [], | ||
start: { | ||
actor: '', | ||
room: '', | ||
}, | ||
step: { | ||
time: 0, | ||
turn: 0, | ||
}, | ||
world: { | ||
depth: 0, | ||
seed: '', | ||
}, | ||
}; | ||
|
||
describe('local script service', () => { | ||
xit('should invoke the script with target'); | ||
it('should invoke the script with target', async () => { | ||
const container = Container.from(new LocalModule()); | ||
await container.configure({ | ||
logger: NullLogger.global, | ||
}); | ||
|
||
const target: Item = { | ||
type: 'item', | ||
meta: { | ||
desc: '', | ||
id: '', | ||
name: '', | ||
template: '', | ||
}, | ||
slots: new Map(), | ||
stats: new Map(), | ||
verbs: new Map(), | ||
}; | ||
|
||
const script = await container.create(LocalScriptService, {}, new Map()); | ||
await script.invoke(target, 'foo', { | ||
data: new Map(), | ||
focus: await container.create(StateFocusResolver, { | ||
events: { | ||
onActor: async () => { }, | ||
onRoom: async () => { }, | ||
onShow: async () => { }, | ||
}, | ||
state: TEST_STATE, | ||
}), | ||
state: TEST_STATE, | ||
transfer: await container.create(StateEntityTransfer, { | ||
state: TEST_STATE, | ||
}), | ||
}); | ||
}); | ||
|
||
it('should gracefully handle unknown scripts', async () => { | ||
const container = Container.from(new LocalModule()); | ||
await container.configure({ | ||
logger: NullLogger.global, | ||
}); | ||
|
||
const target: Item = { | ||
type: 'item', | ||
meta: { | ||
desc: '', | ||
id: '', | ||
name: '', | ||
template: '', | ||
}, | ||
slots: new Map([ | ||
['foo', 'none'], | ||
]), | ||
stats: new Map(), | ||
verbs: new Map(), | ||
}; | ||
|
||
const script = await container.create(LocalScriptService, {}, new Map()); | ||
await script.invoke(target, 'foo', { | ||
data: new Map(), | ||
focus: await container.create(StateFocusResolver, { | ||
events: { | ||
onActor: async () => { }, | ||
onRoom: async () => { }, | ||
onShow: async () => { }, | ||
}, | ||
state: TEST_STATE, | ||
}), | ||
state: TEST_STATE, | ||
transfer: await container.create(StateEntityTransfer, { | ||
state: TEST_STATE, | ||
}), | ||
}); | ||
}); | ||
|
||
it('should invoke scripts with entity', async () => { | ||
const container = Container.from(new LocalModule()); | ||
await container.configure({ | ||
logger: NullLogger.global, | ||
}); | ||
|
||
const target: Item = { | ||
type: 'item', | ||
meta: { | ||
desc: '', | ||
id: '', | ||
name: '', | ||
template: '', | ||
}, | ||
slots: new Map([ | ||
['foo', 'bar'], | ||
]), | ||
stats: new Map(), | ||
verbs: new Map(), | ||
}; | ||
|
||
const scriptSpy = spy(); | ||
const script = await container.create(LocalScriptService, {}, new Map([ | ||
['bar', scriptSpy], | ||
])); | ||
await script.invoke(target, 'foo', { | ||
data: new Map(), | ||
focus: await container.create(StateFocusResolver, { | ||
events: { | ||
onActor: async () => { }, | ||
onRoom: async () => { }, | ||
onShow: async () => { }, | ||
}, | ||
state: TEST_STATE, | ||
}), | ||
state: TEST_STATE, | ||
transfer: await container.create(StateEntityTransfer, { | ||
state: TEST_STATE, | ||
}), | ||
}); | ||
|
||
expect(scriptSpy).to.have.callCount(1); | ||
}); | ||
|
||
xit('should gracefully handle undefined slots'); | ||
xit('should broadcast events to matching entities'); | ||
}); |
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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import chai from 'chai'; | ||
import chaiAsPromised from 'chai-as-promised'; | ||
import sinonChai from 'sinon-chai'; | ||
|
||
export function setupTests(): void { | ||
chai.use(chaiAsPromised); | ||
chai.use(sinonChai); | ||
} | ||
|
||
setupTests(); |
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