@wordpress/media-fields 0.1.1-next.738bb1424.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/alt_text/{index.cjs → index.js} +3 -2
- package/build/alt_text/{index.cjs.map → index.js.map} +2 -2
- package/build/caption/{index.cjs → index.js} +4 -3
- package/build/caption/{index.cjs.map → index.js.map} +2 -2
- package/build/description/{index.cjs → index.js} +4 -3
- package/build/description/{index.cjs.map → index.js.map} +2 -2
- package/build/filename/{index.cjs → index.js} +2 -2
- package/build/filename/{view.cjs → view.js} +1 -1
- package/build/filesize/{index.cjs → index.js} +1 -1
- package/build/{index.cjs → index.js} +9 -9
- package/build/media_dimensions/{index.cjs → index.js} +1 -1
- package/build/media_thumbnail/{index.cjs → index.js} +2 -2
- package/build/media_thumbnail/{view.cjs → view.js} +37 -43
- package/build/media_thumbnail/view.js.map +7 -0
- package/build/mime_type/{index.cjs → index.js} +1 -1
- package/build/{types.cjs → types.js} +1 -1
- package/build/utils/{get-media-type-from-mime-type.cjs → get-media-type-from-mime-type.js} +1 -1
- package/build/utils/{get-raw-content.cjs → get-raw-content.js} +1 -1
- package/build/utils/{get-rendered-content.cjs → get-rendered-content.js} +1 -1
- package/build-module/alt_text/index.js +2 -1
- package/build-module/alt_text/index.js.map +2 -2
- package/build-module/caption/index.js +3 -2
- package/build-module/caption/index.js.map +2 -2
- package/build-module/description/index.js +3 -2
- package/build-module/description/index.js.map +2 -2
- package/build-module/filename/index.js +1 -1
- package/build-module/index.js +8 -8
- package/build-module/media_thumbnail/index.js +1 -1
- package/build-module/media_thumbnail/view.js +36 -42
- package/build-module/media_thumbnail/view.js.map +2 -2
- package/build-types/alt_text/index.d.ts.map +1 -1
- package/build-types/caption/index.d.ts.map +1 -1
- package/build-types/description/index.d.ts.map +1 -1
- package/build-types/media_thumbnail/view.d.ts.map +1 -1
- package/build-types/stories/index.story.d.ts.map +1 -1
- package/package.json +13 -22
- package/src/alt_text/index.tsx +1 -0
- package/src/caption/index.tsx +1 -0
- package/src/description/index.tsx +1 -0
- package/src/media_thumbnail/view.tsx +46 -63
- package/src/stories/index.story.tsx +1 -53
- package/tsconfig.json +31 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/build/media_thumbnail/view.cjs.map +0 -7
- package/build-types/filename/test/index.test.d.ts +0 -2
- package/build-types/filename/test/index.test.d.ts.map +0 -1
- package/build-types/filename/test/view.test.d.ts +0 -2
- package/build-types/filename/test/view.test.d.ts.map +0 -1
- package/build-types/filesize/test/index.test.d.ts +0 -2
- package/build-types/filesize/test/index.test.d.ts.map +0 -1
- package/build-types/media_dimensions/test/index.test.d.ts +0 -2
- package/build-types/media_dimensions/test/index.test.d.ts.map +0 -1
- package/src/filename/test/index.test.ts +0 -59
- package/src/filename/test/view.test.tsx +0 -87
- package/src/filesize/test/index.test.tsx +0 -107
- package/src/media_dimensions/test/index.test.ts +0 -132
- /package/build/filename/{index.cjs.map → index.js.map} +0 -0
- /package/build/filename/{view.cjs.map → view.js.map} +0 -0
- /package/build/filesize/{index.cjs.map → index.js.map} +0 -0
- /package/build/{index.cjs.map → index.js.map} +0 -0
- /package/build/media_dimensions/{index.cjs.map → index.js.map} +0 -0
- /package/build/media_thumbnail/{index.cjs.map → index.js.map} +0 -0
- /package/build/mime_type/{index.cjs.map → index.js.map} +0 -0
- /package/build/{types.cjs.map → types.js.map} +0 -0
- /package/build/utils/{get-media-type-from-mime-type.cjs.map → get-media-type-from-mime-type.js.map} +0 -0
- /package/build/utils/{get-raw-content.cjs.map → get-raw-content.js.map} +0 -0
- /package/build/utils/{get-rendered-content.cjs.map → get-rendered-content.js.map} +0 -0
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/media_thumbnail/view.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport {\n\t__experimentalTruncate as Truncate,\n\t__experimentalVStack as VStack,\n\tIcon,\n} from '@wordpress/components';\nimport { useState } from '@wordpress/element';\nimport type { Attachment } from '@wordpress/core-data';\nimport { getFilename } from '@wordpress/url';\nimport type { DataViewRenderFieldProps } from '@wordpress/dataviews';\n/**\n * Internal dependencies\n */\nimport { getMediaTypeFromMimeType } from '../utils/get-media-type-from-mime-type';\nimport type { MediaItem } from '../types';\n\nfunction FallbackView( {\n\titem,\n\tfilename,\n}: {\n\titem: MediaItem;\n\tfilename: string;\n} ) {\n\treturn (\n\t\t<div className=\"dataviews-media-field__media-thumbnail\">\n\t\t\t<VStack\n\t\t\t\tjustify=\"center\"\n\t\t\t\talignment=\"center\"\n\t\t\t\tclassName=\"dataviews-media-field__media-thumbnail__stack\"\n\t\t\t\tspacing={ 0 }\n\t\t\t>\n\t\t\t\t<Icon\n\t\t\t\t\tclassName=\"dataviews-media-field__media-thumbnail--icon\"\n\t\t\t\t\ticon={ getMediaTypeFromMimeType( item.mime_type ).icon }\n\t\t\t\t\tsize={ 24 }\n\t\t\t\t/>\n\t\t\t\t{ !! filename && (\n\t\t\t\t\t<div className=\"dataviews-media-field__media-thumbnail__filename\">\n\t\t\t\t\t\t<Truncate className=\"dataviews-media-field__media-thumbnail__filename__truncate\">\n\t\t\t\t\t\t\t{ filename }\n\t\t\t\t\t\t</Truncate>\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t</VStack>\n\t\t</div>\n\t);\n}\n\nexport default function MediaThumbnailView( {\n\titem,\n\tconfig,\n}: DataViewRenderFieldProps< MediaItem > ) {\n\tconst [ imageError, setImageError ] = useState( false );\n\n\tconst _featuredMedia = useSelect(\n\t\t( select ) => {\n\t\t\t// Avoid the network request if it's not needed. `featured_media` is\n\t\t\t// 0 for images and media without featured media.\n\t\t\tif ( ! item.featured_media ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\treturn select( coreStore ).getEntityRecord< Attachment >(\n\t\t\t\t'postType',\n\t\t\t\t'attachment',\n\t\t\t\titem.featured_media\n\t\t\t);\n\t\t},\n\t\t[ item.featured_media ]\n\t);\n\tconst featuredMedia = item.featured_media ? _featuredMedia : item;\n\n\t// Fetching.\n\tif ( ! featuredMedia ) {\n\t\treturn null;\n\t}\n\n\tconst filename = getFilename( featuredMedia.source_url || '' );\n\n\t// Show fallback if image failed to load or if not an image type.\n\tif (\n\t\timageError ||\n\t\tgetMediaTypeFromMimeType( featuredMedia.mime_type ).type !== 'image'\n\t) {\n\t\treturn (\n\t\t\t<FallbackView item={ featuredMedia } filename={ filename || '' } />\n\t\t);\n\t}\n\n\treturn (\n\t\t<div className=\"dataviews-media-field__media-thumbnail\">\n\t\t\t<img\n\t\t\t\tclassName=\"dataviews-media-field__media-thumbnail--image\"\n\t\t\t\tsrc={ featuredMedia.source_url }\n\t\t\t\tsrcSet={\n\t\t\t\t\tfeaturedMedia?.media_details?.sizes\n\t\t\t\t\t\t? (\n\t\t\t\t\t\t\t\tObject.values(\n\t\t\t\t\t\t\t\t\tfeaturedMedia.media_details.sizes\n\t\t\t\t\t\t\t\t) as Array< {\n\t\t\t\t\t\t\t\t\tsource_url: string;\n\t\t\t\t\t\t\t\t\twidth: number;\n\t\t\t\t\t\t\t\t} >\n\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t.map(\n\t\t\t\t\t\t\t\t\t( size ) =>\n\t\t\t\t\t\t\t\t\t\t`${ size.source_url } ${ size.width }w`\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t.join( ', ' )\n\t\t\t\t\t\t: undefined\n\t\t\t\t}\n\t\t\t\tsizes={ config?.sizes || '100vw' }\n\t\t\t\talt={ featuredMedia.alt_text || featuredMedia.title.raw }\n\t\t\t\tonError={ () => setImageError( true ) }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA0B;AAC1B,uBAAmC;AACnC,wBAIO;AACP,qBAAyB;AAEzB,iBAA4B;AAK5B,2CAAyC;AAYtC;AATH,SAAS,aAAc;AAAA,EACtB;AAAA,EACA;AACD,GAGI;AACH,SACC,4CAAC,SAAI,WAAU,0CACd;AAAA,IAAC,kBAAAA;AAAA,IAAA;AAAA,MACA,SAAQ;AAAA,MACR,WAAU;AAAA,MACV,WAAU;AAAA,MACV,SAAU;AAAA,MAEV;AAAA;AAAA,UAAC;AAAA;AAAA,YACA,WAAU;AAAA,YACV,UAAO,+DAA0B,KAAK,SAAU,EAAE;AAAA,YAClD,MAAO;AAAA;AAAA,QACR;AAAA,QACE,CAAC,CAAE,YACJ,4CAAC,SAAI,WAAU,oDACd,sDAAC,kBAAAC,wBAAA,EAAS,WAAU,8DACjB,oBACH,GACD;AAAA;AAAA;AAAA,EAEF,GACD;AAEF;AAEe,SAAR,mBAAqC;AAAA,EAC3C;AAAA,EACA;AACD,GAA2C;AAC1C,QAAM,CAAE,YAAY,aAAc,QAAI,yBAAU,KAAM;AAEtD,QAAM,qBAAiB;AAAA,IACtB,CAAE,WAAY;AAGb,UAAK,CAAE,KAAK,gBAAiB;AAC5B;AAAA,MACD;AACA,aAAO,OAAQ,iBAAAC,KAAU,EAAE;AAAA,QAC1B;AAAA,QACA;AAAA,QACA,KAAK;AAAA,MACN;AAAA,IACD;AAAA,IACA,CAAE,KAAK,cAAe;AAAA,EACvB;AACA,QAAM,gBAAgB,KAAK,iBAAiB,iBAAiB;AAG7D,MAAK,CAAE,eAAgB;AACtB,WAAO;AAAA,EACR;AAEA,QAAM,eAAW,wBAAa,cAAc,cAAc,EAAG;AAG7D,MACC,kBACA,+DAA0B,cAAc,SAAU,EAAE,SAAS,SAC5D;AACD,WACC,4CAAC,gBAAa,MAAO,eAAgB,UAAW,YAAY,IAAK;AAAA,EAEnE;AAEA,SACC,4CAAC,SAAI,WAAU,0CACd;AAAA,IAAC;AAAA;AAAA,MACA,WAAU;AAAA,MACV,KAAM,cAAc;AAAA,MACpB,QACC,eAAe,eAAe,QAE3B,OAAO;AAAA,QACN,cAAc,cAAc;AAAA,MAC7B,EAKC;AAAA,QACA,CAAE,SACD,GAAI,KAAK,UAAW,IAAK,KAAK,KAAM;AAAA,MACtC,EACC,KAAM,IAAK,IACZ;AAAA,MAEJ,OAAQ,QAAQ,SAAS;AAAA,MACzB,KAAM,cAAc,YAAY,cAAc,MAAM;AAAA,MACpD,SAAU,MAAM,cAAe,IAAK;AAAA;AAAA,EACrC,GACD;AAEF;",
|
|
6
|
-
"names": ["VStack", "Truncate", "coreStore"]
|
|
7
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../../src/filename/test/index.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"view.test.d.ts","sourceRoot":"","sources":["../../../src/filename/test/view.test.tsx"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../../src/filesize/test/index.test.tsx"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../../src/media_dimensions/test/index.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import filenameField from '../index';
|
|
5
|
-
import type { MediaItem } from '../../types';
|
|
6
|
-
|
|
7
|
-
describe( 'filenameField', () => {
|
|
8
|
-
it( 'has correct field configuration', () => {
|
|
9
|
-
expect( filenameField ).toMatchObject( {
|
|
10
|
-
id: 'filename',
|
|
11
|
-
type: 'text',
|
|
12
|
-
label: 'File name',
|
|
13
|
-
enableSorting: false,
|
|
14
|
-
filterBy: false,
|
|
15
|
-
readOnly: true,
|
|
16
|
-
} );
|
|
17
|
-
} );
|
|
18
|
-
|
|
19
|
-
describe( 'getValue', () => {
|
|
20
|
-
it( 'extracts filename from source_url', () => {
|
|
21
|
-
const item: Partial< MediaItem > = {
|
|
22
|
-
source_url:
|
|
23
|
-
'https://example.com/wp-content/uploads/2024/image.jpg',
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const result = filenameField.getValue?.( {
|
|
27
|
-
item: item as MediaItem,
|
|
28
|
-
} );
|
|
29
|
-
|
|
30
|
-
expect( result ).toBe( 'image.jpg' );
|
|
31
|
-
} );
|
|
32
|
-
|
|
33
|
-
it( 'returns undefined when source_url is undefined', () => {
|
|
34
|
-
const item: Partial< MediaItem > = {};
|
|
35
|
-
|
|
36
|
-
const result = filenameField.getValue?.( {
|
|
37
|
-
item: item as MediaItem,
|
|
38
|
-
} );
|
|
39
|
-
|
|
40
|
-
expect( result ).toBeUndefined();
|
|
41
|
-
} );
|
|
42
|
-
|
|
43
|
-
it( 'returns undefined when source_url is empty string', () => {
|
|
44
|
-
const item: Partial< MediaItem > = {
|
|
45
|
-
source_url: '',
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const result = filenameField.getValue?.( {
|
|
49
|
-
item: item as MediaItem,
|
|
50
|
-
} );
|
|
51
|
-
|
|
52
|
-
expect( result ).toBeUndefined();
|
|
53
|
-
} );
|
|
54
|
-
} );
|
|
55
|
-
|
|
56
|
-
it( 'has a render function', () => {
|
|
57
|
-
expect( filenameField.render ).toBeDefined();
|
|
58
|
-
} );
|
|
59
|
-
} );
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { render, screen } from '@testing-library/react';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* WordPress dependencies
|
|
8
|
-
*/
|
|
9
|
-
import type { NormalizedField } from '@wordpress/dataviews';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Internal dependencies
|
|
13
|
-
*/
|
|
14
|
-
import FileNameView from '../view';
|
|
15
|
-
import filenameField from '../index';
|
|
16
|
-
import type { MediaItem } from '../../types';
|
|
17
|
-
|
|
18
|
-
describe( 'FileNameView', () => {
|
|
19
|
-
describe( 'filename rendering', () => {
|
|
20
|
-
it( 'renders short filename (15 characters or less)', () => {
|
|
21
|
-
const item: Partial< MediaItem > = {
|
|
22
|
-
source_url: 'https://example.com/uploads/12345678901.jpg', // exactly 15 chars
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
render(
|
|
26
|
-
<FileNameView
|
|
27
|
-
item={ item as MediaItem }
|
|
28
|
-
field={ filenameField as NormalizedField< MediaItem > }
|
|
29
|
-
/>
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
// Verify the filename is visible to users
|
|
33
|
-
expect( screen.getByText( '12345678901.jpg' ) ).toBeInTheDocument();
|
|
34
|
-
} );
|
|
35
|
-
|
|
36
|
-
it( 'renders long filename (more than 15 characters)', () => {
|
|
37
|
-
const longFilename =
|
|
38
|
-
'very-long-filename-that-exceeds-fifteen-characters.jpg';
|
|
39
|
-
const item: Partial< MediaItem > = {
|
|
40
|
-
source_url: `https://example.com/uploads/${ longFilename }`,
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
render(
|
|
44
|
-
<FileNameView
|
|
45
|
-
item={ item as MediaItem }
|
|
46
|
-
field={ filenameField as NormalizedField< MediaItem > }
|
|
47
|
-
/>
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
// Verify the full filename text is accessible to users
|
|
51
|
-
// (the component handles truncation via Truncate/Tooltip, but the text is still present)
|
|
52
|
-
expect( screen.getByText( longFilename ) ).toBeInTheDocument();
|
|
53
|
-
} );
|
|
54
|
-
} );
|
|
55
|
-
|
|
56
|
-
describe( 'edge cases', () => {
|
|
57
|
-
it( 'renders nothing when source_url is missing', () => {
|
|
58
|
-
const item: Partial< MediaItem > = {};
|
|
59
|
-
|
|
60
|
-
const { container } = render(
|
|
61
|
-
<FileNameView
|
|
62
|
-
item={ item as MediaItem }
|
|
63
|
-
field={ filenameField as NormalizedField< MediaItem > }
|
|
64
|
-
/>
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
// When there's no source_url, component should render nothing
|
|
68
|
-
expect( container ).toBeEmptyDOMElement();
|
|
69
|
-
} );
|
|
70
|
-
|
|
71
|
-
it( 'renders nothing when source_url is empty', () => {
|
|
72
|
-
const item: Partial< MediaItem > = {
|
|
73
|
-
source_url: '',
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
const { container } = render(
|
|
77
|
-
<FileNameView
|
|
78
|
-
item={ item as MediaItem }
|
|
79
|
-
field={ filenameField as NormalizedField< MediaItem > }
|
|
80
|
-
/>
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
// When source_url is empty, component should render nothing
|
|
84
|
-
expect( container ).toBeEmptyDOMElement();
|
|
85
|
-
} );
|
|
86
|
-
} );
|
|
87
|
-
} );
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import filesizeField from '../index';
|
|
5
|
-
import type { MediaItem } from '../../types';
|
|
6
|
-
|
|
7
|
-
describe( 'filesizeField', () => {
|
|
8
|
-
it( 'has correct field configuration', () => {
|
|
9
|
-
expect( filesizeField ).toMatchObject( {
|
|
10
|
-
id: 'filesize',
|
|
11
|
-
type: 'text',
|
|
12
|
-
label: 'File size',
|
|
13
|
-
enableSorting: false,
|
|
14
|
-
filterBy: false,
|
|
15
|
-
readOnly: true,
|
|
16
|
-
} );
|
|
17
|
-
} );
|
|
18
|
-
|
|
19
|
-
describe( 'getValue - byte formatting logic', () => {
|
|
20
|
-
it( 'returns empty string for 0 bytes due to truthy check', () => {
|
|
21
|
-
const item = {
|
|
22
|
-
media_details: {
|
|
23
|
-
filesize: 0,
|
|
24
|
-
sizes: {},
|
|
25
|
-
},
|
|
26
|
-
} as MediaItem;
|
|
27
|
-
|
|
28
|
-
const result = filesizeField.getValue?.( {
|
|
29
|
-
item,
|
|
30
|
-
} );
|
|
31
|
-
|
|
32
|
-
expect( result ).toBe( '' );
|
|
33
|
-
} );
|
|
34
|
-
|
|
35
|
-
it.each( [
|
|
36
|
-
[ 512, /^512\s+B$/, 'bytes (less than 1 KB)' ],
|
|
37
|
-
[ 1024 * 50, /^50\s+KB$/, '50 kilobytes' ],
|
|
38
|
-
[ 1024 * 1024 * 5, /^5\s+MB$/, '5 megabytes' ],
|
|
39
|
-
[ 1024 * 1024 * 1024 * 2.5, /^2\.5\s+GB$/, '2.5 gigabytes' ],
|
|
40
|
-
[ 1024 * 1024 * 1024 * 1024 * 1.5, /^1\.5\s+TB$/, '1.5 terabytes' ],
|
|
41
|
-
[
|
|
42
|
-
1024 * 1024 * 3.14159,
|
|
43
|
-
/^3\.14\s+MB$/,
|
|
44
|
-
'fractional sizes with proper decimals',
|
|
45
|
-
],
|
|
46
|
-
[ 1024, /^1\s+KB$/, 'boundary value (exactly 1 KB)' ],
|
|
47
|
-
] )(
|
|
48
|
-
'formats %s bytes correctly: %s',
|
|
49
|
-
( filesize, expected, description ) => {
|
|
50
|
-
const item = {
|
|
51
|
-
media_details: {
|
|
52
|
-
filesize,
|
|
53
|
-
sizes: {},
|
|
54
|
-
},
|
|
55
|
-
} as MediaItem;
|
|
56
|
-
|
|
57
|
-
const result = filesizeField.getValue?.( {
|
|
58
|
-
item,
|
|
59
|
-
} );
|
|
60
|
-
|
|
61
|
-
try {
|
|
62
|
-
expect( result ).toMatch( expected );
|
|
63
|
-
} catch ( error ) {
|
|
64
|
-
const message =
|
|
65
|
-
error instanceof Error
|
|
66
|
-
? error.message
|
|
67
|
-
: String( error );
|
|
68
|
-
throw new Error(
|
|
69
|
-
`Failed to format filesize (${ description }): ${ message }`
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
it.each( [
|
|
76
|
-
[ { media_details: { sizes: {} } }, 'when filesize is missing' ],
|
|
77
|
-
[ {}, 'when media_details is missing' ],
|
|
78
|
-
] )( 'returns empty string %s', ( item, description ) => {
|
|
79
|
-
const result = filesizeField.getValue?.( {
|
|
80
|
-
item: item as MediaItem,
|
|
81
|
-
} );
|
|
82
|
-
|
|
83
|
-
try {
|
|
84
|
-
expect( result ).toBe( '' );
|
|
85
|
-
} catch ( error ) {
|
|
86
|
-
const message =
|
|
87
|
-
error instanceof Error ? error.message : String( error );
|
|
88
|
-
throw new Error(
|
|
89
|
-
`Failed getValue test (${ description }): ${ message }`
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
} );
|
|
93
|
-
} );
|
|
94
|
-
|
|
95
|
-
describe( 'isVisible', () => {
|
|
96
|
-
it.each( [
|
|
97
|
-
[ { media_details: { filesize: 1024, sizes: {} } }, true ],
|
|
98
|
-
[ { media_details: { filesize: 0, sizes: {} } }, false ],
|
|
99
|
-
[ { media_details: { sizes: {} } }, false ],
|
|
100
|
-
[ {}, false ],
|
|
101
|
-
] )( 'returns %s for item %#', ( item, expected ) => {
|
|
102
|
-
const result = filesizeField.isVisible?.( item as MediaItem );
|
|
103
|
-
|
|
104
|
-
expect( result ).toBe( expected );
|
|
105
|
-
} );
|
|
106
|
-
} );
|
|
107
|
-
} );
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import type { Attachment, Updatable } from '@wordpress/core-data';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Internal dependencies
|
|
8
|
-
*/
|
|
9
|
-
import mediaDimensionsField from '../index';
|
|
10
|
-
|
|
11
|
-
describe( 'mediaDimensionsField', () => {
|
|
12
|
-
it( 'has correct field configuration', () => {
|
|
13
|
-
expect( mediaDimensionsField ).toMatchObject( {
|
|
14
|
-
id: 'media_dimensions',
|
|
15
|
-
type: 'text',
|
|
16
|
-
label: 'Dimensions',
|
|
17
|
-
enableSorting: false,
|
|
18
|
-
filterBy: false,
|
|
19
|
-
readOnly: true,
|
|
20
|
-
} );
|
|
21
|
-
} );
|
|
22
|
-
|
|
23
|
-
describe( 'getValue - dimension formatting', () => {
|
|
24
|
-
it( 'formats dimensions with × separator', () => {
|
|
25
|
-
const item = {
|
|
26
|
-
media_details: { width: 1920, height: 1080, sizes: {} },
|
|
27
|
-
} as Updatable< Attachment >;
|
|
28
|
-
|
|
29
|
-
const result = mediaDimensionsField.getValue?.( {
|
|
30
|
-
item,
|
|
31
|
-
} );
|
|
32
|
-
|
|
33
|
-
expect( result ).toMatch( /1920\s*×\s*1080/ );
|
|
34
|
-
} );
|
|
35
|
-
|
|
36
|
-
it.each( [
|
|
37
|
-
[
|
|
38
|
-
{ media_details: { height: 1080, sizes: {} } },
|
|
39
|
-
'when width is missing',
|
|
40
|
-
],
|
|
41
|
-
[
|
|
42
|
-
{ media_details: { width: 1920, sizes: {} } },
|
|
43
|
-
'when height is missing',
|
|
44
|
-
],
|
|
45
|
-
[
|
|
46
|
-
{ media_details: { sizes: {} } },
|
|
47
|
-
'when both dimensions are missing',
|
|
48
|
-
],
|
|
49
|
-
[ {}, 'when media_details is missing' ],
|
|
50
|
-
[
|
|
51
|
-
{ media_details: { width: 0, height: 1080, sizes: {} } },
|
|
52
|
-
'when width is 0',
|
|
53
|
-
],
|
|
54
|
-
[
|
|
55
|
-
{ media_details: { width: 1920, height: 0, sizes: {} } },
|
|
56
|
-
'when height is 0',
|
|
57
|
-
],
|
|
58
|
-
[
|
|
59
|
-
{ media_details: { width: 0, height: 0, sizes: {} } },
|
|
60
|
-
'when both width and height are 0',
|
|
61
|
-
],
|
|
62
|
-
] )( 'returns empty string %s', ( item, description ) => {
|
|
63
|
-
const result = mediaDimensionsField.getValue?.( {
|
|
64
|
-
item: item as Updatable< Attachment >,
|
|
65
|
-
} );
|
|
66
|
-
|
|
67
|
-
try {
|
|
68
|
-
expect( result ).toBe( '' );
|
|
69
|
-
} catch ( error ) {
|
|
70
|
-
const message =
|
|
71
|
-
error instanceof Error ? error.message : String( error );
|
|
72
|
-
throw new Error(
|
|
73
|
-
`Failed getValue test (${ description }): ${ message }`
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
} );
|
|
77
|
-
} );
|
|
78
|
-
|
|
79
|
-
describe( 'isVisible', () => {
|
|
80
|
-
it.each( [
|
|
81
|
-
[
|
|
82
|
-
{ media_details: { width: 1920, height: 1080, sizes: {} } },
|
|
83
|
-
true,
|
|
84
|
-
'when both dimensions exist',
|
|
85
|
-
],
|
|
86
|
-
[
|
|
87
|
-
{ media_details: { height: 1080, sizes: {} } },
|
|
88
|
-
false,
|
|
89
|
-
'when width is missing',
|
|
90
|
-
],
|
|
91
|
-
[
|
|
92
|
-
{ media_details: { width: 1920, sizes: {} } },
|
|
93
|
-
false,
|
|
94
|
-
'when height is missing',
|
|
95
|
-
],
|
|
96
|
-
[
|
|
97
|
-
{ media_details: { sizes: {} } },
|
|
98
|
-
false,
|
|
99
|
-
'when both dimensions are missing',
|
|
100
|
-
],
|
|
101
|
-
[
|
|
102
|
-
{ media_details: { width: 0, height: 1080, sizes: {} } },
|
|
103
|
-
false,
|
|
104
|
-
'when width is 0 (due to truthy check)',
|
|
105
|
-
],
|
|
106
|
-
[
|
|
107
|
-
{ media_details: { width: 1920, height: 0, sizes: {} } },
|
|
108
|
-
false,
|
|
109
|
-
'when height is 0 (due to truthy check)',
|
|
110
|
-
],
|
|
111
|
-
[
|
|
112
|
-
{ media_details: { width: 0, height: 0, sizes: {} } },
|
|
113
|
-
false,
|
|
114
|
-
'when both width and height are 0',
|
|
115
|
-
],
|
|
116
|
-
] )( 'returns %s %s', ( item, expected, description ) => {
|
|
117
|
-
const result = mediaDimensionsField.isVisible?.(
|
|
118
|
-
item as Updatable< Attachment >
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
try {
|
|
122
|
-
expect( result ).toBe( expected );
|
|
123
|
-
} catch ( error ) {
|
|
124
|
-
const message =
|
|
125
|
-
error instanceof Error ? error.message : String( error );
|
|
126
|
-
throw new Error(
|
|
127
|
-
`Failed isVisible test (${ description }): ${ message }`
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
} );
|
|
131
|
-
} );
|
|
132
|
-
} );
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/build/utils/{get-media-type-from-mime-type.cjs.map → get-media-type-from-mime-type.js.map}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|