Skip to content

Commit

Permalink
Lint test files
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewFerr committed Nov 12, 2024
1 parent 0e3b2fc commit 428c03a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
"plugin:matrix-org/babel",
],
parserOptions: {
project: ["./tsconfig.json"],
project: ["./tsconfig-dev.json"],
},
env: {
browser: true,
Expand Down
29 changes: 15 additions & 14 deletions test/ClientWidgetApi-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

import { waitFor } from '@testing-library/dom';

import { ClientWidgetApi } from "../src/ClientWidgetApi";
import { WidgetDriver } from "../src/driver/WidgetDriver";
import { UnstableApiVersion } from '../src/interfaces/ApiVersion';
Expand Down Expand Up @@ -43,11 +44,11 @@ import {
} from '../src';
import { IGetMediaConfigActionFromWidgetActionRequest } from '../src/interfaces/GetMediaConfigAction';

jest.mock('../src/transport/PostmessageTransport')
jest.mock('../src/transport/PostmessageTransport');

afterEach(() => {
jest.resetAllMocks();
})
});

function createRoomEvent(event: Partial<IRoomEvent> = {}): IRoomEvent {
return {
Expand All @@ -63,7 +64,7 @@ function createRoomEvent(event: Partial<IRoomEvent> = {}): IRoomEvent {
}

class CustomMatrixError extends Error {
constructor(
public constructor(
message: string,
public readonly httpStatus: number,
public readonly name: string,
Expand Down Expand Up @@ -96,7 +97,7 @@ describe('ClientWidgetApi', () => {
let transport: PostmessageTransport;
let emitEvent: Parameters<PostmessageTransport["on"]>["1"];

async function loadIframe(caps: Capability[] = []) {
async function loadIframe(caps: Capability[] = []): Promise<void> {
capabilities = caps;

const ready = new Promise<void>(resolve => {
Expand Down Expand Up @@ -517,7 +518,7 @@ describe('ClientWidgetApi', () => {
});
});

expect(driver.sendDelayedEvent).not.toBeCalled()
expect(driver.sendDelayedEvent).not.toBeCalled();
});

it('sends delayed message events', async () => {
Expand Down Expand Up @@ -736,7 +737,7 @@ describe('ClientWidgetApi', () => {
});
});

expect(driver.updateDelayedEvent).not.toBeCalled()
expect(driver.updateDelayedEvent).not.toBeCalled();
});

it('fails to update delayed events with unsupported action', async () => {
Expand All @@ -761,7 +762,7 @@ describe('ClientWidgetApi', () => {
});
});

expect(driver.updateDelayedEvent).not.toBeCalled()
expect(driver.updateDelayedEvent).not.toBeCalled();
});

it('updates delayed events', async () => {
Expand Down Expand Up @@ -1123,7 +1124,7 @@ describe('ClientWidgetApi', () => {
driver.readStateEvents.mockResolvedValue([
createRoomEvent({ type: 'net.example.test', state_key: 'A' }),
createRoomEvent({ type: 'net.example.test', state_key: 'B' }),
])
]);

const event: IReadEventFromWidgetActionRequest = {
api: WidgetApiDirection.FromWidget,
Expand Down Expand Up @@ -1151,7 +1152,7 @@ describe('ClientWidgetApi', () => {

expect(driver.readStateEvents).toBeCalledWith(
'net.example.test', undefined, 0, null,
)
);
});

it('fails to read state events with any state key', async () => {
Expand All @@ -1176,13 +1177,13 @@ describe('ClientWidgetApi', () => {
});
});

expect(driver.readStateEvents).not.toBeCalled()
expect(driver.readStateEvents).not.toBeCalled();
});

it('reads state events with a specific state key', async () => {
driver.readStateEvents.mockResolvedValue([
createRoomEvent({ type: 'net.example.test', state_key: 'B' }),
])
]);

const event: IReadEventFromWidgetActionRequest = {
api: WidgetApiDirection.FromWidget,
Expand All @@ -1209,7 +1210,7 @@ describe('ClientWidgetApi', () => {

expect(driver.readStateEvents).toBeCalledWith(
'net.example.test', 'B', 0, null,
)
);
});

it('fails to read state events with a specific state key', async () => {
Expand All @@ -1235,9 +1236,9 @@ describe('ClientWidgetApi', () => {
});
});

expect(driver.readStateEvents).not.toBeCalled()
expect(driver.readStateEvents).not.toBeCalled();
});
})
});

