-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(model3d): Add flyout for animation clips (#1369)
- Loading branch information
Conrad Chan
authored
May 5, 2021
1 parent
3164ac3
commit 09eefd9
Showing
12 changed files
with
299 additions
and
32 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
20 changes: 20 additions & 0 deletions
20
src/lib/viewers/controls/model3d/AnimationClipsControl.scss
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,20 @@ | ||
.bp-AnimationClipsControl { | ||
position: relative; | ||
display: flex; | ||
align-items: center; | ||
|
||
.bp-SettingsFlyout { | ||
right: auto; | ||
left: 0; | ||
max-width: 240px; | ||
} | ||
} | ||
|
||
.bp-AnimationClipsControl-radioItem { | ||
.bp-SettingsRadioItem-value { | ||
max-width: 180px; | ||
overflow-x: hidden; | ||
white-space: nowrap; | ||
text-overflow: ellipsis; | ||
} | ||
} |
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
65 changes: 65 additions & 0 deletions
65
src/lib/viewers/controls/model3d/__tests__/AnimationClipsControl-test.tsx
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,65 @@ | ||
import React from 'react'; | ||
import { shallow, ShallowWrapper } from 'enzyme'; | ||
import AnimationClipsControl, { formatDuration, Props as AnimationClipsControlProps } from '../AnimationClipsControl'; | ||
import AnimationClipsToggle from '../AnimationClipsToggle'; | ||
import Settings from '../../settings'; | ||
|
||
describe('AnimationClipsControl', () => { | ||
const animationClips = [ | ||
{ duration: 1, id: '1', name: 'first' }, | ||
{ duration: 2, id: '2', name: 'second' }, | ||
]; | ||
const getDefaults = (): AnimationClipsControlProps => ({ | ||
animationClips, | ||
currentAnimationClipId: '1', | ||
onAnimationClipSelect: jest.fn(), | ||
}); | ||
const getWrapper = (props = {}): ShallowWrapper => shallow(<AnimationClipsControl {...getDefaults()} {...props} />); | ||
|
||
describe('render', () => { | ||
test('should return a valid wrapper', () => { | ||
const wrapper = getWrapper(); | ||
|
||
expect(wrapper.find(Settings).props()).toMatchObject({ | ||
className: 'bp-AnimationClipsControl', | ||
toggle: AnimationClipsToggle, | ||
}); | ||
expect(wrapper.exists(Settings.Menu)).toBe(true); | ||
}); | ||
|
||
test('should return the animationClips as RadioItems', () => { | ||
const onAnimationClipSelect = jest.fn(); | ||
const wrapper = getWrapper({ onAnimationClipSelect }); | ||
const radioItems = wrapper.find(Settings.RadioItem); | ||
|
||
expect(radioItems).toHaveLength(2); | ||
expect(radioItems.at(0).props()).toMatchObject({ | ||
className: 'bp-AnimationClipsControl-radioItem', | ||
isSelected: true, | ||
label: '00:00:01 first', | ||
onChange: onAnimationClipSelect, | ||
value: animationClips[0].id, | ||
}); | ||
expect(radioItems.at(1).props()).toMatchObject({ | ||
className: 'bp-AnimationClipsControl-radioItem', | ||
isSelected: false, | ||
label: '00:00:02 second', | ||
onChange: onAnimationClipSelect, | ||
value: animationClips[1].id, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('formatDuration()', () => { | ||
test.each` | ||
time | expectedString | ||
${0} | ${'00:00:00'} | ||
${59} | ${'00:00:59'} | ||
${61} | ${'00:01:01'} | ||
${3599} | ${'00:59:59'} | ||
${3661} | ${'01:01:01'} | ||
`('should format $time as $expectedString', ({ time, expectedString }) => { | ||
expect(formatDuration(time)).toBe(expectedString); | ||
}); | ||
}); | ||
}); |
40 changes: 40 additions & 0 deletions
40
src/lib/viewers/controls/model3d/__tests__/AnimationControls-test.tsx
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,40 @@ | ||
import React from 'react'; | ||
import { shallow, ShallowWrapper } from 'enzyme'; | ||
import AnimationClipsControl from '../AnimationClipsControl'; | ||
import AnimationControls, { Props as AnimationControlsProps } from '../AnimationControls'; | ||
import PlayPauseToggle from '../../media/PlayPauseToggle'; | ||
|
||
describe('AnimationControls', () => { | ||
const getDefaults = (): AnimationControlsProps => ({ | ||
animationClips: [{ duration: 1, id: '1', name: 'one' }], | ||
currentAnimationClipId: '1', | ||
isPlaying: false, | ||
onAnimationClipSelect: jest.fn(), | ||
onPlayPause: jest.fn(), | ||
}); | ||
const getWrapper = (props = {}): ShallowWrapper => shallow(<AnimationControls {...getDefaults()} {...props} />); | ||
|
||
describe('render', () => { | ||
test('should return null if animationClips is empty', () => { | ||
const wrapper = getWrapper({ animationClips: [] }); | ||
|
||
expect(wrapper.isEmptyRender()).toBe(true); | ||
}); | ||
|
||
test('should return valid wrapper', () => { | ||
const onAnimationClipSelect = jest.fn(); | ||
const onPlayPause = jest.fn(); | ||
const wrapper = getWrapper({ onAnimationClipSelect, onPlayPause }); | ||
|
||
expect(wrapper.find(PlayPauseToggle).props()).toMatchObject({ | ||
isPlaying: false, | ||
onPlayPause, | ||
}); | ||
expect(wrapper.find(AnimationClipsControl).props()).toMatchObject({ | ||
animationClips: expect.any(Array), | ||
currentAnimationClipId: '1', | ||
onAnimationClipSelect, | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.