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

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerry Archibald committed Sep 26, 2022
1 parent 24f920d commit 3dcd9f7
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ describe('<DeviceDetails />', () => {
display_name: 'My Device',
last_seen_ip: '123.456.789',
last_seen_ts: now - 60000000,
clientName: 'Element Web',
};
const { container } = render(getComponent({ device }));
expect(container).toMatchSnapshot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,32 @@ exports[`<DeviceDetails /> renders device with metadata 1`] = `
</tr>
</tbody>
</table>
<table
class="mx_DeviceDetails_metadataTable"
data-testid="device-detail-metadata-application"
>
<thead>
<tr>
<th>
Application
</th>
</tr>
</thead>
<tbody>
<tr>
<td
class="mxDeviceDetails_metadataLabel"
>
Name
</td>
<td
class="mxDeviceDetails_metadataValue"
>
Element Web
</td>
</tr>
</tbody>
</table>
<table
class="mx_DeviceDetails_metadataTable"
data-testid="device-detail-metadata-device"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ describe('<SessionManagerTab />', () => {
mockClient.getDevices.mockResolvedValue({ devices: [alicesDevice, alicesMobileDevice] });
mockClient.getAccountData.mockImplementation((eventType: string) => {
const content = {
name: 'Element Web',
version: '1.2.3',
url: 'test.com',
};
name: 'Element Web',
version: '1.2.3',
url: 'test.com',
};
return new MatrixEvent({
type: eventType,
content,
Expand Down
62 changes: 61 additions & 1 deletion test/utils/device/clientInformation-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { MatrixEvent } from "matrix-js-sdk/src/matrix";

import BasePlatform from "../../../src/BasePlatform";
import { IConfigOptions } from "../../../src/IConfigOptions";
import { recordClientInformation } from "../../../src/utils/device/clientInformation";
import {
getDeviceClientInformation,
recordClientInformation,
} from "../../../src/utils/device/clientInformation";
import { getMockClientWithEventEmitter } from "../../test-utils";

describe('recordClientInformation()', () => {
Expand Down Expand Up @@ -84,3 +89,58 @@ describe('recordClientInformation()', () => {
);
});
});

describe('getDeviceClientInformation()', () => {
const deviceId = 'my-device-id';

const mockClient = getMockClientWithEventEmitter({
getAccountData: jest.fn(),
});

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

it('returns an empty object when no event exists for the device', () => {
expect(getDeviceClientInformation(mockClient, deviceId)).toEqual({});

expect(mockClient.getAccountData).toHaveBeenCalledWith(
`io.element.matrix-client-information.${deviceId}`,
);
});

it('returns client information for the device', () => {
const eventContent = {
name: 'Element Web',
version: '1.2.3',
url: 'test.com',
};
const event = new MatrixEvent({
type: `io.element.matrix-client-information.${deviceId}`,
content: eventContent,
});
mockClient.getAccountData.mockReturnValue(event);
expect(getDeviceClientInformation(mockClient, deviceId)).toEqual(eventContent);
});

it('excludes values with incorrect types', () => {
const eventContent = {
extraField: 'hello',
name: 'Element Web',
// wrong format
version: { value: '1.2.3' },
url: 'test.com',
};
const event = new MatrixEvent({
type: `io.element.matrix-client-information.${deviceId}`,
content: eventContent,
});
mockClient.getAccountData.mockReturnValue(event);
// invalid fields excluded
expect(getDeviceClientInformation(mockClient, deviceId)).toEqual({
name: eventContent.name,
url: eventContent.url,
});
});
});

0 comments on commit 3dcd9f7

Please sign in to comment.