Skip to content

Commit

Permalink
Add test for ExpressionManager
Browse files Browse the repository at this point in the history
  • Loading branch information
guansss committed Jun 24, 2022
1 parent 081a9ed commit 7a81ec2
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion test/assets/haru/expressions/F01.exp3.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"Type": "Live2D Expression",
"Parameters": [
{
"Id": "ParamMouthForm",
"Id": "ParamMouthOpenY",
"Value": 0.27,
"Blend": "Add"
}
Expand Down
42 changes: 42 additions & 0 deletions test/module/ExpressionManager.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { config } from '@/config';
import { Cubism4ModelSettings } from '@/cubism4/Cubism4ModelSettings';
import '@/factory';
import { expect } from 'chai';
import sinon from 'sinon';
import { Cubism4ExpressionManager } from '../../src';
import { TEST_MODEL4 } from '../env';

describe('ExpressionManager', function () {
let clock;

before(() => {
clock = sinon.useFakeTimers();
});

after(function () {
clock.restore();
});

it('should update parameters', async function () {
const epsilon = 1e-5;

const expManager = new Cubism4ExpressionManager(new Cubism4ModelSettings(TEST_MODEL4.json));
const expJson = require('../assets/haru/expressions/F01.exp3.json');
const expParamId = expJson.Parameters[0].Id;
const expParamValue = expJson.Parameters[0].Value;

expect(TEST_MODEL4.coreModel.getParameterValueById(expParamId)).to.not.closeTo(expParamValue, epsilon);

await expManager.setExpression('f00');

// let the expression start
expManager.update(TEST_MODEL4.coreModel, performance.now());

clock.tick(config.expressionFadingDuration);

const updated = expManager.update(TEST_MODEL4.coreModel, performance.now());

expect(updated).to.be.true;
expect(TEST_MODEL4.coreModel.getParameterValueById(expParamId)).to.closeTo(expParamValue, epsilon);
});
});
3 changes: 3 additions & 0 deletions test/module/compat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { TEST_TEXTURE } from '../env';
import { delay } from '../utils';

describe('Compatibility', function() {
// for some reason these tests may exceed the default timeout (2000ms) in CI
this.timeout(5000);

const ITEM_SIZE = 32;
let itemOriginY = 0;

Expand Down
1 change: 1 addition & 0 deletions test/module/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export * from './FocusController.test';
export * from './ModelSettings.test';
export * from './SoundManager.test';
export * from './MotionManager.test';
export * from './ExpressionManager.test';
export * from './InternalModel.test';
export * from './Live2DFactory.test';
export * from './loaders.test';
Expand Down

0 comments on commit 7a81ec2

Please sign in to comment.