Skip to content
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

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft

Refactor audio #1668

wants to merge 13 commits into from

Conversation

YonatanKra
Copy link
Contributor

No description provided.

Yonatan Kra added 8 commits April 7, 2024 15:08
- 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
Comment on lines +12 to +21
let audioElement: any;
class MockAudio extends Audio {
constructor() {
super();
// eslint-disable-next-line @typescript-eslint/no-this-alias
audioElement = this;
}
}

window.Audio = MockAudio;
Copy link
Contributor Author

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}>`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove network dependent source

Comment on lines 58 to 90
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);
});
});
Copy link
Contributor Author

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?
@@ -97,128 +122,217 @@ describe('vwc-audio-player', () => {
});

describe('disabled', () => {
Copy link
Contributor Author

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 () {
Copy link
Contributor Author

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

@rinaok rinaok marked this pull request as draft May 2, 2024 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant