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

[RNMobile] Search Block: Add UI Tests and make available to production! #30783

Merged
merged 31 commits into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2da4ec0
Add initial basic UI test for search block
AmandaRiu Apr 7, 2021
1f067ec
Search block UI tests -- wip
AmandaRiu Apr 8, 2021
7e51bf6
Work in progress
AmandaRiu Apr 9, 2021
15c2fbf
Add testIDs for iOS UI tests
AmandaRiu Apr 10, 2021
0d2a822
Simplify access to block child components
AmandaRiu Apr 10, 2021
cad8a0f
Finished iOS and Android tests for editing child elements
AmandaRiu Apr 12, 2021
4f7065c
Add method to open block settings and dismiss
AmandaRiu Apr 12, 2021
65d07cf
Add Search block settings UI tests
AmandaRiu Apr 12, 2021
c9c400d
Clean up and optimize Search block tests
AmandaRiu Apr 13, 2021
3ba23c6
Add unit tests to check for testIDs
AmandaRiu Apr 13, 2021
056ba95
Move button below input if width greater than 50%
AmandaRiu Apr 13, 2021
963e6f3
Use long button styles only when container or button width changes
AmandaRiu Apr 14, 2021
1dc8fdb
Update unit-test snapshots
AmandaRiu Apr 15, 2021
e4a5461
Remove unused code
AmandaRiu Apr 15, 2021
34752e7
Merge branch 'rnmobile/search-block-long-button-text' into rnmobile/s…
AmandaRiu Apr 15, 2021
84941e4
Update unit-test snapshot
AmandaRiu Apr 15, 2021
abfde8a
Add changelog note for Search Block release
AmandaRiu Apr 15, 2021
d655e88
Merge branch 'trunk' into rnmobile/search-block-ui-tests
AmandaRiu Apr 16, 2021
fe44004
Updated unit-test snapshots for changes in long text
AmandaRiu Apr 16, 2021
78a47c4
Merge branch 'trunk' into rnmobile/search-block-ui-tests
AmandaRiu Apr 20, 2021
fe0a2d2
Remove unit-tests for testIDs
AmandaRiu Apr 20, 2021
52a41b9
Update packages/react-native-editor/CHANGELOG.md
AmandaRiu Apr 20, 2021
ddc4f3d
Track when a screenreader is active
AmandaRiu Apr 21, 2021
b3e70e3
Set accessibilityLabel to match testID when screenreader is not active
AmandaRiu Apr 21, 2021
e4f0aea
Access search block elements by accessibilityID
AmandaRiu Apr 21, 2021
faaa933
Update unit test snapshot
AmandaRiu Apr 21, 2021
2e7a4ef
Use undefined instead of null so it doesn't show up in snapshot
AmandaRiu Apr 22, 2021
e2e5a20
Remove unused code
AmandaRiu Apr 22, 2021
17a78d9
Remove testID as no longer needed for iOS e2e
AmandaRiu Apr 22, 2021
9bbe965
Remove forced clear text option and expand sleep
AmandaRiu Apr 23, 2021
e552cf4
Avoid test flakiness by making search block fields
AmandaRiu Apr 23, 2021
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
2 changes: 1 addition & 1 deletion packages/block-library/src/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export const registerCoreBlocks = () => {
file,
audio,
devOnly( reusableBlock ),
devOnly( search ),
search,
devOnly( embed ),
].forEach( registerBlock );

Expand Down
108 changes: 92 additions & 16 deletions packages/block-library/src/search/edit.native.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { View } from 'react-native';
import { View, AccessibilityInfo } from 'react-native';
import classnames from 'classnames';

/**
Expand Down Expand Up @@ -57,6 +57,9 @@ export default function SearchEdit( {
);
const [ isLongButton, setIsLongButton ] = useState( false );
const [ buttonWidth, setButtonWidth ] = useState( MIN_BUTTON_WIDTH );
const [ isScreenReaderEnabled, setIsScreenReaderEnabled ] = useState(
false
);

const textInputRef = useRef( null );

Expand All @@ -69,6 +72,34 @@ export default function SearchEdit( {
buttonText,
} = attributes;

/*
* Check if screenreader is enabled and save to state. This is important for
* properly creating accessibilityLabel text.
*/
useEffect( () => {
AccessibilityInfo.addEventListener(
'screenReaderChanged',
handleScreenReaderToggled
);

AccessibilityInfo.isScreenReaderEnabled().then(
( screenReaderEnabled ) => {
setIsScreenReaderEnabled( screenReaderEnabled );
}
);

return () => {
AccessibilityInfo.removeEventListener(
'screenReaderChanged',
handleScreenReaderToggled
);
};
}, [] );

