Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/changelog/add-pre-publish-tags-hint
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Before publishing a post without tags, the tag suggestion now explains that tags are shared as hashtags, which help people on the Fediverse find your post.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The changelog only mentions the tag sentence, but people who update will also see the new format sentence and the reworded format suggestion. Maybe "Before publishing, the tag and post format suggestions now explain what tags and formats do on the Fediverse." so the entry covers both.

4 changes: 3 additions & 1 deletion build/pre-publish-panel/plugin.asset.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions build/pre-publish-panel/plugin.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions includes/class-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public static function enqueue_editor_assets() {
'noteLength' => ACTIVITYPUB_NOTE_LENGTH,
'statsImageUrlEndpoint' => Stats_Image::is_available() ? \get_rest_url( null, ACTIVITYPUB_REST_NAMESPACE . '/stats/image-url/{user_id}/{year}' ) : '',
'reactionTypes' => self::get_reaction_types(),
'useHashtags' => '1' === \get_option( 'activitypub_use_hashtags', '0' ),
);
\wp_localize_script( 'wp-editor', '_activityPubOptions', $data );

Expand Down
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"@wordpress/editor": "^16.1.0",
"@wordpress/element": "^10.0.0",
"@wordpress/env": "^12.1.0",
"@wordpress/hooks": "^5.1.0",
"@wordpress/html-entities": "^5.0.0",
"@wordpress/i18n": "^7.0.0",
"@wordpress/icons": "^20.0.0",
Expand Down
167 changes: 167 additions & 0 deletions src/pre-publish-panel/__tests__/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,55 @@
// Set up the global options before importing utils, so NOTE_LENGTH picks up the value.
window._activityPubOptions = { noteLength: 500 };

import { render, screen } from '@testing-library/react';
import { registerPlugin } from '@wordpress/plugins';
import { applyFilters } from '@wordpress/hooks';
import { __, sprintf } from '@wordpress/i18n';
import { analyzeBlocks, getSuggestedPostFormat } from '../utils';
import '../plugin';

// The editor state the panels read, changed per test.
let mockEditorState;

jest.mock( '@wordpress/plugins', () => ( { registerPlugin: jest.fn() } ) );

jest.mock( '@wordpress/editor', () => ( {
PluginPrePublishPanel: ( { title, children } ) => (
<div data-testid="pre-publish-panel">
<h2>{ title }</h2>
{ children }
</div>
),
PostTaxonomiesFlatTermSelector: ( { slug } ) => <div data-testid="term-selector" data-slug={ slug } />,
store: 'core/editor',
} ) );

jest.mock( '@wordpress/components', () => ( {
Button: ( { children, onClick } ) => <button onClick={ onClick }>{ children }</button>,
} ) );

jest.mock( '@wordpress/block-editor', () => ( { store: 'core/block-editor' } ) );

jest.mock( '@wordpress/core-data', () => ( { store: 'core' } ) );

jest.mock( '@wordpress/data', () => ( {
useDispatch: () => ( { editPost: jest.fn() } ),
useSelect: ( callback ) =>
callback( ( store ) => {
if ( 'core/block-editor' === store ) {
return { getBlocks: () => mockEditorState.blocks ?? [] };
}

if ( 'core' === store ) {
return { getThemeSupports: () => ( { formats: mockEditorState.themeFormats ?? [] } ) };
}

return {
getEditedPostAttribute: ( attribute ) => mockEditorState.attributes[ attribute ],
getSuggestedPostFormat: () => mockEditorState.coreSuggestion ?? null,
};
} ),
} ) );