describe('org.matrix.msc3869.read_relations action', () => {
it('should present as supported api version', () => {
Expand Down
20 changes: 10 additions & 10 deletions test/WidgetApi-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ import {
} from '../src';

type SendRequestArgs = {
action: WidgetApiFromWidgetAction,
data: IWidgetApiRequestData,
action: WidgetApiFromWidgetAction;
data: IWidgetApiRequestData;
};

class TransportChannels {
Expand All @@ -54,7 +54,7 @@ class WidgetTransportHelper {
/** For ignoring the request sent by {@link WidgetApi.start} */
private skippedFirstRequest = false;

constructor(private channels: TransportChannels) {}
public constructor(private channels: TransportChannels) {}

public nextTrackedRequest(): SendRequestArgs | undefined {
if (!this.skippedFirstRequest) {
Expand All @@ -70,7 +70,7 @@ class WidgetTransportHelper {
}

class ClientTransportHelper {
constructor(private channels: TransportChannels) {}
public constructor(private channels: TransportChannels) {}

public trackRequest(action: WidgetApiFromWidgetAction, data: IWidgetApiRequestData): void {
this.channels.requestQueue.push({action, data});
Expand All @@ -91,7 +91,7 @@ describe('WidgetApi', () => {
widgetTransportHelper = new WidgetTransportHelper(channels);
const clientTrafficHelper = new ClientTransportHelper(channels);

clientListener = (e: MessageEvent) => {
clientListener = (e: MessageEvent): void => {
if (!e.data.action || !e.data.requestId || !e.data.widgetId) return; // invalid request/response
if ("response" in e.data || e.data.api !== WidgetApiDirection.FromWidget) return; // not a request
const request = <IWidgetApiRequest>e.data;
Expand All @@ -111,7 +111,7 @@ describe('WidgetApi', () => {
"*",
);
}
}
};
window.addEventListener("message", clientListener);

widgetApi = new WidgetApi("WidgetApi-test", "*");
Expand Down Expand Up @@ -171,7 +171,7 @@ describe('WidgetApi', () => {
expect(request).not.toEqual({
action: WidgetApiFromWidgetAction.MSC3869ReadRelations,
data: expect.anything(),
} satisfies SendRequestArgs)
} satisfies SendRequestArgs);
});

it('should handle an error', async () => {
Expand Down Expand Up @@ -486,13 +486,13 @@ describe('WidgetApi', () => {
],
} as ISupportedVersionsActionResponseData,
);
})
});

it('should request supported client versions', async () => {
await expect(widgetApi.getClientVersions()).resolves.toEqual([
'org.matrix.msc3869', 'org.matrix.msc2762',
]);
})
});

it('should cache supported client versions on successive calls', async () => {
await expect(widgetApi.getClientVersions()).resolves.toEqual([
Expand All @@ -505,7 +505,7 @@ describe('WidgetApi', () => {

expect(widgetTransportHelper.nextTrackedRequest()).not.toBeUndefined();
expect(widgetTransportHelper.nextTrackedRequest()).toBeUndefined();
})
});
});

describe('searchUserDirectory', () => {
Expand Down
6 changes: 6 additions & 0 deletions tsconfig-dev.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "./tsconfig.json",
"include": [
"./test/**/*.ts"
]
}

0 comments on commit 428c03a

Please sign in to comment.