Skip to content

Commit

Permalink
Merge d88fe54 into 3e6102e
Browse files Browse the repository at this point in the history
  • Loading branch information
spacedmonkey committed Jun 3, 2020
2 parents 3e6102e + d88fe54 commit 7ec5211
Show file tree
Hide file tree
Showing 16 changed files with 131 additions and 26 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';
5 changes: 2 additions & 3 deletions assets/src/media-selector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
* Internal dependencies
*/
import './style.css';
import withUnsplashTab from './helpers/with-unsplash-tab';
import unsetUnsplashLibrary from './helpers/unset-unsplash-library';
import PostFrame from './views/post-frame';
import unsetUnsplashLibrary from './controllers/unset-unsplash-library';
import { withUnsplashTab, PostFrame } from './views';

// Override media frames in the respective editors to add the Unsplash tab.
if ( wp.media && wp.media.view && wp.media.view.MediaFrame ) {
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
4 changes: 2 additions & 2 deletions assets/src/media-selector/views/images-browser.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* Internal dependencies
*/
import ImageViews from './image-views';
import getConfig from '../helpers/get-config';
import { ImageViews } from './';
import { getConfig } from '../helpers';

const ImagesBrowser = wp.media.view.AttachmentsBrowser.extend( {
className: 'unsplash-browser attachments-browser',
Expand Down
8 changes: 8 additions & 0 deletions assets/src/media-selector/views/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export { default as Button } from './button';
export { default as ImagesBrowser } from './images-browser';
export { default as ImageView } from './image-view';
export { default as ImageViews } from './image-views';
export { default as PostFrame } from './post-frame';
export { default as Toolbar } from './toolbar';
export { default as ToolbarSelect } from './toolbar-select';
export { default as withUnsplashTab } from './with-unsplash-tab';
2 changes: 1 addition & 1 deletion assets/src/media-selector/views/toolbar-select.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Internal dependencies
*/
import Toolbar from './toolbar';
import { Toolbar } from './';

const ToolbarSelect = wp.media.view.Toolbar.Select.extend( {
initialize() {
Expand Down
2 changes: 1 addition & 1 deletion assets/src/media-selector/views/toolbar.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Internal dependencies
*/
import Button from './button';
import { Button } from './';

const Toolbar = wp.media.view.Toolbar.extend( {
initialize() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@
* 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, ImageView, Toolbar, ToolbarSelect } from './';
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 7ec5211

Please sign in to comment.