const handleScreenReaderToggled = ( screenReaderEnabled ) => {
setIsScreenReaderEnabled( screenReaderEnabled );
};

/*
* Called when the value of isSelected changes. Blurs the PlainText component
* used by the placeholder when this block loses focus.
Expand Down Expand Up @@ -204,24 +235,67 @@ export default function SearchEdit( {
isLongButton && { flexDirection: 'column' },
];

const getPlaceholderAccessibilityLabel = () => {
/**
* If a screenreader is enabled, create a descriptive label for this field. If
* not, return a label that is used during automated UI tests.
*
* @return {string} The accessibilityLabel for the Search Button
*/
const getAccessibilityLabelForButton = () => {
if ( ! isScreenReaderEnabled ) {
return 'search-block-button';
}
dcalhoun marked this conversation as resolved.
Show resolved Hide resolved

return `${ __(
'Search button. Current button text is'
) } ${ buttonText }`;
};

/**
* If a screenreader is enabled, create a descriptive label for this field. If
* not, return a label that is used during automated UI tests.
*
* @return {string} The accessibilityLabel for the Search Input
* placeholder field.
*/
const getAccessibilityLabelForPlaceholder = () => {
if ( ! isScreenReaderEnabled ) {
return 'search-block-input';
}

const title = __( 'Search input field.' );
const description = placeholder
? `${ __( 'Current placeholder text is' ) } ${ placeholder }`
: __( 'No custom placeholder set' );
return `${ title } ${ description }`;
};

/**
* If a screenreader is enabled, create a descriptive label for this field. If
* not, return a label that is used during automated UI tests.
*
* @return {string} The accessibilityLabel for the Search Label field
*/
const getAccessibilityLabelForLabel = () => {
if ( ! isScreenReaderEnabled ) {
return 'search-block-label';
}

return `${ __( 'Search block label. Current text is' ) } ${ label }`;
};

