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

Commit 4ceb87e

Browse files
author
Kerry Archibald
committed
tests
1 parent 89019cd commit 4ceb87e

File tree

4 files changed

+92
-5
lines changed

4 files changed

+92
-5
lines changed

test/components/views/settings/devices/DeviceDetails-test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ describe('<DeviceDetails />', () => {
5151
display_name: 'My Device',
5252
last_seen_ip: '123.456.789',
5353
last_seen_ts: now - 60000000,
54+
clientName: 'Element Web',
5455
};
5556
const { container } = render(getComponent({ device }));
5657
expect(container).toMatchSnapshot();

test/components/views/settings/devices/__snapshots__/DeviceDetails-test.tsx.snap

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,32 @@ exports[`<DeviceDetails /> renders device with metadata 1`] = `
195195
</tr>
196196
</tbody>
197197
</table>
198+
<table
199+
class="mx_DeviceDetails_metadataTable"
200+
data-testid="device-detail-metadata-application"
201+
>
202+
<thead>
203+
<tr>
204+
<th>
205+
Application
206+
</th>
207+
</tr>
208+
</thead>
209+
<tbody>
210+
<tr>
211+
<td
212+
class="mxDeviceDetails_metadataLabel"
213+
>
214+
Name
215+
</td>
216+
<td
217+
class="mxDeviceDetails_metadataValue"
218+
>
219+
Element Web
220+
</td>
221+
</tr>
222+
</tbody>
223+
</table>
198224
<table
199225
class="mx_DeviceDetails_metadataTable"
200226
data-testid="device-detail-metadata-device"

test/components/views/settings/tabs/user/SessionManagerTab-test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,10 @@ describe('<SessionManagerTab />', () => {
173173
mockClient.getDevices.mockResolvedValue({ devices: [alicesDevice, alicesMobileDevice] });
174174
mockClient.getAccountData.mockImplementation((eventType: string) => {
175175
const content = {
176-
name: 'Element Web',
177-
version: '1.2.3',
178-
url: 'test.com',
179-
};
176+
name: 'Element Web',
177+
version: '1.2.3',
178+
url: 'test.com',
179+
};
180180
return new MatrixEvent({
181181
type: eventType,
182182
content,

test/utils/device/clientInformation-test.ts

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17+
import { MatrixEvent } from "matrix-js-sdk/src/matrix";
18+
1719
import BasePlatform from "../../../src/BasePlatform";
1820
import { IConfigOptions } from "../../../src/IConfigOptions";
19-
import { recordClientInformation } from "../../../src/utils/device/clientInformation";
21+
import {
22+
getDeviceClientInformation,
23+
recordClientInformation,
24+
} from "../../../src/utils/device/clientInformation";
2025
import { getMockClientWithEventEmitter } from "../../test-utils";
2126

2227
describe('recordClientInformation()', () => {
@@ -84,3 +89,58 @@ describe('recordClientInformation()', () => {
8489
);
8590
});
8691
});
92+
93+
describe('getDeviceClientInformation()', () => {
94+
const deviceId = 'my-device-id';
95+
96+
const mockClient = getMockClientWithEventEmitter({
97+
getAccountData: jest.fn(),
98+
});
99+
100+
beforeEach(() => {
101+
jest.resetAllMocks();
102+
});
103+
104+
it('returns an empty object when no event exists for the device', () => {
105+
expect(getDeviceClientInformation(mockClient, deviceId)).toEqual({});
106+
107+
expect(mockClient.getAccountData).toHaveBeenCalledWith(
108+
`io.element.matrix-client-information.${deviceId}`,
109+
);
110+
});
111+
112+
it('returns client information for the device', () => {
113+
const eventContent = {
114+
name: 'Element Web',
115+
version: '1.2.3',
116+
url: 'test.com',
117+
};
118+
const event = new MatrixEvent({
119+
type: `io.element.matrix-client-information.${deviceId}`,
120+
content: eventContent,
121+
});
122+
mockClient.getAccountData.mockReturnValue(event);
123+
expect(getDeviceClientInformation(mockClient, deviceId)).toEqual(eventContent);
124+
});
125+
126+
it('excludes values with incorrect types', () => {
127+
const eventContent = {
128+
extraField: 'hello',
129+
name: 'Element Web',
130+
// wrong format
131+
version: { value: '1.2.3' },
132+
url: 'test.com',
133+
};
134+
const event = new MatrixEvent({
135+
type: `io.element.matrix-client-information.${deviceId}`,
136+
content: eventContent,
137+
});
138+
mockClient.getAccountData.mockReturnValue(event);
139+
// invalid fields excluded
140+
expect(getDeviceClientInformation(mockClient, deviceId)).toEqual({
141+
name: eventContent.name,
142+
url: eventContent.url,
143+
});
144+
});
145+
});
146+

0 commit comments

Comments
 (0)