Use js-sdk imports for poll event types instead of events-sdk (#9904)
* Use js-sdk imports for poll event types instead of events-sdk * Attempt to appease some tsc --strict errors * Manually create poll response in cypress test
This commit is contained in:
@@ -26,7 +26,8 @@ import {
|
||||
getBeaconInfoIdentifier,
|
||||
EventType,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { M_POLL_KIND_DISCLOSED, PollStartEvent } from "matrix-events-sdk";
|
||||
import { M_POLL_KIND_DISCLOSED } from "matrix-js-sdk/src/@types/polls";
|
||||
import { PollStartEvent } from "matrix-js-sdk/src/extensible_events_v1/PollStartEvent";
|
||||
import { FeatureSupport, Thread } from "matrix-js-sdk/src/models/thread";
|
||||
import { mocked } from "jest-mock";
|
||||
import { act } from "@testing-library/react";
|
||||
|
||||
@@ -18,7 +18,7 @@ import React from "react";
|
||||
import { act } from "react-dom/test-utils";
|
||||
import { MatrixEvent, EventType } from "matrix-js-sdk/src/matrix";
|
||||
import { LocationAssetType, M_ASSET, M_LOCATION, M_TIMESTAMP } from "matrix-js-sdk/src/@types/location";
|
||||
import { TEXT_NODE_TYPE } from "matrix-js-sdk/src/@types/extensible_events";
|
||||
import { M_TEXT } from "matrix-js-sdk/src/@types/extensible_events";
|
||||
import { fireEvent, getByTestId, render, RenderResult, screen } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
|
||||
@@ -248,7 +248,7 @@ describe("ForwardDialog", () => {
|
||||
const expectedStrippedContent = {
|
||||
...modernLocationEvent.getContent(),
|
||||
body: text,
|
||||
[TEXT_NODE_TYPE.name]: text,
|
||||
[M_TEXT.name]: text,
|
||||
[M_TIMESTAMP.name]: now,
|
||||
[M_ASSET.name]: { type: LocationAssetType.Pin },
|
||||
[M_LOCATION.name]: {
|
||||
@@ -276,7 +276,7 @@ describe("ForwardDialog", () => {
|
||||
const expectedStrippedContent = {
|
||||
...modernLocationEvent.getContent(),
|
||||
body: text,
|
||||
[TEXT_NODE_TYPE.name]: text,
|
||||
[M_TEXT.name]: text,
|
||||
[M_ASSET.name]: { type: LocationAssetType.Pin },
|
||||
[M_LOCATION.name]: {
|
||||
uri: geoUri,
|
||||
@@ -297,7 +297,7 @@ describe("ForwardDialog", () => {
|
||||
const expectedContent = {
|
||||
msgtype: "m.location",
|
||||
body: text,
|
||||
[TEXT_NODE_TYPE.name]: text,
|
||||
[M_TEXT.name]: text,
|
||||
[M_ASSET.name]: { type: LocationAssetType.Pin },
|
||||
[M_LOCATION.name]: {
|
||||
uri: geoUri,
|
||||
|
||||
@@ -18,14 +18,10 @@ import React from "react";
|
||||
// eslint-disable-next-line deprecate/import
|
||||
import { mount, ReactWrapper } from "enzyme";
|
||||
import { Room } from "matrix-js-sdk/src/models/room";
|
||||
import {
|
||||
M_POLL_KIND_DISCLOSED,
|
||||
M_POLL_KIND_UNDISCLOSED,
|
||||
M_POLL_START,
|
||||
M_TEXT,
|
||||
PollStartEvent,
|
||||
} from "matrix-events-sdk";
|
||||
import { M_POLL_KIND_DISCLOSED, M_POLL_KIND_UNDISCLOSED, M_POLL_START } from "matrix-js-sdk/src/@types/polls";
|
||||
import { PollStartEvent } from "matrix-js-sdk/src/extensible_events_v1/PollStartEvent";
|
||||
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
|
||||
import { M_TEXT } from "matrix-js-sdk/src/@types/extensible_events";
|
||||
|
||||
import { findById, getMockClientWithEventEmitter } from "../../../test-utils";
|
||||
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
||||
|
||||
@@ -26,10 +26,10 @@ import {
|
||||
M_POLL_KIND_UNDISCLOSED,
|
||||
M_POLL_RESPONSE,
|
||||
M_POLL_START,
|
||||
M_POLL_START_EVENT_CONTENT,
|
||||
M_TEXT,
|
||||
POLL_ANSWER,
|
||||
} from "matrix-events-sdk";
|
||||
PollStartEventContent,
|
||||
PollAnswer,
|
||||
} from "matrix-js-sdk/src/@types/polls";
|
||||
import { M_TEXT } from "matrix-js-sdk/src/@types/extensible_events";
|
||||
import { MockedObject } from "jest-mock";
|
||||
|
||||
import {
|
||||
@@ -440,7 +440,7 @@ describe("MPollBody", () => {
|
||||
responseEvent("@catrd:example.com", "poutine"),
|
||||
responseEvent("@dune2:example.com", "wings"),
|
||||
];
|
||||
const body = newMPollBody(votes, [], null, false);
|
||||
const body = newMPollBody(votes, [], undefined, false);
|
||||
expect(votesCount(body, "pizza")).toBe("");
|
||||
expect(votesCount(body, "poutine")).toBe("");
|
||||
expect(votesCount(body, "italian")).toBe("");
|
||||
@@ -456,7 +456,7 @@ describe("MPollBody", () => {
|
||||
responseEvent("@catrd:example.com", "poutine"),
|
||||
responseEvent("@dune2:example.com", "wings"),
|
||||
];
|
||||
const body = newMPollBody(votes, [], null, false);
|
||||
const body = newMPollBody(votes, [], undefined, false);
|
||||
|
||||
// My vote is marked
|
||||
expect(body.find('input[value="pizza"]').prop("checked")).toBeTruthy();
|
||||
@@ -474,7 +474,7 @@ describe("MPollBody", () => {
|
||||
responseEvent("@dune2:example.com", "wings"),
|
||||
];
|
||||
const ends = [endEvent("@me:example.com", 12)];
|
||||
const body = newMPollBody(votes, ends, null, false);
|
||||
const body = newMPollBody(votes, ends, undefined, false);
|
||||
expect(endedVotesCount(body, "pizza")).toBe("3 votes");
|
||||
expect(endedVotesCount(body, "poutine")).toBe("1 vote");
|
||||
expect(endedVotesCount(body, "italian")).toBe("0 votes");
|
||||
@@ -913,7 +913,7 @@ describe("MPollBody", () => {
|
||||
responseEvent("@yh:example.com", "poutine", 14),
|
||||
];
|
||||
const ends = [];
|
||||
const body = newMPollBody(votes, ends, null, false);
|
||||
const body = newMPollBody(votes, ends, undefined, false);
|
||||
expect(body.html()).toMatchSnapshot();
|
||||
});
|
||||
|
||||
@@ -927,7 +927,7 @@ describe("MPollBody", () => {
|
||||
responseEvent("@yh:example.com", "poutine", 14),
|
||||
];
|
||||
const ends = [endEvent("@me:example.com", 25)];
|
||||
const body = newMPollBody(votes, ends, null, false);
|
||||
const body = newMPollBody(votes, ends, undefined, false);
|
||||
expect(body.html()).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
@@ -951,7 +951,7 @@ function newRelations(relationEvents: Array<MatrixEvent>, eventType: string): Re
|
||||
function newMPollBody(
|
||||
relationEvents: Array<MatrixEvent>,
|
||||
endEvents: Array<MatrixEvent> = [],
|
||||
answers?: POLL_ANSWER[],
|
||||
answers?: PollAnswer[],
|
||||
disclosed = true,
|
||||
): ReactWrapper {
|
||||
const mxEvent = new MatrixEvent({
|
||||
@@ -1033,7 +1033,7 @@ function endedVotesCount(wrapper: ReactWrapper, value: string): string {
|
||||
return wrapper.find(`div[data-value="${value}"] .mx_MPollBody_optionVoteCount`).text();
|
||||
}
|
||||
|
||||
function newPollStart(answers?: POLL_ANSWER[], question?: string, disclosed = true): M_POLL_START_EVENT_CONTENT {
|
||||
function newPollStart(answers?: PollAnswer[], question?: string, disclosed = true): PollStartEventContent {
|
||||
if (!answers) {
|
||||
answers = [
|
||||
{ id: "pizza", [M_TEXT.name]: "Pizza" },
|
||||
@@ -1047,7 +1047,7 @@ function newPollStart(answers?: POLL_ANSWER[], question?: string, disclosed = tr
|
||||
question = "What should we order for the party?";
|
||||
}
|
||||
|
||||
const answersFallback = answers.map((a, i) => `${i + 1}. ${a[M_TEXT.name]}`).join("\n");
|
||||
const answersFallback = answers.map((a, i) => `${i + 1}. ${M_TEXT.findIn<string>(a)}`).join("\n");
|
||||
|
||||
const fallback = `${question}\n${answersFallback}`;
|
||||
|
||||
|
||||
@@ -23,14 +23,10 @@ import { MatrixEvent } from "matrix-js-sdk/src/models/event";
|
||||
import { EventType, RelationType, MsgType } from "matrix-js-sdk/src/@types/event";
|
||||
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
|
||||
import { IEvent, Room, EventTimelineSet, IMinimalEvent } from "matrix-js-sdk/src/matrix";
|
||||
import {
|
||||
M_POLL_RESPONSE,
|
||||
M_POLL_END,
|
||||
M_POLL_KIND_DISCLOSED,
|
||||
PollStartEvent,
|
||||
PollResponseEvent,
|
||||
PollEndEvent,
|
||||
} from "matrix-events-sdk";
|
||||
import { M_POLL_RESPONSE, M_POLL_END, M_POLL_KIND_DISCLOSED } from "matrix-js-sdk/src/@types/polls";
|
||||
import { PollStartEvent } from "matrix-js-sdk/src/extensible_events_v1/PollStartEvent";
|
||||
import { PollResponseEvent } from "matrix-js-sdk/src/extensible_events_v1/PollResponseEvent";
|
||||
import { PollEndEvent } from "matrix-js-sdk/src/extensible_events_v1/PollEndEvent";
|
||||
|
||||
import { stubClient, mkStubRoom, mkEvent, mkMessage } from "../../../test-utils";
|
||||
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
||||
|
||||
@@ -15,9 +15,10 @@ limitations under the License.
|
||||
*/
|
||||
|
||||
import { MatrixEvent } from "matrix-js-sdk/src/matrix";
|
||||
import { M_TEXT, M_POLL_START, POLL_ANSWER, M_POLL_KIND_DISCLOSED } from "matrix-events-sdk";
|
||||
import { M_POLL_START, PollAnswer, M_POLL_KIND_DISCLOSED } from "matrix-js-sdk/src/@types/polls";
|
||||
import { M_TEXT } from "matrix-js-sdk/src/@types/extensible_events";
|
||||
|
||||
export const makePollStartEvent = (question: string, sender: string, answers?: POLL_ANSWER[]): MatrixEvent => {
|
||||
export const makePollStartEvent = (question: string, sender: string, answers?: PollAnswer[]): MatrixEvent => {
|
||||
if (!answers) {
|
||||
answers = [
|
||||
{ id: "socks", [M_TEXT.name]: "Socks" },
|
||||
|
||||
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { TEXT_NODE_TYPE } from "matrix-js-sdk/src/@types/extensible_events";
|
||||
import { M_TEXT } from "matrix-js-sdk/src/@types/extensible_events";
|
||||
import {
|
||||
ILocationContent,
|
||||
LocationAssetType,
|
||||
@@ -38,7 +38,7 @@ describe("isSelfLocation", () => {
|
||||
msgtype: "m.location",
|
||||
geo_uri: "",
|
||||
[M_LOCATION.name]: { uri: "" },
|
||||
[TEXT_NODE_TYPE.name]: "",
|
||||
[M_TEXT.name]: "",
|
||||
[M_TIMESTAMP.name]: 0,
|
||||
// Note: no m.asset!
|
||||
};
|
||||
@@ -51,7 +51,7 @@ describe("isSelfLocation", () => {
|
||||
msgtype: "m.location",
|
||||
geo_uri: "",
|
||||
[M_LOCATION.name]: { uri: "" },
|
||||
[TEXT_NODE_TYPE.name]: "",
|
||||
[M_TEXT.name]: "",
|
||||
[M_TIMESTAMP.name]: 0,
|
||||
[M_ASSET.name]: {
|
||||
// Note: no type!
|
||||
|
||||
Reference in New Issue
Block a user