const renderTextField = () => {
return (
<View
style={ styles.searchInputContainer }
accessible={ true }
accessibilityRole="none"
accessibilityHint={ __(
'Double tap to edit placeholder text'
) }
accessibilityLabel={ getPlaceholderAccessibilityLabel() }
accessibilityHint={
isScreenReaderEnabled
? __( 'Double tap to edit placeholder text' )
: undefined
}
accessibilityLabel={ getAccessibilityLabelForPlaceholder() }
>
<PlainText
ref={ textInputRef }
Expand Down Expand Up @@ -278,12 +352,12 @@ export default function SearchEdit( {
<View
accessible={ true }
accessibilityRole="none"
accessibilityHint={ __(
'Double tap to edit button text'
) }
accessibilityLabel={ `${ __(
'Search button. Current button text is'
) } ${ buttonText }` }
accessibilityHint={
isScreenReaderEnabled
? __( 'Double tap to edit button text' )
: undefined
}
accessibilityLabel={ getAccessibilityLabelForButton() }
onLayout={ onLayoutButton }
>
<RichText
Expand Down Expand Up @@ -333,10 +407,12 @@ export default function SearchEdit( {
<View
accessible={ true }
accessibilityRole="none"
accessibilityHint={ __( 'Double tap to edit label text' ) }
accessibilityLabel={ `${ __(
'Search block label. Current text is'
) } ${ label }` }
accessibilityHint={
isScreenReaderEnabled
? __( 'Double tap to edit label text' )
: undefined
}
accessibilityLabel={ getAccessibilityLabelForLabel() }
>
<RichText
className="wp-block-search__label"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ exports[`Search Block renders block with button inside option 1`] = `
importantForAccessibility="no-hide-descendants"
>
<View
accessibilityHint="Double tap to edit label text"
accessibilityLabel="Search block label. Current text is Search"
accessibilityLabel="search-block-label"
accessibilityRole="none"
accessible={true}
>
Expand Down Expand Up @@ -74,8 +73,7 @@ exports[`Search Block renders block with button inside option 1`] = `
}
>
<View
accessibilityHint="Double tap to edit placeholder text"
accessibilityLabel="Search input field. No custom placeholder set"
accessibilityLabel="search-block-input"
accessibilityRole="none"
accessible={true}
>
Expand Down Expand Up @@ -111,8 +109,7 @@ exports[`Search Block renders block with button inside option 1`] = `
}
>
<View
accessibilityHint="Double tap to edit button text"
accessibilityLabel="Search button. Current button text is Search Button"
accessibilityLabel="search-block-button"
accessibilityRole="none"
accessible={true}
onLayout={[Function]}
Expand Down Expand Up @@ -183,8 +180,7 @@ exports[`Search Block renders block with icon button option matches snapshot 1`]
importantForAccessibility="no-hide-descendants"
>
<View
accessibilityHint="Double tap to edit label text"
accessibilityLabel="Search block label. Current text is Search"
accessibilityLabel="search-block-label"
accessibilityRole="none"
accessible={true}
>
Expand Down Expand Up @@ -250,8 +246,7 @@ exports[`Search Block renders block with icon button option matches snapshot 1`]
}
>
<View
accessibilityHint="Double tap to edit placeholder text"
accessibilityLabel="Search input field. No custom placeholder set"
accessibilityLabel="search-block-input"
accessibilityRole="none"
accessible={true}
>
Expand Down Expand Up @@ -308,8 +303,7 @@ exports[`Search Block renders block with label hidden matches snapshot 1`] = `
}
>
<View
accessibilityHint="Double tap to edit placeholder text"
accessibilityLabel="Search input field. No custom placeholder set"
accessibilityLabel="search-block-input"
accessibilityRole="none"
accessible={true}
>
Expand Down Expand Up @@ -345,8 +339,7 @@ exports[`Search Block renders block with label hidden matches snapshot 1`] = `
}
>
<View
accessibilityHint="Double tap to edit button text"
accessibilityLabel="Search button. Current button text is Search Button"
accessibilityLabel="search-block-button"
accessibilityRole="none"
accessible={true}
onLayout={[Function]}
Expand Down Expand Up @@ -417,8 +410,7 @@ exports[`Search Block renders with default configuration matches snapshot 1`] =
importantForAccessibility="no-hide-descendants"
>
<View
accessibilityHint="Double tap to edit label text"
accessibilityLabel="Search block label. Current text is Search"
accessibilityLabel="search-block-label"
accessibilityRole="none"
accessible={true}
>
Expand Down Expand Up @@ -484,8 +476,7 @@ exports[`Search Block renders with default configuration matches snapshot 1`] =
}
>
<View
accessibilityHint="Double tap to edit placeholder text"
accessibilityLabel="Search input field. No custom placeholder set"
accessibilityLabel="search-block-input"
accessibilityRole="none"
accessible={true}
>
Expand Down Expand Up @@ -521,8 +512,7 @@ exports[`Search Block renders with default configuration matches snapshot 1`] =
}
>
<View
accessibilityHint="Double tap to edit button text"
accessibilityLabel="Search button. Current button text is Search Button"
accessibilityLabel="search-block-button"
accessibilityRole="none"
accessible={true}
onLayout={[Function]}
Expand Down Expand Up @@ -593,8 +583,7 @@ exports[`Search Block renders with no-button option matches snapshot 1`] = `
importantForAccessibility="no-hide-descendants"
>
<View
accessibilityHint="Double tap to edit label text"
accessibilityLabel="Search block label. Current text is Search"
accessibilityLabel="search-block-label"
accessibilityRole="none"
accessible={true}
>
Expand Down Expand Up @@ -651,8 +640,7 @@ exports[`Search Block renders with no-button option matches snapshot 1`] = `
</View>
</View>
<View
accessibilityHint="Double tap to edit placeholder text"
accessibilityLabel="Search input field. No custom placeholder set"
accessibilityLabel="search-block-input"
accessibilityRole="none"
accessible={true}
>
Expand Down
1 change: 1 addition & 0 deletions packages/react-native-editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ For each user feature we should also add a importance categorization label to i

## Unreleased

- [***] Search block now available on mobile! [https://github.com/WordPress/gutenberg/pull/30783]
- [*] Image block: Add a "featured" banner. (Android only) [#30806]

## 1.51.0
Expand Down
Loading