Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Merge branch 'psg-906/poll-history-active-filter' into psg-1030/poll-…
Browse files Browse the repository at this point in the history
…history-extract-poll-option
  • Loading branch information
Kerry authored Feb 9, 2023
2 parents 4a41ee4 + eeffebc commit e246c6a
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 111 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/static_analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ jobs:
- "--noImplicitAny"
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Install Deps
run: "scripts/ci/layered.sh"
Expand Down
4 changes: 2 additions & 2 deletions src/components/views/location/ZoomButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ const ZoomButtons: React.FC<Props> = ({ map }) => {
<div className="mx_ZoomButtons">
<AccessibleButton
onClick={onZoomIn}
data-test-id="map-zoom-in-button"
data-testid="map-zoom-in-button"
title={_t("Zoom in")}
className="mx_ZoomButtons_button"
>
<PlusIcon className="mx_ZoomButtons_icon" />
</AccessibleButton>
<AccessibleButton
onClick={onZoomOut}
data-test-id="map-zoom-out-button"
data-testid="map-zoom-out-button"
title={_t("Zoom out")}
className="mx_ZoomButtons_button"
>
Expand Down
9 changes: 6 additions & 3 deletions src/components/views/rooms/BasicMessageComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,19 @@ export default class BasicMessageEditor extends React.Component<IProps, IState>
public replaceEmoticon(caretPosition: DocumentPosition, regex: RegExp): number {
const { model } = this.props;
const range = model.startRange(caretPosition);
// expand range max 8 characters backwards from caretPosition,
// expand range max 9 characters backwards from caretPosition,
// as a space to look for an emoticon
let n = 8;
let n = 9;
range.expandBackwardsWhile((index, offset) => {
const part = model.parts[index];
n -= 1;
return n >= 0 && [Type.Plain, Type.PillCandidate, Type.Newline].includes(part.type);
});
const emoticonMatch = regex.exec(range.text);
if (emoticonMatch) {
// ignore matches at start of proper substrings
// so xd will not match if the string was "mixd 123456"
// and we are lookinh at xd 123456 part of the string
if (emoticonMatch && (n >= 0 || emoticonMatch.index !== 0)) {
const query = emoticonMatch[1].replace("-", "");
// try both exact match and lower-case, this means that xd won't match xD but :P will match :p
const data = EMOTICON_TO_EMOJI.get(query) || EMOTICON_TO_EMOJI.get(query.toLowerCase());
Expand Down
3 changes: 2 additions & 1 deletion src/effects/confetti/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
Copyright 2020 Nurjin Jafar
Copyright 2020 Nordeck IT + Consulting GmbH.
Copyright 2023 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -86,7 +87,7 @@ export default class Confetti implements ICanvasEffect {
private particles: Array<ConfettiParticle> = [];
private waveAngle = 0;

public isRunning: boolean;
public isRunning = false;

public start = async (canvas: HTMLCanvasElement, timeout = 3000): Promise<void> => {
if (!canvas) {
Expand Down
5 changes: 3 additions & 2 deletions src/effects/fireworks/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
Copyright 2020 Nurjin Jafar
Copyright 2020 Nordeck IT + Consulting GmbH.
Copyright 2023 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -69,7 +70,7 @@ export default class Fireworks implements ICanvasEffect {
private context: CanvasRenderingContext2D | null = null;
private supportsAnimationFrame = window.requestAnimationFrame;
private particles: Array<FireworksParticle> = [];
public isRunning: boolean;
public isRunning = false;

public start = async (canvas: HTMLCanvasElement, timeout = 3000): Promise<void> => {
if (!canvas) {
Expand All @@ -94,7 +95,7 @@ export default class Fireworks implements ICanvasEffect {
if (this.particles.length < this.options.maxCount && this.isRunning) {
this.createFirework();
}
const alive = [];
const alive: FireworksParticle[] = [];
for (let i = 0; i < this.particles.length; i++) {
if (this.move(this.particles[i])) {
alive.push(this.particles[i]);
Expand Down
6 changes: 3 additions & 3 deletions src/effects/hearts/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 The Matrix.org Foundation C.I.C.
Copyright 2021 - 2023 The Matrix.org Foundation C.I.C.
Copyright 2022 Arseny Uskov
Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -65,7 +65,7 @@ export default class Hearts implements ICanvasEffect {

private context: CanvasRenderingContext2D | null = null;
private particles: Array<Heart> = [];
private lastAnimationTime: number;
private lastAnimationTime = 0;

private colours = [
"rgba(194,210,224,1)",
Expand All @@ -82,7 +82,7 @@ export default class Hearts implements ICanvasEffect {
"rgba(252,116,183,1)",
];

public isRunning: boolean;
public isRunning = false;

public start = async (canvas: HTMLCanvasElement, timeout = 3000): Promise<void> => {
if (!canvas) {
Expand Down
6 changes: 3 additions & 3 deletions src/effects/rainfall/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 The Matrix.org Foundation C.I.C.
Copyright 2020 - 2023 The Matrix.org Foundation C.I.C.
Copyright 2021 Josias Allestad
Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -52,9 +52,9 @@ export default class Rainfall implements ICanvasEffect {

private context: CanvasRenderingContext2D | null = null;
private particles: Array<Raindrop> = [];
private lastAnimationTime: number;
private lastAnimationTime = 0;

public isRunning: boolean;
public isRunning = false;

public start = async (canvas: HTMLCanvasElement, timeout = 3000): Promise<void> => {
if (!canvas) {
Expand Down
6 changes: 3 additions & 3 deletions src/effects/snowfall/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 The Matrix.org Foundation C.I.C.
Copyright 2020 - 2023 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -57,9 +57,9 @@ export default class Snowfall implements ICanvasEffect {

private context: CanvasRenderingContext2D | null = null;
private particles: Array<Snowflake> = [];
private lastAnimationTime: number;
private lastAnimationTime = 0;

public isRunning: boolean;
public isRunning = false;

public start = async (canvas: HTMLCanvasElement, timeout = 3000): Promise<void> => {
if (!canvas) {
Expand Down
6 changes: 3 additions & 3 deletions src/effects/spaceinvaders/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 The Matrix.org Foundation C.I.C.
Copyright 2021 - 2023 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -51,9 +51,9 @@ export default class SpaceInvaders implements ICanvasEffect {

private context: CanvasRenderingContext2D | null = null;
private particles: Array<Invader> = [];
private lastAnimationTime: number;
private lastAnimationTime = 0;

public isRunning: boolean;
public isRunning = false;

public start = async (canvas: HTMLCanvasElement, timeout = 3000): Promise<void> => {
if (!canvas) {
Expand Down
21 changes: 6 additions & 15 deletions test/components/views/location/ZoomButtons-test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 The Matrix.org Foundation C.I.C.
Copyright 2022, 2023 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -15,48 +15,39 @@ limitations under the License.
*/

import React from "react";
// eslint-disable-next-line deprecate/import
import { mount } from "enzyme";
import * as maplibregl from "maplibre-gl";
import { act } from "react-dom/test-utils";
import { render, screen } from "@testing-library/react";

import ZoomButtons from "../../../../src/components/views/location/ZoomButtons";
import { findByTestId } from "../../../test-utils";

describe("<ZoomButtons />", () => {
const mapOptions = { container: {} as unknown as HTMLElement, style: "" };
const mockMap = new maplibregl.Map(mapOptions);
const defaultProps = {
map: mockMap,
};
const getComponent = (props = {}) => mount(<ZoomButtons {...defaultProps} {...props} />);
const getComponent = (props = {}) => render(<ZoomButtons {...defaultProps} {...props} />);

beforeEach(() => {
jest.clearAllMocks();
});

it("renders buttons", () => {
const component = getComponent();
expect(component).toMatchSnapshot();
expect(component.asFragment()).toMatchSnapshot();
});

it("calls map zoom in on zoom in click", () => {
const component = getComponent();

act(() => {
findByTestId(component, "map-zoom-in-button").at(0).simulate("click");
});
screen.getByTestId("map-zoom-in-button").click();

expect(mockMap.zoomIn).toHaveBeenCalled();
expect(component).toBeTruthy();
});

it("calls map zoom out on zoom out click", () => {
const component = getComponent();

act(() => {
findByTestId(component, "map-zoom-out-button").at(0).simulate("click");
});
screen.getByTestId("map-zoom-out-button").click();

expect(mockMap.zoomOut).toHaveBeenCalled();
expect(component).toBeTruthy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ exports[`<LocationViewDialog /> renders map correctly 1`] = `
>
<AccessibleButton
className="mx_ZoomButtons_button"
data-test-id="map-zoom-in-button"
data-testid="map-zoom-in-button"
element="div"
onClick={[Function]}
role="button"
Expand All @@ -144,7 +144,7 @@ exports[`<LocationViewDialog /> renders map correctly 1`] = `
>
<div
className="mx_AccessibleButton mx_ZoomButtons_button"
data-test-id="map-zoom-in-button"
data-testid="map-zoom-in-button"
onClick={[Function]}
onKeyDown={[Function]}
onKeyUp={[Function]}
Expand All @@ -159,7 +159,7 @@ exports[`<LocationViewDialog /> renders map correctly 1`] = `
</AccessibleButton>
<AccessibleButton
className="mx_ZoomButtons_button"
data-test-id="map-zoom-out-button"
data-testid="map-zoom-out-button"
element="div"
onClick={[Function]}
role="button"
Expand All @@ -168,7 +168,7 @@ exports[`<LocationViewDialog /> renders map correctly 1`] = `
>
<div
className="mx_AccessibleButton mx_ZoomButtons_button"
data-test-id="map-zoom-out-button"
data-testid="map-zoom-out-button"
onClick={[Function]}
onKeyDown={[Function]}
onKeyUp={[Function]}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,74 +1,32 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<ZoomButtons /> renders buttons 1`] = `
<ZoomButtons
map={
MockMap {
"_events": {},
"_eventsCount": 0,
"_maxListeners": undefined,
"addControl": [MockFunction],
"fitBounds": [MockFunction],
"removeControl": [MockFunction],
"setCenter": [MockFunction],
"setStyle": [MockFunction],
"zoomIn": [MockFunction],
"zoomOut": [MockFunction],
Symbol(kCapture): false,
}
}
>
<DocumentFragment>
<div
className="mx_ZoomButtons"
class="mx_ZoomButtons"
>
<AccessibleButton
className="mx_ZoomButtons_button"
data-test-id="map-zoom-in-button"
element="div"
onClick={[Function]}
<div
class="mx_AccessibleButton mx_ZoomButtons_button"
data-testid="map-zoom-in-button"
role="button"
tabIndex={0}
tabindex="0"
title="Zoom in"
>
<div
className="mx_AccessibleButton mx_ZoomButtons_button"
data-test-id="map-zoom-in-button"
onClick={[Function]}
onKeyDown={[Function]}
onKeyUp={[Function]}
role="button"
tabIndex={0}
title="Zoom in"
>
<div
className="mx_ZoomButtons_icon"
/>
</div>
</AccessibleButton>
<AccessibleButton
className="mx_ZoomButtons_button"
data-test-id="map-zoom-out-button"
element="div"
onClick={[Function]}
class="mx_ZoomButtons_icon"
/>
</div>
<div
class="mx_AccessibleButton mx_ZoomButtons_button"
data-testid="map-zoom-out-button"
role="button"
tabIndex={0}
tabindex="0"
title="Zoom out"
>
<div
className="mx_AccessibleButton mx_ZoomButtons_button"
data-test-id="map-zoom-out-button"
onClick={[Function]}
onKeyDown={[Function]}
onKeyUp={[Function]}
role="button"
tabIndex={0}
title="Zoom out"
>
<div
className="mx_ZoomButtons_icon"
/>
</div>
</AccessibleButton>
class="mx_ZoomButtons_icon"
/>
</div>
</div>
</ZoomButtons>
</DocumentFragment>
`;
Loading

0 comments on commit e246c6a

Please sign in to comment.