Skip to content

Commit

Permalink
Merge fa50cfd into 3e6102e
Browse files Browse the repository at this point in the history
  • Loading branch information
spacedmonkey authored Jun 2, 2020
2 parents 3e6102e + fa50cfd commit d572d9d
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/**
* Internal dependencies
*/
import isApplicableLibraries from './is-applicable-libraries';
import isImageIncluded from './is-image-included';
import { isApplicableLibraries, isImageIncluded } from '../helpers';

const { setUserSetting, getUserSetting } = window;

Expand Down
9 changes: 4 additions & 5 deletions assets/src/media-selector/helpers/import-images.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { addQueryArgs } from '@wordpress/url';
/**
* Internal dependencies
*/
import isUnsplashImage from './is-unsplash-image';
import getConfig from './get-config';
import preloadImage from './preload-image';
import { getConfig, isUnsplashImage, preloadImage } from './';

const { getUserSetting } = window;

/**
* Import selected Unsplash images.
Expand Down Expand Up @@ -108,8 +108,7 @@ const processImage = options => {
*/
const preloadImageWp = image => {
const defaultProps = wp.media.view.settings.defaultProps;
const imageSize =
window.getUserSetting( 'imgsize', defaultProps.size ) || 'medium';
const imageSize = getUserSetting( 'imgsize', defaultProps.size ) || 'medium';
const { sizes } = image.attributes;
if ( sizes && sizes[ imageSize ] && sizes[ imageSize ].url ) {
return preloadImage( sizes[ imageSize ].url );
Expand Down
6 changes: 6 additions & 0 deletions assets/src/media-selector/helpers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export { default as getConfig } from './get-config';
export { default as importImages } from './import-images';
export { default as isApplicableLibraries } from './is-applicable-libraries';
export { default as isImageIncluded } from './is-image-included';
export { default as isUnsplashImage } from './is-unsplash-image';
export { default as preloadImage } from './preload-image';
4 changes: 2 additions & 2 deletions assets/src/media-selector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* Internal dependencies
*/
import './style.css';
import withUnsplashTab from './helpers/with-unsplash-tab';
import unsetUnsplashLibrary from './helpers/unset-unsplash-library';
import unsetUnsplashLibrary from './controllers/unset-unsplash-library';
import withUnsplashTab from './views/with-unsplash-tab';
import PostFrame from './views/post-frame';

// Override media frames in the respective editors to add the Unsplash tab.
Expand Down
3 changes: 1 addition & 2 deletions assets/src/media-selector/models/images-query-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import { addQueryArgs } from '@wordpress/url';
* Internal dependencies
*/
import ImagesCollection from '../collections/images-collection';
import getConfig from '../helpers/get-config';
import preloadImage from '../helpers/preload-image';
import { preloadImage, getConfig } from '../helpers';

const ImagesQueryModel = wp.media.model.Query.extend(
{
Expand Down
2 changes: 1 addition & 1 deletion assets/src/media-selector/store/unsplash-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Internal dependencies
*/
import ImagesCollection from '../collections/images-collection';
import getConfig from '../helpers/get-config';
import { getConfig } from '../helpers';

const State = wp.media.controller.State;

Expand Down
3 changes: 1 addition & 2 deletions assets/src/media-selector/views/button.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/**
* Internal dependencies
*/
import isUnsplashImage from '../helpers/is-unsplash-image';
import importImages from '../helpers/import-images';
import { importImages, isUnsplashImage } from '../helpers';

const Button = wp.media.view.Button.extend( {
/**
Expand Down
2 changes: 1 addition & 1 deletion assets/src/media-selector/views/images-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Internal dependencies
*/
import ImageViews from './image-views';
import getConfig from '../helpers/get-config';
import { getConfig } from '../helpers';

const ImagesBrowser = wp.media.view.AttachmentsBrowser.extend( {
className: 'unsplash-browser attachments-browser',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
* Internal dependencies
*/
import UnsplashState from '../store/unsplash-state';
import ImagesBrowser from '../views/images-browser';
import ImageView from '../views/image-view';
import Toolbar from '../views/toolbar';
import ToolbarSelect from '../views/toolbar-select';
import getConfig from './get-config';
import isImageIncluded from './is-image-included';
import isApplicableLibraries from './is-applicable-libraries';
import ImagesBrowser from './images-browser';
import ImageView from './image-view';
import Toolbar from './toolbar';
import ToolbarSelect from './toolbar-select';
import { getConfig, isApplicableLibraries, isImageIncluded } from '../helpers';

export default View => {
return View.extend( {
Expand Down
32 changes: 32 additions & 0 deletions tests/js/media-selector/helpers/get-config.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Internal dependencies
*/
import { getConfig } from '../../../../assets/src/media-selector/helpers';

describe( 'get-config', () => {
beforeEach( () => {
// Delete the existing
delete window.unsplash;
window.unsplash = {
test: '123',
};
} );

afterAll( () => {
// Delete the existing
delete window.unsplash;
} );

it( 'check key', () => {
expect( getConfig( 'test' ) ).toBe( '123' );
} );

it( 'invalid key', () => {
expect( getConfig( 'wordpress' ) ).toBeUndefined();
} );

it( 'not set on window', () => {
delete window.unsplash;
expect( getConfig( 'wordpress' ) ).toBeUndefined();
} );
} );
14 changes: 14 additions & 0 deletions tests/js/media-selector/helpers/is-applicable-libraries.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Internal dependencies
*/
import { isApplicableLibraries } from '../../../../assets/src/media-selector/helpers';

describe( 'is-applicable-libraries', () => {
it( 'check string of video', () => {
expect( isApplicableLibraries( 'video' ) ).toBe( false );
} );

it( 'check string of library', () => {
expect( isApplicableLibraries( 'library' ) ).toBe( true );
} );
} );
22 changes: 22 additions & 0 deletions tests/js/media-selector/helpers/is-image-included.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Internal dependencies
*/
import { isImageIncluded } from '../../../../assets/src/media-selector/helpers';

describe( 'is-image-included', () => {
it( 'check empty array', () => {
expect( isImageIncluded( [] ) ).toBe( false );
} );

it( 'check with video array', () => {
expect( isImageIncluded( [ 'video' ] ) ).toBe( false );
} );

it( 'check array with image', () => {
expect( isImageIncluded( [ 'image' ] ) ).toBe( true );
} );

it( 'check string of image', () => {
expect( isImageIncluded( 'image' ) ).toBe( true );
} );
} );
33 changes: 33 additions & 0 deletions tests/js/media-selector/helpers/is-unsplash-image.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Internal dependencies
*/
import { isUnsplashImage } from '../../../../assets/src/media-selector/helpers';

describe( 'is-unsplash-image', () => {
it( 'valid attachment', () => {
const attachment = {
attributes: {
unsplash_order: 2,
id: 'fsfds',
},
};
expect( isUnsplashImage( attachment ) ).toBe( true );
} );
it( 'invalid attachment', () => {
const attachment = {
attributes: {
unsplash_order: 2,
id: 22,
},
};
expect( isUnsplashImage( attachment ) ).toBe( false );
} );
it( 'no order attachment', () => {
const attachment = {
attributes: {
id: 22,
},
};
expect( isUnsplashImage( attachment ) ).toBe( false );
} );
} );

0 comments on commit d572d9d

Please sign in to comment.