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

Add Site Icon tests for Site Health and warnings in Customizer control #702

Merged
merged 69 commits into from
Apr 1, 2022

Conversation

ankitrox
Copy link
Collaborator

@ankitrox ankitrox commented Feb 16, 2022

Description

When user uploads the site icon via customizer, validate its presence as well as size.
If site icon is not set or is smaller than 512 x 512, issue an error notification in customizer.

In site health screen, check the following.

  1. If site icon is present.
  2. Site icon is greater than 512 x 512
  3. Site icon is png

If any of above fails, issue the warning in site health screen.

Closes #229

thelovekesh and others added 30 commits February 16, 2022 17:48
… as maskable

* Lighthouse gives an error if icon is not maskable.
* Add a checkbox to allow user to save icon as maskable icon.
* If user have not opt-in for maskable icon then manifest will add icon purpose as `any maskable`.
@thelovekesh
Copy link
Collaborator

@thelovekesh I just noticed the PR is targeting the feature/integration branch instead of develop. Should that be changed?

Yes, since the changes of feature/integration have been already merged we can change the branch to develop.

Perhaps the test should be skipped on PHP 7.1?

IMO yes, tests are passing on all other PHP versions except the 7.1 due to bugs related to images.

@westonruter westonruter changed the base branch from feature/integration to develop March 31, 2022 15:16

notifications.map((notification) => {
wp.customize
.section('title_tagline')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since the control can be moved to another section, it would be best to get the section via siteIconControl.section():

Suggested change
.section('title_tagline')
.section(siteIconControl.section())

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nevertheless, the notification should rather be added to the control instead of being added to the section.

Copy link
Collaborator

Choose a reason for hiding this comment

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

A key reason is that the top of the section may be scrolled out of view, so the user may not see it.

const iconData = wp.customize
.control('site_icon')
.container.find('img.app-icon-preview');
const NotificationData = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The casing of this variable makes it look like a class. So it should be initially lower-cased.

Comment on lines 36 to 37
const iconData = wp.customize
.control('site_icon')
Copy link
Collaborator

Choose a reason for hiding this comment

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

We actually already have a variable containing the site icon control here: siteIconControl

const NotificationData = {
dismissible: true,
message: '',
type: 'error',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably better to make this a warning:

Suggested change
type: 'error',
type: 'warning',


if (!iconData.length) {
notifications.push(
new wp.customize.Notification('pwa_icon_not_set', {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't see this notification being added initially when no icon was set.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, it should get automatically cleared when an icon is set.

$icon_validation_messages = array(
'pwa_icon_not_set' => __( 'Site icon is not present', 'pwa' ),
'pwa_icon_too_small' => __( 'Site icon needs to be at least 512 x 512', 'pwa' ),
'pwa_icon_no_png' => __( 'Site icon should .png', 'pwa' ),
Copy link
Collaborator

Choose a reason for hiding this comment

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

This message isn't being used currently.

tests/test-class-wp-web-app-manifest.php Show resolved Hide resolved
.control('site_icon')
.container.find('img.app-icon-preview');
const NotificationData = {
dismissible: true,
Copy link
Collaborator

Choose a reason for hiding this comment

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

There won't be a need to be dismissible if the notification automatically is removed when the issue is fixed.

$results['badge']['color'] = 'orange';
$results['actions'] = wp_kses_post(
sprintf(
'<a class="button button-primary" href="%s">%s</a>',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
'<a class="button button-primary" href="%s">%s</a>',
'<a class="button button-secondary" href="%s">%s</a>',

return $icon_errors;
}

if ( $site_icon_metadata['width'] < 512 && $site_icon_metadata['height'] < 512 ) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if ( $site_icon_metadata['width'] < 512 && $site_icon_metadata['height'] < 512 ) {
if ( $site_icon_metadata['width'] < 512 || $site_icon_metadata['height'] < 512 ) {

@westonruter
Copy link
Collaborator

With my latest changes…

When a user selects a non-square GIF that is too small in the Customizer:

Screen Shot 2022-03-31 at 16 27 54

And in the Site Health test:

Screen Shot 2022-03-31 at 16 27 42

@westonruter westonruter changed the title Site icon validation and customiser notifications Add Site Icon tests for Site Health and warnings in Customizer control Apr 1, 2022
@westonruter westonruter added the web-app-manifest Web App Manifests label Apr 1, 2022
@westonruter westonruter merged commit 95425af into develop Apr 1, 2022
@westonruter westonruter deleted the feature/229-site-health-tests-for-site-icon branch April 1, 2022 02:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Warn when no Site Icon set, when it is too small, or when a PNG is not being used
4 participants