Skip to content

Conversation

@ramonjd
Copy link
Member

@ramonjd ramonjd commented Dec 16, 2025

What?

Related to #72612 (comment) and partial follow up to #73071

Add unit tests for media fields: filename, filesize, media dimensions.

  • filename field (7 tests): Field configuration, filename extraction via getValue, and view component rendering (short/long filenames, edge cases)
  • filesize field (20 tests): Field configuration, byte formatting logic (B → KB → MB → GB → TB with proper decimal handling), and isVisible behavior
  • media_dimensions field (8 tests): Field configuration, dimension formatting (width × height), and isVisible behavior

I think the media thumbnail could an E2E test? Happy to try to mock that up too if required.

Testing Instructions

Tests should pass!

@ramonjd ramonjd self-assigned this Dec 16, 2025
@ramonjd ramonjd added [Feature] Media Anything that impacts the experience of managing media [Type] Code Quality Issues or PRs that relate to code quality labels Dec 16, 2025
Comment on lines +9 to +17
expect( filesizeField ).toMatchObject( {
id: 'filesize',
type: 'text',
label: 'File size',
enableSorting: false,
filterBy: false,
readOnly: true,
} );
} );
Copy link
Member Author

Choose a reason for hiding this comment

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

These kind of expectations might be an overkill?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hrm... could be! If pressed, I'd say the has correct field configuration test does feel a bit overkill as it's unlikely to be a useful test for us. That said, it's very easy to change if it causes any trouble, so I don't mind either way.

@github-actions
Copy link

github-actions bot commented Dec 16, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @Copilot.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: Copilot.

Co-authored-by: ramonjd <[email protected]>
Co-authored-by: andrewserong <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds comprehensive unit tests for media fields with unique logic, covering filename, filesize, and media_dimensions fields. The tests validate field configuration, data extraction/formatting logic, visibility conditions, and view component rendering behavior.

Key Changes:

  • Added 7 tests for filename field covering configuration, getValue extraction, and view rendering with various filename lengths
  • Added 20 tests for filesize field covering configuration, byte unit formatting (B through TB), and isVisible behavior
  • Added 8 tests for media_dimensions field covering configuration, dimension formatting, and isVisible behavior

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
packages/media-fields/src/media_dimensions/test/index.test.ts Adds tests for media dimensions field configuration, getValue dimension formatting with × separator, and isVisible logic
packages/media-fields/src/filesize/test/index.test.tsx Adds tests for filesize field configuration, byte formatting across multiple units with decimal handling, and isVisible behavior
packages/media-fields/src/filename/test/view.test.tsx Adds tests for filename view component rendering with short/long filenames and edge cases
packages/media-fields/src/filename/test/index.test.ts Adds tests for filename field configuration and getValue extraction from source_url

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI commented Dec 16, 2025

@ramonjd I've opened a new pull request, #74016, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI commented Dec 16, 2025

@ramonjd I've opened a new pull request, #74017, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI commented Dec 16, 2025

@ramonjd I've opened a new pull request, #74018, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI commented Dec 16, 2025

@ramonjd I've opened a new pull request, #74019, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI commented Dec 16, 2025

@ramonjd I've opened a new pull request, #74020, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI commented Dec 16, 2025

@ramonjd I've opened a new pull request, #74021, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI commented Dec 16, 2025

@ramonjd I've opened a new pull request, #74022, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI commented Dec 16, 2025

@ramonjd I've opened a new pull request, #74023, to work on those changes. Once the pull request is ready, I'll request review from you.

@ramonjd
Copy link
Member Author

ramonjd commented Dec 16, 2025

LOL, thanks for all the PRs copilot

@github-actions
Copy link

Flaky tests detected in 13ae070.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/20254574974
📝 Reported issues:

Copy link
Contributor

@andrewserong andrewserong left a comment

Choose a reason for hiding this comment

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

Thanks for adding the tests! Hope you don't mind, but I've pushed a Claude-assisted change to consolidate some of the repetitive tests to use it.each() to group them together for readability. But feel free to keep moving things around if you preferred a different structure.

LGTM! 🚀

Comment on lines +9 to +17
expect( filesizeField ).toMatchObject( {
id: 'filesize',
type: 'text',
label: 'File size',
enableSorting: false,
filterBy: false,
readOnly: true,
} );
} );
Copy link
Contributor

Choose a reason for hiding this comment

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

Hrm... could be! If pressed, I'd say the has correct field configuration test does feel a bit overkill as it's unlikely to be a useful test for us. That said, it's very easy to change if it causes any trouble, so I don't mind either way.

@ramonjd
Copy link
Member Author

ramonjd commented Dec 18, 2025

to group them together for readability. But feel free to keep moving things around if you preferred a different structure.

Thank you! All changes are welcome 🙇🏻

@ramonjd ramonjd force-pushed the add/media-fields-tests branch from 2ab6faf to 5175d8d Compare December 18, 2025 00:48
@ramonjd
Copy link
Member Author

ramonjd commented Dec 18, 2025

Just rebasing and kicking off tests again. Some funky e2e fails, not related I presume

@ramonjd ramonjd enabled auto-merge (squash) December 18, 2025 00:49
@andrewserong
Copy link
Contributor

Oh, I think I might have missed a TypeScript error, I'll take a quick look

@andrewserong
Copy link
Contributor

Just kicked the e2es off again. Looks like the TS issue is fixed, so I'm pretty sure this one was just flaky. We'll see if the auto-merge winds up doing its thing!

@ramonjd ramonjd merged commit e51d410 into trunk Dec 18, 2025
41 of 45 checks passed
@ramonjd ramonjd deleted the add/media-fields-tests branch December 18, 2025 01:47
@github-actions github-actions bot added this to the Gutenberg 22.4 milestone Dec 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Media Anything that impacts the experience of managing media [Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants