Skip to content

Fix isMouseEvent returning false for simulated context menu events #301

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

Merged
merged 3 commits into from
Jan 29, 2021
Merged
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
22 changes: 2 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
FROM drydock-prod.workiva.net/workiva/dart_build_image:1

# Chrome install taken from https://github.com/Workiva/dart_unit_test_image/blob/master@%7B13-01-2021%7D/Dockerfile

# Set the expected Chrome major version. This allows us to update the expected version when
# we need to roll out a new version of this base image with a new chrome version as the only change
ENV EXPECTED_CHROME_VERSION=87

# Install Chrome
# Chrome install adapted from https://github.com/Workiva/dart_unit_test_image/blob/master@%7B13-01-2021%7D/Dockerfile
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' | tee /etc/apt/sources.list.d/google-chrome.list && \
apt-get -qq update && apt-get install -y google-chrome-stable && \
mv /usr/bin/google-chrome-stable /usr/bin/google-chrome && \
sed -i --follow-symlinks -e 's/\"\$HERE\/chrome\"/\"\$HERE\/chrome\" --no-sandbox/g' /usr/bin/google-chrome

# Fail the build if the version doesn't match what we expected
RUN google-chrome --version | grep " $EXPECTED_CHROME_VERSION\."

# TODO: Remove this and instead run it within the github actions CI on the stable channel once SDK lower bound is >=2.9.3
RUN dartfmt --line-length=120 --dry-run --set-exit-if-changed .

Expand Down Expand Up @@ -46,22 +37,13 @@ RUN apt-get install -y \
wget \
&& rm -rf /var/lib/apt/lists/*

# Chrome install taken from https://github.com/Workiva/dart_unit_test_image/blob/master@%7B13-01-2021%7D/Dockerfile

# Set the expected Chrome major version. This allows us to update the expected version when
# we need to roll out a new version of this base image with a new chrome version as the only change
ENV EXPECTED_CHROME_VERSION=87

# Install Chrome
# Chrome install adapted from https://github.com/Workiva/dart_unit_test_image/blob/master@%7B13-01-2021%7D/Dockerfile
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' | tee /etc/apt/sources.list.d/google-chrome.list && \
apt-get -qq update && apt-get install -y google-chrome-stable && \
mv /usr/bin/google-chrome-stable /usr/bin/google-chrome && \
sed -i --follow-symlinks -e 's/\"\$HERE\/chrome\"/\"\$HERE\/chrome\" --no-sandbox/g' /usr/bin/google-chrome

# Fail the build if the version doesn't match what we expected
RUN google-chrome --version | grep " $EXPECTED_CHROME_VERSION\."

WORKDIR /build/
ADD . /build/

Expand Down
3 changes: 2 additions & 1 deletion lib/src/react_client/event_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,8 @@ extension SyntheticEventTypeHelpers on SyntheticEvent {
(_hasProperty('relatedTarget') && !_hasProperty('button')) || _checkEventType(const ['focus', 'blur']);

/// Uses Duck Typing to detect if the event instance is a [SyntheticMouseEvent].
bool get isMouseEvent => _hasProperty('button') || _checkEventType(const ['mouse', 'click', 'drag', 'drop']);
bool get isMouseEvent =>
_hasProperty('button') || _checkEventType(const ['mouse', 'click', 'drag', 'drop', 'contextmenu']);

/// Uses Duck Typing to detect if the event instance is a [SyntheticPointerEvent].
bool get isPointerEvent => _hasProperty('pointerId') || _checkEventType(const ['pointer']);
Expand Down
1 change: 1 addition & 0 deletions test/react_test_utils_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ testUtils({isComponent2: false, dynamic eventComponent, dynamic sampleComponent,
group('compositionStart', () => testEvent(Simulate.compositionStart, 'compositionStart', expectCompositionEvent));
group('compositionUpdate',
() => testEvent(Simulate.compositionUpdate, 'compositionUpdate', expectCompositionEvent));
group('contextMenu', () => testEvent(Simulate.contextMenu, 'contextMenu', expectMouseEvent));
group('cut', () => testEvent(Simulate.cut, 'cut', expectClipboardEvent));
group('doubleClick', () => testEvent(Simulate.doubleClick, 'doubleClick', expectMouseEvent));
group('drag', () => testEvent(Simulate.drag, 'drag', expectMouseEvent));
Expand Down
1 change: 1 addition & 0 deletions test/test_components.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class EventComponent extends Component {
'onCompositionEnd': onEvent,
'onCompositionStart': onEvent,
'onCompositionUpdate': onEvent,
'onContextMenu': onEvent,
'onCut': onEvent,
'onDoubleClick': onEvent,
'onDrag': onEvent,
Expand Down
1 change: 1 addition & 0 deletions test/test_components2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class EventComponent2 extends Component2 {
'onCompositionEnd': onEvent,
'onCompositionStart': onEvent,
'onCompositionUpdate': onEvent,
'onContextMenu': onEvent,
'onCut': onEvent,
'onDoubleClick': onEvent,
'onDrag': onEvent,
Expand Down