Include /test in tsc config, fix rest of issues (#8119)
* fix ts issue in PosthogAnalytics test Signed-off-by: Kerry Archibald <kerrya@element.io> * fix remaining ts issues Signed-off-by: Kerry Archibald <kerrya@element.io> * tsconfig change Signed-off-by: Kerry Archibald <kerrya@element.io> * use sdkconfig patch instead of put Signed-off-by: Kerry Archibald <kerrya@element.io>
This commit is contained in:
parent
752ad6a9f9
commit
a8d65ab5c5
8 changed files with 63 additions and 65 deletions
|
@ -41,7 +41,7 @@ import { ScreenName } from "./PosthogTrackers";
|
||||||
* - If both flags are false or not set, events are not sent.
|
* - If both flags are false or not set, events are not sent.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
interface IEvent {
|
export interface IPosthogEvent {
|
||||||
// The event name that will be used by PostHog. Event names should use camelCase.
|
// The event name that will be used by PostHog. Event names should use camelCase.
|
||||||
eventName: string;
|
eventName: string;
|
||||||
|
|
||||||
|
@ -272,7 +272,7 @@ export class PosthogAnalytics {
|
||||||
this.setAnonymity(Anonymity.Disabled);
|
this.setAnonymity(Anonymity.Disabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
public trackEvent<E extends IEvent>({ eventName, ...properties }: E): void {
|
public trackEvent<E extends IPosthogEvent>({ eventName, ...properties }: E): void {
|
||||||
if (this.anonymity == Anonymity.Disabled || this.anonymity == Anonymity.Anonymous) return;
|
if (this.anonymity == Anonymity.Disabled || this.anonymity == Anonymity.Anonymous) return;
|
||||||
this.capture(eventName, properties);
|
this.capture(eventName, properties);
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ const VIRTUAL_ROOM_BOB = "$virtual_bob_room:example.org";
|
||||||
const BOB_PHONE_NUMBER = "01818118181";
|
const BOB_PHONE_NUMBER = "01818118181";
|
||||||
|
|
||||||
function mkStubDM(roomId, userId) {
|
function mkStubDM(roomId, userId) {
|
||||||
const room = mkStubRoom(roomId);
|
const room = mkStubRoom(roomId, 'room', MatrixClientPeg.get());
|
||||||
room.getJoinedMembers = jest.fn().mockReturnValue([
|
room.getJoinedMembers = jest.fn().mockReturnValue([
|
||||||
{
|
{
|
||||||
userId: '@me:example.org',
|
userId: '@me:example.org',
|
||||||
|
@ -312,9 +312,9 @@ describe('CallHandler', () => {
|
||||||
fakeCall.emit(CallEvent.AssertedIdentityChanged);
|
fakeCall.emit(CallEvent.AssertedIdentityChanged);
|
||||||
|
|
||||||
// Now set the config option
|
// Now set the config option
|
||||||
SdkConfig.put({
|
SdkConfig.add({
|
||||||
voip: {
|
voip: {
|
||||||
obeyAssertedIdentity: true,
|
obey_asserted_identity: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -14,37 +14,34 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { mocked } from 'jest-mock';
|
||||||
|
import { PostHog } from 'posthog-js';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Anonymity,
|
Anonymity,
|
||||||
|
|
||||||
getRedactedCurrentLocation,
|
getRedactedCurrentLocation,
|
||||||
IEvent,
|
IPosthogEvent,
|
||||||
PosthogAnalytics,
|
PosthogAnalytics,
|
||||||
} from '../src/PosthogAnalytics';
|
} from '../src/PosthogAnalytics';
|
||||||
import SdkConfig from '../src/SdkConfig';
|
import SdkConfig from '../src/SdkConfig';
|
||||||
|
import { getMockClientWithEventEmitter } from './test-utils';
|
||||||
|
|
||||||
class FakePosthog {
|
const getFakePosthog = (): PostHog => ({
|
||||||
public capture;
|
capture: jest.fn(),
|
||||||
public init;
|
init: jest.fn(),
|
||||||
public identify;
|
identify: jest.fn(),
|
||||||
public reset;
|
reset: jest.fn(),
|
||||||
public register;
|
register: jest.fn(),
|
||||||
|
} as unknown as PostHog);
|
||||||
|
|
||||||
constructor() {
|
export interface ITestEvent extends IPosthogEvent {
|
||||||
this.capture = jest.fn();
|
|
||||||
this.init = jest.fn();
|
|
||||||
this.identify = jest.fn();
|
|
||||||
this.reset = jest.fn();
|
|
||||||
this.register = jest.fn();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ITestEvent extends IEvent {
|
|
||||||
eventName: "JestTestEvents";
|
eventName: "JestTestEvents";
|
||||||
foo: string;
|
foo: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("PosthogAnalytics", () => {
|
describe("PosthogAnalytics", () => {
|
||||||
let fakePosthog: FakePosthog;
|
let fakePosthog: PostHog;
|
||||||
const shaHashes = {
|
const shaHashes = {
|
||||||
"42": "73475cb40a568e8da8a045ced110137e159f890ac4da883b6b17dc651b3a8049",
|
"42": "73475cb40a568e8da8a045ced110137e159f890ac4da883b6b17dc651b3a8049",
|
||||||
"some": "a6b46dd0d1ae5e86cbc8f37e75ceeb6760230c1ca4ffbcb0c97b96dd7d9c464b",
|
"some": "a6b46dd0d1ae5e86cbc8f37e75ceeb6760230c1ca4ffbcb0c97b96dd7d9c464b",
|
||||||
|
@ -53,7 +50,7 @@ describe("PosthogAnalytics", () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
fakePosthog = new FakePosthog();
|
fakePosthog = getFakePosthog();
|
||||||
|
|
||||||
window.crypto = {
|
window.crypto = {
|
||||||
subtle: {
|
subtle: {
|
||||||
|
@ -64,10 +61,10 @@ describe("PosthogAnalytics", () => {
|
||||||
for (let c = 0; c < hexHash.length; c += 2) {
|
for (let c = 0; c < hexHash.length; c += 2) {
|
||||||
bytes.push(parseInt(hexHash.substr(c, 2), 16));
|
bytes.push(parseInt(hexHash.substr(c, 2), 16));
|
||||||
}
|
}
|
||||||
return bytes;
|
return bytes as unknown as ArrayBuffer;
|
||||||
},
|
},
|
||||||
},
|
} as unknown as SubtleCrypto,
|
||||||
};
|
} as unknown as Crypto;
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
@ -118,8 +115,8 @@ describe("PosthogAnalytics", () => {
|
||||||
eventName: "JestTestEvents",
|
eventName: "JestTestEvents",
|
||||||
foo: "bar",
|
foo: "bar",
|
||||||
});
|
});
|
||||||
expect(fakePosthog.capture.mock.calls[0][0]).toBe("JestTestEvents");
|
expect(mocked(fakePosthog).capture.mock.calls[0][0]).toBe("JestTestEvents");
|
||||||
expect(fakePosthog.capture.mock.calls[0][1]["foo"]).toEqual("bar");
|
expect(mocked(fakePosthog).capture.mock.calls[0][1]["foo"]).toEqual("bar");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not track events if anonymous", async () => {
|
it("Should not track events if anonymous", async () => {
|
||||||
|
@ -128,7 +125,7 @@ describe("PosthogAnalytics", () => {
|
||||||
eventName: "JestTestEvents",
|
eventName: "JestTestEvents",
|
||||||
foo: "bar",
|
foo: "bar",
|
||||||
});
|
});
|
||||||
expect(fakePosthog.capture.mock.calls.length).toBe(0);
|
expect(fakePosthog.capture).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not track any events if disabled", async () => {
|
it("Should not track any events if disabled", async () => {
|
||||||
|
@ -137,7 +134,7 @@ describe("PosthogAnalytics", () => {
|
||||||
eventName: "JestTestEvents",
|
eventName: "JestTestEvents",
|
||||||
foo: "bar",
|
foo: "bar",
|
||||||
});
|
});
|
||||||
expect(fakePosthog.capture.mock.calls.length).toBe(0);
|
expect(fakePosthog.capture).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should anonymise location of a known screen", async () => {
|
it("Should anonymise location of a known screen", async () => {
|
||||||
|
@ -157,28 +154,30 @@ describe("PosthogAnalytics", () => {
|
||||||
|
|
||||||
it("Should identify the user to posthog if pseudonymous", async () => {
|
it("Should identify the user to posthog if pseudonymous", async () => {
|
||||||
analytics.setAnonymity(Anonymity.Pseudonymous);
|
analytics.setAnonymity(Anonymity.Pseudonymous);
|
||||||
class FakeClient {
|
const client = getMockClientWithEventEmitter({
|
||||||
getAccountDataFromServer = jest.fn().mockResolvedValue(null);
|
getAccountDataFromServer: jest.fn().mockResolvedValue(null),
|
||||||
setAccountData = jest.fn().mockResolvedValue({});
|
setAccountData: jest.fn().mockResolvedValue({}),
|
||||||
}
|
});
|
||||||
await analytics.identifyUser(new FakeClient(), () => "analytics_id");
|
await analytics.identifyUser(client, () => "analytics_id");
|
||||||
expect(fakePosthog.identify.mock.calls[0][0]).toBe("analytics_id");
|
expect(mocked(fakePosthog).identify.mock.calls[0][0]).toBe("analytics_id");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not identify the user to posthog if anonymous", async () => {
|
it("Should not identify the user to posthog if anonymous", async () => {
|
||||||
analytics.setAnonymity(Anonymity.Anonymous);
|
analytics.setAnonymity(Anonymity.Anonymous);
|
||||||
await analytics.identifyUser(null);
|
const client = getMockClientWithEventEmitter({});
|
||||||
expect(fakePosthog.identify.mock.calls.length).toBe(0);
|
await analytics.identifyUser(client, () => "analytics_id");
|
||||||
|
expect(mocked(fakePosthog).identify.mock.calls.length).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should identify using the server's analytics id if present", async () => {
|
it("Should identify using the server's analytics id if present", async () => {
|
||||||
analytics.setAnonymity(Anonymity.Pseudonymous);
|
analytics.setAnonymity(Anonymity.Pseudonymous);
|
||||||
class FakeClient {
|
|
||||||
getAccountDataFromServer = jest.fn().mockResolvedValue({ id: "existing_analytics_id" });
|
const client = getMockClientWithEventEmitter({
|
||||||
setAccountData = jest.fn().mockResolvedValue({});
|
getAccountDataFromServer: jest.fn().mockResolvedValue({ id: "existing_analytics_id" }),
|
||||||
}
|
setAccountData: jest.fn().mockResolvedValue({}),
|
||||||
await analytics.identifyUser(new FakeClient(), () => "new_analytics_id");
|
});
|
||||||
expect(fakePosthog.identify.mock.calls[0][0]).toBe("existing_analytics_id");
|
await analytics.identifyUser(client, () => "new_analytics_id");
|
||||||
|
expect(mocked(fakePosthog).identify.mock.calls[0][0]).toBe("existing_analytics_id");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { mocked } from 'jest-mock';
|
||||||
import { ConditionKind, PushRuleActionName, TweakName } from "matrix-js-sdk/src/@types/PushRules";
|
import { ConditionKind, PushRuleActionName, TweakName } from "matrix-js-sdk/src/@types/PushRules";
|
||||||
|
|
||||||
import { stubClient } from "./test-utils";
|
import { stubClient } from "./test-utils";
|
||||||
|
@ -26,7 +27,7 @@ describe("RoomNotifs test", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("getRoomNotifsState handles rules with no conditions", () => {
|
it("getRoomNotifsState handles rules with no conditions", () => {
|
||||||
MatrixClientPeg.get().pushRules = {
|
mocked(MatrixClientPeg.get()).pushRules = {
|
||||||
global: {
|
global: {
|
||||||
override: [{
|
override: [{
|
||||||
rule_id: "!roomId:server",
|
rule_id: "!roomId:server",
|
||||||
|
@ -40,7 +41,7 @@ describe("RoomNotifs test", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("getRoomNotifsState handles guest users", () => {
|
it("getRoomNotifsState handles guest users", () => {
|
||||||
MatrixClientPeg.get().isGuest.mockReturnValue(true);
|
mocked(MatrixClientPeg.get()).isGuest.mockReturnValue(true);
|
||||||
expect(getRoomNotifsState("!roomId:server")).toBe(RoomNotifState.AllMessages);
|
expect(getRoomNotifsState("!roomId:server")).toBe(RoomNotifState.AllMessages);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -19,9 +19,13 @@ import {
|
||||||
mock,
|
mock,
|
||||||
} from "../../src/accessibility/KeyboardShortcuts";
|
} from "../../src/accessibility/KeyboardShortcuts";
|
||||||
import { getKeyboardShortcuts, getKeyboardShortcutsForUI } from "../../src/accessibility/KeyboardShortcutUtils";
|
import { getKeyboardShortcuts, getKeyboardShortcutsForUI } from "../../src/accessibility/KeyboardShortcutUtils";
|
||||||
import PlatformPeg from "../../src/PlatformPeg";
|
import { mockPlatformPeg, unmockPlatformPeg } from "../test-utils";
|
||||||
|
|
||||||
describe("KeyboardShortcutUtils", () => {
|
describe("KeyboardShortcutUtils", () => {
|
||||||
|
afterEach(() => {
|
||||||
|
unmockPlatformPeg();
|
||||||
|
});
|
||||||
|
|
||||||
it("doesn't change KEYBOARD_SHORTCUTS when getting shortcuts", async () => {
|
it("doesn't change KEYBOARD_SHORTCUTS when getting shortcuts", async () => {
|
||||||
mock({
|
mock({
|
||||||
keyboardShortcuts: {
|
keyboardShortcuts: {
|
||||||
|
@ -31,7 +35,7 @@ describe("KeyboardShortcutUtils", () => {
|
||||||
macOnlyShortcuts: ["Keybind1"],
|
macOnlyShortcuts: ["Keybind1"],
|
||||||
desktopShortcuts: ["Keybind2"],
|
desktopShortcuts: ["Keybind2"],
|
||||||
});
|
});
|
||||||
PlatformPeg.get = () => ({ overrideBrowserShortcuts: () => false });
|
mockPlatformPeg({ overrideBrowserShortcuts: jest.fn().mockReturnValue(false) });
|
||||||
const copyKeyboardShortcuts = Object.assign({}, KEYBOARD_SHORTCUTS);
|
const copyKeyboardShortcuts = Object.assign({}, KEYBOARD_SHORTCUTS);
|
||||||
|
|
||||||
getKeyboardShortcuts();
|
getKeyboardShortcuts();
|
||||||
|
@ -52,7 +56,7 @@ describe("KeyboardShortcutUtils", () => {
|
||||||
desktopShortcuts: ["Keybind2"],
|
desktopShortcuts: ["Keybind2"],
|
||||||
|
|
||||||
});
|
});
|
||||||
PlatformPeg.get = () => ({ overrideBrowserShortcuts: () => false });
|
mockPlatformPeg({ overrideBrowserShortcuts: jest.fn().mockReturnValue(false) });
|
||||||
expect(getKeyboardShortcuts()).toEqual({ "Keybind4": {} });
|
expect(getKeyboardShortcuts()).toEqual({ "Keybind4": {} });
|
||||||
|
|
||||||
mock({
|
mock({
|
||||||
|
@ -63,8 +67,7 @@ describe("KeyboardShortcutUtils", () => {
|
||||||
macOnlyShortcuts: undefined,
|
macOnlyShortcuts: undefined,
|
||||||
desktopShortcuts: ["Keybind2"],
|
desktopShortcuts: ["Keybind2"],
|
||||||
});
|
});
|
||||||
PlatformPeg.get = () => ({ overrideBrowserShortcuts: () => true });
|
mockPlatformPeg({ overrideBrowserShortcuts: jest.fn().mockReturnValue(true) });
|
||||||
expect(getKeyboardShortcuts()).toEqual({ "Keybind1": {}, "Keybind2": {} });
|
expect(getKeyboardShortcuts()).toEqual({ "Keybind1": {}, "Keybind2": {} });
|
||||||
jest.resetModules();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -108,7 +108,10 @@ describe("RovingTabIndex", () => {
|
||||||
{ button2 }
|
{ button2 }
|
||||||
<RovingTabIndexWrapper>
|
<RovingTabIndexWrapper>
|
||||||
{ ({ onFocus, isActive, ref }) =>
|
{ ({ onFocus, isActive, ref }) =>
|
||||||
<button onFocus={onFocus} tabIndex={isActive ? 0 : -1} ref={ref}>.</button>
|
<button
|
||||||
|
onFocus={onFocus}
|
||||||
|
tabIndex={isActive ? 0 : -1}
|
||||||
|
ref={ref as React.RefObject<HTMLButtonElement>}>.</button>
|
||||||
}
|
}
|
||||||
</RovingTabIndexWrapper>
|
</RovingTabIndexWrapper>
|
||||||
</React.Fragment> }
|
</React.Fragment> }
|
||||||
|
|
|
@ -35,10 +35,9 @@ import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
||||||
import defaultDispatcher from "../../../../src/dispatcher/dispatcher";
|
import defaultDispatcher from "../../../../src/dispatcher/dispatcher";
|
||||||
import DocumentOffset from '../../../../src/editor/offset';
|
import DocumentOffset from '../../../../src/editor/offset';
|
||||||
import { Layout } from '../../../../src/settings/enums/Layout';
|
import { Layout } from '../../../../src/settings/enums/Layout';
|
||||||
import PlatformPeg from "../../../../src/PlatformPeg";
|
|
||||||
import { IRoomState } from "../../../../src/components/structures/RoomView";
|
import { IRoomState } from "../../../../src/components/structures/RoomView";
|
||||||
import { RoomPermalinkCreator } from "../../../../src/utils/permalinks/Permalinks";
|
import { RoomPermalinkCreator } from "../../../../src/utils/permalinks/Permalinks";
|
||||||
import BasePlatform from "../../../../src/BasePlatform";
|
import { mockPlatformPeg } from "../../../test-utils/platform";
|
||||||
|
|
||||||
const WrapWithProviders: React.FC<{
|
const WrapWithProviders: React.FC<{
|
||||||
roomContext: IRoomState;
|
roomContext: IRoomState;
|
||||||
|
@ -271,8 +270,7 @@ describe('<SendMessageComposer/>', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("persists to session history upon sending", async () => {
|
it("persists to session history upon sending", async () => {
|
||||||
jest.spyOn(PlatformPeg, 'get').mockReturnValue(
|
mockPlatformPeg({ overrideBrowserShortcuts: jest.fn().mockReturnValue(false) });
|
||||||
{ overrideBrowserShortcuts: () => false } as unknown as BasePlatform);
|
|
||||||
|
|
||||||
const wrapper = getComponent({ replyToEvent: mockEvent });
|
const wrapper = getComponent({ replyToEvent: mockEvent });
|
||||||
|
|
||||||
|
|
|
@ -22,14 +22,8 @@
|
||||||
"include": [
|
"include": [
|
||||||
"./src/**/*.ts",
|
"./src/**/*.ts",
|
||||||
"./src/**/*.tsx",
|
"./src/**/*.tsx",
|
||||||
"./test/test-utils/**/*.ts",
|
"./test/**/*.ts",
|
||||||
"./test/test-utils/**/*.tsx",
|
"./test/**/*.tsx",
|
||||||
"./test/utils/**/*.ts",
|
|
||||||
"./test/utils/**/*.tsx",
|
|
||||||
"./test/stores/**/*.ts",
|
|
||||||
"./test/stores/**/*.tsx",
|
|
||||||
"./test/components/**/*.tsx",
|
|
||||||
"./test/components/**/*.ts",
|
|
||||||
],
|
],
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"./test/end-to-end-tests/"
|
"./test/end-to-end-tests/"
|
||||||
|
|
Loading…
Reference in a new issue