Device manager - New device tile info design (#9122)(PSG-637)

* redesign device tile info

* test DeviceTile except for broken date mocking

* mock dates the nice way, test lastactivity in device tile

* tweak spacing style

* update comment style in rethemendex

* i18n
This commit is contained in:
Kerry 2022-08-08 08:59:22 +02:00 committed by GitHub
parent 7eaed1a3f8
commit 94f3168ab8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 334 additions and 35 deletions

View file

@ -0,0 +1,107 @@
/*
Copyright 2022 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import React from 'react';
import { render } from '@testing-library/react';
import { IMyDevice } from 'matrix-js-sdk/src/matrix';
import DeviceTile from '../../../../../src/components/views/settings/devices/DeviceTile';
describe('<DeviceTile />', () => {
const defaultProps = {
device: {
device_id: '123',
},
};
const getComponent = (props = {}) => (
<DeviceTile {...defaultProps} {...props} />
);
// 14.03.2022 16:15
const now = 1647270879403;
jest.useFakeTimers();
beforeEach(() => {
jest.setSystemTime(now);
});
it('renders a device with no metadata', () => {
const { container } = render(getComponent());
expect(container).toMatchSnapshot();
});
it('renders display name with a tooltip', () => {
const device: IMyDevice = {
device_id: '123',
display_name: 'My device',
};
const { container } = render(getComponent({ device }));
expect(container).toMatchSnapshot();
});
it('renders last seen ip metadata', () => {
const device: IMyDevice = {
device_id: '123',
display_name: 'My device',
last_seen_ip: '1.2.3.4',
};
const { getByTestId } = render(getComponent({ device }));
expect(getByTestId('device-metadata-lastSeenIp').textContent).toEqual(device.last_seen_ip);
});
it('separates metadata with a dot', () => {
const device: IMyDevice = {
device_id: '123',
last_seen_ip: '1.2.3.4',
last_seen_ts: now - 60000,
};
const { container } = render(getComponent({ device }));
expect(container).toMatchSnapshot();
});
describe('Last activity', () => {
const MS_DAY = 24 * 60 * 60 * 1000;
it('renders with day of week and time when last activity is less than 6 days ago', () => {
const device: IMyDevice = {
device_id: '123',
last_seen_ip: '1.2.3.4',
last_seen_ts: now - (MS_DAY * 3),
};
const { getByTestId } = render(getComponent({ device }));
expect(getByTestId('device-metadata-lastActivity').textContent).toEqual('Last activity Fri 15:14');
});
it('renders with month and date when last activity is more than 6 days ago', () => {
const device: IMyDevice = {
device_id: '123',
last_seen_ip: '1.2.3.4',
last_seen_ts: now - (MS_DAY * 8),
};
const { getByTestId } = render(getComponent({ device }));
expect(getByTestId('device-metadata-lastActivity').textContent).toEqual('Last activity Mar 6');
});
it('renders with month, date, year when activity is in a different calendar year', () => {
const device: IMyDevice = {
device_id: '123',
last_seen_ip: '1.2.3.4',
last_seen_ts: new Date('2021-12-29').getTime(),
};
const { getByTestId } = render(getComponent({ device }));
expect(getByTestId('device-metadata-lastActivity').textContent).toEqual('Last activity Dec 29, 2021');
});
});
});

View file

@ -0,0 +1,93 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<DeviceTile /> renders a device with no metadata 1`] = `
<div>
<div
class="mx_DeviceTile"
>
<div
class="mx_DeviceTile_info"
>
<h4
class="mx_Heading_h4"
>
123
</h4>
<div
class="mx_DeviceTile_metadata"
>
·
</div>
</div>
<div
class="mx_DeviceTile_actions"
/>
</div>
</div>
`;
exports[`<DeviceTile /> renders display name with a tooltip 1`] = `
<div>
<div
class="mx_DeviceTile"
>
<div
class="mx_DeviceTile_info"
>
<div
tabindex="0"
>
<h4
class="mx_Heading_h4"
>
My device
</h4>
</div>
<div
class="mx_DeviceTile_metadata"
>
·
</div>
</div>
<div
class="mx_DeviceTile_actions"
/>
</div>
</div>
`;
exports[`<DeviceTile /> separates metadata with a dot 1`] = `
<div>
<div
class="mx_DeviceTile"
>
<div
class="mx_DeviceTile_info"
>
<h4
class="mx_Heading_h4"
>
123
</h4>
<div
class="mx_DeviceTile_metadata"
>
<span
data-testid="device-metadata-lastActivity"
>
Last activity 15:13
</span>
·
<span
data-testid="device-metadata-lastSeenIp"
>
1.2.3.4
</span>
</div>
</div>
<div
class="mx_DeviceTile_actions"
/>
</div>
</div>
`;