-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor audio #1668
base: main
Are you sure you want to change the base?
Refactor audio #1668
Conversation
- set the correct paused tests - Should move loadmetadata and timeupdate tests to a more concise API section - Should handle the click and _rewind function
also removed similar test from paused
let audioElement: any; | ||
class MockAudio extends Audio { | ||
constructor() { | ||
super(); | ||
// eslint-disable-next-line @typescript-eslint/no-this-alias | ||
audioElement = this; | ||
} | ||
} | ||
|
||
window.Audio = MockAudio; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mock audio
@@ -28,15 +39,15 @@ describe('vwc-audio-player', () => { | |||
|
|||
beforeEach(async () => { | |||
element = (await fixture( | |||
`<${COMPONENT_TAG} timestamp src="https://download.samplelib.com/mp3/sample-6s.mp3"></${COMPONENT_TAG}>` | |||
`<${COMPONENT_TAG} timestamp src="./sample-6s.mp3"></${COMPONENT_TAG}>` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove network dependent source
describe('notime', function () { | ||
it('should remove the time stamp when equal to true', async function () { | ||
it('should show timestamp when false', async () => { | ||
element.notime = false; | ||
await elementUpdated(element); | ||
|
||
const controls = getBaseElement(element).querySelector('.controls') as HTMLDivElement; | ||
const currentTimeClassExistsBeforeTheChange = controls.querySelector('.current-time'); | ||
const totalTimeClassExistsBeforeTheChange = controls.querySelector('.total-time'); | ||
const currentTimeClassExists = controls.querySelector('.current-time'); | ||
const totalTimeClassExists = controls.querySelector('.total-time'); | ||
|
||
expect(currentTimeClassExists).toBeTruthy(); | ||
expect(totalTimeClassExists).toBeTruthy(); | ||
}); | ||
|
||
it('should remove the time stamp when equal to true', async function () { | ||
element.notime = true; | ||
await elementUpdated(element); | ||
|
||
const currentTimeClassExistsAfterTheChange = controls.querySelector('.current-time'); | ||
const totalTimeClassExistsAfterTheChange = controls.querySelector('.total-time'); | ||
const controls = getBaseElement(element).querySelector('.controls') as HTMLDivElement; | ||
const currentTimeClassExists = controls.querySelector('.current-time'); | ||
const totalTimeClassExists = controls.querySelector('.total-time'); | ||
|
||
expect(currentTimeClassExistsBeforeTheChange).toBeTruthy(); | ||
expect(totalTimeClassExistsBeforeTheChange).toBeTruthy(); | ||
expect(currentTimeClassExists).toBeFalsy(); | ||
expect(totalTimeClassExists).toBeFalsy(); | ||
}); | ||
|
||
expect(currentTimeClassExistsAfterTheChange).toBeFalsy(); | ||
expect(totalTimeClassExistsAfterTheChange).toBeFalsy(); | ||
it('should update the duration when notime is set to true', async function () { | ||
const newElement = (await fixture( | ||
`<${COMPONENT_TAG} notime src="./sample-6s.mp3"></${COMPONENT_TAG}>`)) as AudioPlayer; | ||
setAudioDuration(60); | ||
await elementUpdated(newElement); | ||
expect(newElement.duration).toBe(60); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More comprehensive tests for notime
What was done? 1. Simpler and more correct slider change tracking 2. Removal of "_togglePlay" 3. Paused state is totally managed by `paused` 4. Slider element is now private 5. Timestamp element is now private What's left? 1. Make duration private 2. Move _formatTime to be a utility function 3. Extract native audio player creation to its own private method 4. handleSlideMouseUp biz logic should be extracted so it can be used with keyboard too 5. change the notime API?
b972bdd
to
928a457
Compare
@@ -97,128 +122,217 @@ describe('vwc-audio-player', () => { | |||
}); | |||
|
|||
describe('disabled', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More comprehensive tests
|
||
pauseButton.click(); | ||
describe('paused', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set pause as the only way to change the state of the audio player in regards to play/pause - both visually and auditory
TODO::handle space bar to play
No description provided.