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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RNMobile] Audio block URL Parser unit tests #31920

Merged
merged 60 commits into from
May 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
0519567
Basics of Audio block working
etoledom Dec 1, 2020
690224d
Add audio support to MediaUpload
etoledom Dec 1, 2020
b7965fd
Add handling of file uploads and replace
etoledom Dec 1, 2020
f2ccb18
WPMediaLibrary support for Audio block
etoledom Dec 1, 2020
2a02b83
Avoid removing media info on error state
etoledom Dec 1, 2020
276b07d
Linting
etoledom Dec 1, 2020
8a8b550
Added an AUDIO file to the test requestMediaPickFromMediaLibrary func
jd-alexander Dec 9, 2020
9e03e63
Fixed typo in ToolbarButton of Audio Block.
jd-alexander Dec 9, 2020
349aa19
Removed auto help behavior present on web that's not used on mobile.
jd-alexander Dec 9, 2020
04a39b4
Merge branch 'master' into rnmobile/audio-block-I-b
jd-alexander Dec 9, 2020
32029e0
[Android] Wired the click of the Audio Media Library button.
jd-alexander Dec 16, 2020
a18b8ac
Added Audio media options for choosing audio file locally.
jd-alexander Dec 16, 2020
af6cb99
[RNMobile] Audio Block: Proper caption field (#27689)
ceyhun Dec 17, 2020
193339f
Add alert prompt to insert from URL
ceyhun Dec 18, 2020
4ab2988
Set entered URL in audio block attributes
ceyhun Dec 18, 2020
d9a6041
Merge branch 'master' into rnmobile/audio-block-I-b
jd-alexander Jan 7, 2021
1a46994
Merge branch 'master' into rnmobile/audio-block-I-b
jd-alexander Jan 14, 2021
f09c955
Merge branch 'master' into rnmobile/audio-block-I-b
jd-alexander Jan 18, 2021
fff09be
initial integration with react native prompt.
jd-alexander Jan 20, 2021
d4209e8
updated prompt lib.
jd-alexander Jan 20, 2021
9d61d49
Merge branch 'rnmobile/audio-block-I-b' into rnmobile/audio-block-IV-…
jd-alexander Jan 20, 2021
f0a1034
updated commit hash of prompt lib.
jd-alexander Jan 20, 2021
1eb58d2
Updated package-lock.json.
jd-alexander Jan 20, 2021
17dea27
Added RNPromptPackage to Glue Code.
jd-alexander Jan 20, 2021
c7154d3
Merge branch 'master' into rnmobile/audio-block-IV-from-url
jd-alexander Feb 18, 2021
0f597f3
fixed merge conflicts between the edit.native.js files of the branches
jd-alexander Feb 18, 2021
e4dec03
added onSelectURL to the media-upload component
jd-alexander Feb 20, 2021
f77a861
added onSelectURL to the media-placeholder
jd-alexander Feb 20, 2021
cad8e8a
updated onSelectURL support with notice and URL validation
jd-alexander Feb 20, 2021
ef478bb
sync package-lock.json
jd-alexander Feb 20, 2021
ee9a536
Merge remote-tracking branch 'origin/master' into rnmobile/audio-bloc…
jd-alexander Feb 23, 2021
6b6221f
updated package-lock.json
jd-alexander Feb 23, 2021
377ceae
updated package-lock.json
jd-alexander Feb 23, 2021
01242f5
Merge branch 'trunk' into rnmobile/audio-block-IV-from-url
jd-alexander Apr 7, 2021
5911b09
updated react-native-prompt-android setup due to binary dep changes.
jd-alexander Apr 7, 2021
cebdf5f
sync package-lock.json
jd-alexander Apr 7, 2021
2dd3b6c
Integrated RNPromptPackage with the glue code.
jd-alexander Apr 7, 2021
f348df3
sync package-lock.json
jd-alexander Apr 7, 2021
b81dd77
package-lock.json fix
jd-alexander Apr 7, 2021
d4ad088
sync package-lock.json
jd-alexander Apr 8, 2021
754b999
Added the globe icon to the Insert from URL source.Only shown on Android
jd-alexander Apr 8, 2021
e7ab21b
Extract filename from all URL types and optimized extension logic.
jd-alexander Apr 20, 2021
1834b58
Merge branch 'trunk' into rnmobile/audio-block-IV-from-url
jd-alexander Apr 20, 2021
614d57b
Merge branch 'trunk' into rnmobile/audio-block-IV-from-url
jd-alexander Apr 29, 2021
6170600
Merge branch 'trunk' into rnmobile/audio-block-IV-from-url
jd-alexander May 13, 2021
b864661
Extracted the url parsing logic to a file so it can be tested.
jd-alexander May 15, 2021
875441c
integrated parseAudioUrl function with the Audio block.
jd-alexander May 15, 2021
8d2d545
Created tests for the audio url parsing.
jd-alexander May 15, 2021
d79719f
Made the component and its respective tests native.
jd-alexander May 18, 2021
1e550e6
Merge branch 'trunk' into rnmobile/audio-block-IV-from-url
jd-alexander May 19, 2021
e68550e
Reduced onPress -> onSelectURL logic since the parameters match.
jd-alexander May 19, 2021
024ecad
Added entry to CHANGELOG.md
jd-alexander May 19, 2021
7fd4385
Merge branch 'rnmobile/audio-block-IV-from-url' into rnmobile/audio-b…
jd-alexander May 19, 2021
462fd4f
Utilized getPath from the `wordpress/url` package to simplify logic.
jd-alexander May 19, 2021
05a8335
Added URL with folder to the tests for audio urls with an extension.
jd-alexander May 19, 2021
e4ea54b
Enhanced tests to verify the title and extension values.
jd-alexander May 19, 2021
15bd47e
Trimmed the extension since a space exists in the string for the UI.
jd-alexander May 19, 2021
92752b2
Removed trim and put the space in the string.
jd-alexander May 19, 2021
f33dd98
Merge branch 'trunk' into rnmobile/audio-block-IV-from-url-unit-tests
jd-alexander May 21, 2021
2bbecc8
Removed duplicate entry.
jd-alexander May 21, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* WordPress dependencies
*/
import { safeDecodeURI, getPath } from '@wordpress/url';

export const parseAudioUrl = ( src ) => {
const fileName = getPath( safeDecodeURI( src ) ).split( '/' ).pop();
const parts = fileName.split( '.' );
const extension = parts.length === 2 ? parts.pop().toUpperCase() + ' ' : '';
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that if the file contains an extension. we're adding an extra blank space at the end of the string, what's the reason for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, yes, I decided to add a space here because there are times when the extension isn't present but if it is I need to add the space here so within the UI itself the extension doesn't get attached to the audio file Text in the UI. For more context, see this comment #27817 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh ok, I'm wondering if the extra space should be handled then in the component instead since it's specific to how to render it, wdyt? My first impression was that this method was agnostic to the component but maybe since it's located under the same folder makes sense to include it 🤔 .

Copy link
Contributor Author

@jd-alexander jd-alexander May 21, 2021

Choose a reason for hiding this comment

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

You are right about the component handling this especially since it's UI-related. I could create another small PR to resolve this since this PR solved the main need which was to add the tests 😄

const title = parts.join( '.' );
return { title, extension };
};
17 changes: 5 additions & 12 deletions packages/components/src/mobile/audio-player/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ import {
requestImageFailedRetryDialog,
requestImageUploadCancelDialog,
} from '@wordpress/react-native-bridge';
import { getProtocol, safeDecodeURI } from '@wordpress/url';
import { getProtocol } from '@wordpress/url';
import { useState } from '@wordpress/element';

/**
* Internal dependencies
*/
import styles from './styles.scss';
import { parseAudioUrl } from './audio-url-parser.native';

const isIOS = Platform.OS === 'ios';

Expand Down Expand Up @@ -127,17 +128,9 @@ function Player( {
let extension = '';

if ( src ) {
const decodedURI = safeDecodeURI( src );
const fileName = decodedURI
.split( '#' )
.shift()
.split( '?' )
.shift()
.split( '/' )
.pop();
const parts = fileName.split( '.' );
extension = parts.length === 2 ? parts.pop().toUpperCase() + ' ' : '';
title = parts.join( '.' );
const result = parseAudioUrl( src );
extension = result.extension;
title = result.title;
}

const getSubtitleValue = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Internal dependencies
*/
import { parseAudioUrl } from '../audio-url-parser.native';

const supportedAudioUrlsWithExtensions = [
'https://www.mp3.com/file.mp3?key1=value1&key2=value2#anchorforsomereason',
'https://www.mp3.com/file.mp3?key1=value1&key2=value2',
'https://www.mp3.com/file.mp3',
fluiddot marked this conversation as resolved.
Show resolved Hide resolved
`https://www.mp3.com/folder/file.mp3`,
];

const supportedAudioUrlsWithoutExtensions = [
'https://www.mp3.com/file?key1=value1&key2=value2#anchorforsomereason',
'https://www.mp3.com/file?key1=value1&key2=value2',
'https://www.mp3.com/file',
'https://www.mp3.com/folder/file',
];

describe( 'supportedAudioUrlsWithExtensions', () => {
supportedAudioUrlsWithExtensions.forEach( ( url ) => {
it( `supports ${ url }`, () => {
const { title, extension } = parseAudioUrl( url );
expect( title ).toBe( 'file' );
expect( extension ).toBe( 'MP3 ' );
} );
} );
} );

describe( 'supportedAudioUrlsWithoutExtensions', () => {
supportedAudioUrlsWithoutExtensions.forEach( ( url ) => {
it( `supports ${ url }`, () => {
const { title, extension } = parseAudioUrl( url );
expect( title ).toBe( 'file' );
expect( extension ).toBe( '' );
} );
} );
} );