@@ -40,3 +40,72 @@ describe( 'FollowMe Edit utilities', () => {
4040 expect ( options . defaultAvatarUrl ) . toBe ( 'test.jpg' ) ;
4141 } ) ;
4242} ) ;
43+
44+ describe ( 'FollowMe button-only style detection' , ( ) => {
45+ /**
46+ * Helper to detect if button-only style is active.
47+ * This mirrors the logic used in edit.js.
48+ *
49+ * @param {string } className Block className attribute.
50+ * @return {boolean } True if button-only style is active.
51+ */
52+ const isButtonOnly = ( className ) => {
53+ return className && className . includes ( 'is-style-button-only' ) ;
54+ } ;
55+
56+ test ( 'detects button-only style from className' , ( ) => {
57+ expect ( isButtonOnly ( 'is-style-button-only' ) ) . toBe ( true ) ;
58+ expect ( isButtonOnly ( 'wp-block-activitypub-follow-me is-style-button-only' ) ) . toBe ( true ) ;
59+ expect ( isButtonOnly ( 'is-style-button-only has-custom-width' ) ) . toBe ( true ) ;
60+ } ) ;
61+
62+ test ( 'returns false for other styles' , ( ) => {
63+ expect ( isButtonOnly ( 'is-style-default' ) ) . toBe ( false ) ;
64+ expect ( isButtonOnly ( 'is-style-profile' ) ) . toBe ( false ) ;
65+ } ) ;
66+
67+ test ( 'returns falsy for empty or missing className' , ( ) => {
68+ expect ( isButtonOnly ( '' ) ) . toBeFalsy ( ) ;
69+ expect ( isButtonOnly ( null ) ) . toBeFalsy ( ) ;
70+ expect ( isButtonOnly ( undefined ) ) . toBeFalsy ( ) ;
71+ } ) ;
72+ } ) ;
73+
74+ describe ( 'FollowMe button width CSS classes' , ( ) => {
75+ /**
76+ * Core/button adds these classes when width is selected.
77+ * Our CSS targets these to enable percentage widths in button-only style.
78+ */
79+ const BUTTON_WIDTH_CLASSES = {
80+ 25 : 'has-custom-width wp-block-button__width-25' ,
81+ 50 : 'has-custom-width wp-block-button__width-50' ,
82+ 75 : 'has-custom-width wp-block-button__width-75' ,
83+ 100 : 'has-custom-width wp-block-button__width-100' ,
84+ } ;
85+
86+ test ( 'width classes follow core/button naming convention' , ( ) => {
87+ Object . entries ( BUTTON_WIDTH_CLASSES ) . forEach ( ( [ width , className ] ) => {
88+ expect ( className ) . toContain ( 'has-custom-width' ) ;
89+ expect ( className ) . toContain ( `wp-block-button__width-${ width } ` ) ;
90+ } ) ;
91+ } ) ;
92+
93+ test ( 'all percentage widths are supported' , ( ) => {
94+ const supportedWidths = [ 25 , 50 , 75 , 100 ] ;
95+ supportedWidths . forEach ( ( width ) => {
96+ expect ( BUTTON_WIDTH_CLASSES [ width ] ) . toBeDefined ( ) ;
97+ } ) ;
98+ } ) ;
99+
100+ test ( 'has-custom-width class triggers block display mode' , ( ) => {
101+ // This test documents the expected behavior:
102+ // When .has-custom-width is present on .wp-block-button inside button-only style,
103+ // the CSS should switch from inline-block to block display.
104+ const hasCustomWidthSelector = '.is-style-button-only div.wp-block-button.has-custom-width' ;
105+ const expectedDisplay = 'block' ;
106+
107+ // We're testing the selector pattern, not actual CSS (that's in style.scss)
108+ expect ( hasCustomWidthSelector ) . toContain ( 'has-custom-width' ) ;
109+ expect ( expectedDisplay ) . toBe ( 'block' ) ;
110+ } ) ;
111+ } ) ;
0 commit comments