This repository has been archived by the owner on Jun 14, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #130 from Ragg-/fix/project-entity-broken-on-save
Fix project entity broken on serialization / deserialization
- Loading branch information
Showing
5 changed files
with
163 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import Keyframe from '../keyframe' | ||
import ColorRGB from '../../values/color-rgb' | ||
import ColorRGBA from '../../values/color-rgba' | ||
|
||
import assign from '../../__spec__/Utils/assign' | ||
|
||
describe('Keyframe', () => { | ||
const baseParam = Object.freeze({ easeInParam: [1, 1] as [number, number], easeOutParam: [1, 1] as [number, number], frameOnClip: 0, value: null }) | ||
|
||
it('Should correct toJSON / fromJSON with number value', () => { | ||
const numberKf = assign(new Keyframe(), { ...baseParam, value: 1 }) | ||
const expected = { id: numberKf.id, config: { ...baseParam, value: 1 } } | ||
|
||
expect(numberKf.toJSON()).to.eql(expected) | ||
expect(Keyframe.deserialize(numberKf.toJSON()).toJSON()).to.eql(expected) | ||
}) | ||
|
||
it('Should correct toJSON / fromJSON with boolean value', () => { | ||
const booleanKf = assign(new Keyframe(), { ...baseParam, value: 1 }) | ||
const expected = { id: booleanKf.id , config: { ...baseParam, value: true } } | ||
|
||
expect(booleanKf.toJSON()).to.eql(expected) | ||
expect(Keyframe.deserialize(booleanKf.toJSON()).toJSON()).to.eql(expected) | ||
}) | ||
|
||
it('Should correct toJSON / fromJSON with string value', () => { | ||
const stringKf = assign(new Keyframe(), { ...baseParam, value: 'string' }) | ||
const expected = { id: stringKf.id, config: { ...baseParam, value: 'string' } } | ||
|
||
expect(stringKf.toJSON()).to.eql(expected) | ||
expect(Keyframe.deserialize(stringKf.toJSON()).toJSON()).to.eql(expected) | ||
}) | ||
|
||
it('Should correct toJSON / fromJSON with AssetPointer value', () => { | ||
const assetKf = assign(new Keyframe(), { ...baseParam, value: { assetId: 'asset-id' } }) | ||
const expected = { id: assetKf.id, config: { ...baseParam, value: { type: 'asset', value: { assetId: 'asset-id' } } } } | ||
|
||
expect(assetKf.toJSON()).to.eql(expected) | ||
expect(Keyframe.deserialize(assetKf.toJSON()).toJSON()).to.eql(expected) | ||
}) | ||
|
||
it('Should correct toJSON / fromJSON with ColorRGB value', () => { | ||
const assetKf = assign(new Keyframe(), { ...baseParam, value: new ColorRGB(0, 1, 2) }) | ||
const expected = { id: assetKf.id, config: { ...baseParam, value: { type: 'color-rgb', value: { red: 0, green: 1, blue: 2 } } } } | ||
|
||
expect(assetKf.toJSON()).to.eql(expected) | ||
|
||
const restoredKf = Keyframe.deserialize(assetKf.toJSON()) | ||
expect(restoredKf.toJSON()).to.eql(expected) | ||
expect(restoredKf.value).to.eql(new ColorRGB(0, 1, 2)) | ||
}) | ||
|
||
it('Should correct toJSON / fromJSON with ColorRGBA value', () => { | ||
const assetKf = assign(new Keyframe(), { ...baseParam, value: new ColorRGBA(0, 1, 2, 3) }) | ||
const expected = { id: assetKf.id, config: { ...baseParam, value: { type: 'color-rgba', value: { red: 0, green: 1, blue: 2, alpha: 3 } } } } | ||
|
||
expect(assetKf.toJSON()).to.eql(expected) | ||
|
||
const restoredKf = Keyframe.deserialize(assetKf.toJSON()) | ||
expect(restoredKf.toJSON()).to.eql(expected) | ||
expect(restoredKf.value).to.eql(new ColorRGBA(0, 1, 2, 3)) | ||
}) | ||
|
||
it('Should failed fromJSON with unexpected input', () => { | ||
expect(() => { | ||
Keyframe.deserialize({ | ||
id: 'kfid', | ||
config: { | ||
...baseParam, | ||
value: { | ||
type: 'あたまわるわる〜', | ||
value: '✌(´◓q◔`)✌' | ||
} as any | ||
} | ||
}) | ||
}).throwError() | ||
}) | ||
}) |
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,25 +1,31 @@ | ||
import Point2D from '../../values/point-2d' | ||
import Point3D from '../../values/point-3d' | ||
import Size2D from '../../values/size-2d' | ||
import Size3D from '../../values/size-3d' | ||
import ColorRGB from '../../values/color-rgb' | ||
import ColorRGBA from '../../values/color-rgba' | ||
// import Point2D from '../../values/point-2d' | ||
// import Point3D from '../../values/point-3d' | ||
// import Size2D from '../../values/size-2d' | ||
// import Size3D from '../../values/size-3d' | ||
import {ColorRgbJSON} from '../../values/color-rgb' | ||
import {ColorRgbaJSON} from '../../values/color-rgba' | ||
|
||
export interface AssetPointerScheme { | ||
assetId: string | ||
} | ||
|
||
export type KeyframeValueTypes = | ||
Point2D|Point3D|Size2D|Size3D|ColorRGB|ColorRGBA|number|boolean|string|AssetPointerScheme | ||
export type JSONKeyframeValueTypes = | ||
| number | ||
| boolean | ||
| string | ||
| {type: 'color-rgb', value: ColorRgbJSON} | ||
| {type: 'color-rgba', value: ColorRgbaJSON} | ||
| {type: 'asset', value: AssetPointerScheme} | ||
// Point2D|Point3D|Size2D|Size3D | ||
|
||
export interface KeyframeConfigScheme { | ||
value: KeyframeValueTypes | ||
frameOnClip: number|null | ||
value: JSONKeyframeValueTypes | ||
frameOnClip: number | ||
easeInParam: [number, number] | ||
easeOutParam: [number, number] | ||
} | ||
|
||
export interface KeyframeScheme { | ||
id: string|null | ||
id: string | ||
config: KeyframeConfigScheme | ||
} |
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