describe( 'analyzeBlocks', () => {
test( 'returns all zeros for empty blocks', () => {
Expand Down Expand Up @@ -397,3 +445,122 @@ describe( 'getSuggestedPostFormat', () => {
expect( result.format ).toBe( 'gallery' );
} );
} );

describe( 'Tags suggestion', () => {
const Panels = () => {
const { render: Render } = registerPlugin.mock.calls[ 0 ][ 1 ];
return <Render />;
};

const coreText =
'%s help users and search engines navigate your site and find your content. Add a few keywords to describe your post.';

beforeEach( () => {
window._activityPubOptions = { noteLength: 500 };
mockEditorState = { attributes: {} };
} );

test( 'marks the panels with the asterism icon', () => {
const { container } = render( registerPlugin.mock.calls[ 0 ][ 1 ].icon );

expect( container.querySelector( 'svg text' ) ).toHaveTextContent( '⁂' );
} );

test( 'renders no panel of its own', () => {
render( <Panels /> );

expect( screen.queryByTestId( 'pre-publish-panel' ) ).toBeNull();
} );

test( 'adds a note on hashtags to core suggestion text', () => {
// Core's call, through the default i18n instance.
expect(
sprintf(
/* translators: %s: The taxonomy name. */
__(
'%s help users and search engines navigate your site and find your content. Add a few keywords to describe your post.'
),
'Tags'
)
).toBe(
'Tags help users and search engines navigate your site and find your content. Add a few keywords to describe your post. Tags are also shared as hashtags, which help people on the Fediverse find your post.'
);
} );

test( 'mentions hashtags in the content when they are enabled', () => {
window._activityPubOptions.useHashtags = true;

expect( sprintf( applyFilters( 'i18n.gettext_default', coreText, coreText, undefined ), 'Tags' ) ).toMatch(
/Any #hashtag you write in your post is added as a tag too\.$/
);
} );

test( 'leaves other core strings alone', () => {
expect( __( 'Add a few keywords to describe your post.' ) ).toBe( 'Add a few keywords to describe your post.' );
} );
} );

describe( 'Post format suggestion text', () => {
const coreText =
'Your theme uses post formats to highlight different kinds of content, like images or videos. Apply a post format to see this special styling.';

test( 'adds a note on the Fediverse when the format sets the object type', () => {
window._activityPubOptions = { objectType: 'wordpress-post-format' };

// Core's call, through the default i18n instance.
expect(
__(
'Your theme uses post formats to highlight different kinds of content, like images or videos. Apply a post format to see this special styling.'
)
).toBe( `${ coreText } The format also changes how your post is shared on the Fediverse.` );
} );

test( 'leaves the text alone when the format does not set the object type', () => {
window._activityPubOptions = { objectType: 'note' };

expect( applyFilters( 'i18n.gettext_default', coreText, coreText, undefined ) ).toBe( coreText );
} );
} );

describe( 'Post format panel', () => {
const Panels = () => {
const { render: Render } = registerPlugin.mock.calls[ 0 ][ 1 ];
return <Render />;
};

beforeEach( () => {
window._activityPubOptions = { noteLength: 500, objectType: 'wordpress-post-format' };
mockEditorState = {
attributes: { format: 'standard' },
blocks: [ { name: 'core/image', attributes: {}, innerBlocks: [] } ],
};
} );

test( 'titles a format suggestion as a suggestion', () => {
render( <Panels /> );

expect( screen.getByRole( 'heading' ) ).toHaveTextContent( 'Suggestion:Use a post format' );
} );

test( 'titles the confirmation of a set format as the post format', () => {
mockEditorState.attributes.format = 'image';
render( <Panels /> );

expect( screen.getByRole( 'heading' ) ).toHaveTextContent( /^Post format$/ );
} );

test( 'leaves the suggestion to core when core suggests a format', () => {
mockEditorState.coreSuggestion = 'image';
mockEditorState.themeFormats = [ 'image' ];
render( <Panels /> );

expect( screen.queryByTestId( 'pre-publish-panel' ) ).toBeNull();
} );

test( "suggests a format when the theme does not support core's suggestion", () => {
mockEditorState.coreSuggestion = 'image';
render( <Panels /> );

expect( screen.getByRole( 'heading' ) ).toHaveTextContent( 'Suggestion:Use a post format' );
} );
} );
Loading
Loading