Files
flipper/desktop/plugins/public/flipper-messages/__tests__/flipper_messages.node.tsx
Michel Weststrate 7e4df00138 Implement context menu
Summary:
Re-introduced context menu to DataTable, due to popular demand.

Originally it wasn't there to better align with ant design principles, but in an app like Flipper it makes just too much sense to have it

See e.g. https://fb.workplace.com/groups/flippersupport/permalink/1138285579985432/

changelog: Restored context menu in data tables

Reviewed By: passy

Differential Revision: D28996137

fbshipit-source-id: 16ef4c90997c9313efa62da7576fd453a7853761
2021-06-10 12:57:47 -07:00

162 lines
3.8 KiB
TypeScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
import {TestUtils} from 'flipper-plugin';
import * as Plugin from '../';
import {MessageRow} from '../';
const fixRowTimestamps = (r: MessageRow): MessageRow => ({
...r,
time: new Date(Date.UTC(0, 0, 0, 0, 0, 0)),
});
test('It can store rows', () => {
const {instance, ...plugin} = TestUtils.startPlugin(Plugin);
expect(instance.rows.records()).toEqual([]);
expect(instance.highlightedRow.get()).toBeUndefined();
plugin.sendEvent('newMessage', {
app: 'Flipper',
direction: 'toFlipper',
});
plugin.sendEvent('newMessage', {
app: 'FB4A',
direction: 'toClient',
device: 'Android Phone',
payload: {hello: 'world'},
});
expect(instance.rows.records().map(fixRowTimestamps)).toMatchInlineSnapshot(`
Array [
Object {
"app": "Flipper",
"direction": "toFlipper",
"time": 1899-12-31T00:00:00.000Z,
},
Object {
"app": "FB4A",
"device": "Android Phone",
"direction": "toClient",
"payload": Object {
"hello": "world",
},
"time": 1899-12-31T00:00:00.000Z,
},
]
`);
});
test('It can clear', () => {
const {instance, ...plugin} = TestUtils.startPlugin(Plugin);
expect(instance.rows.records()).toEqual([]);
expect(instance.highlightedRow.get()).toBeUndefined();
plugin.sendEvent('newMessage', {
app: 'Flipper',
direction: 'toFlipper',
});
instance.clear();
const newRows = instance.rows.records().map(fixRowTimestamps);
expect(newRows).toEqual([]);
});
test('It can highlight a row', () => {
const {instance, ...plugin} = TestUtils.startPlugin(Plugin);
plugin.sendEvent('newMessage', {
app: 'Flipper',
direction: 'toFlipper',
});
instance.setHighlightedRow(instance.rows.records()[0]);
expect(instance.rows.records()).toHaveLength(1);
expect(instance.highlightedRow.get()?.app).toEqual('Flipper');
});
test('It can render empty', async () => {
const {renderer} = TestUtils.renderPlugin(Plugin);
// Default message without any highlighted rows.
expect(
await renderer.findByText('Select a message to view details'),
).not.toBeNull();
});
test('It can render rows', async () => {
const {renderer, ...plugin} = TestUtils.renderPlugin(Plugin);
plugin.sendEvent('newMessage', {
time: new Date(0, 0, 0, 0, 0, 0),
app: 'Flipper',
direction: 'toFlipper',
});
plugin.sendEvent('newMessage', {
time: new Date(0, 0, 0, 0, 0, 0),
app: 'FB4A',
direction: 'toClient',
device: 'Android Phone',
flipperInternalMethod: 'unique-string',
payload: {hello: 'world'},
});
expect((await renderer.findByText('unique-string')).parentElement)
.toMatchInlineSnapshot(`
<div
class="ant-dropdown-trigger css-1k3kr6b-TableBodyRowContainer e1luu51r1"
>
<div
class="css-1vr131n-TableBodyColumnContainer e1luu51r0"
width="14%"
>
00:00:00.000
</div>
<div
class="css-1vr131n-TableBodyColumnContainer e1luu51r0"
width="14%"
>
Android Phone
</div>
<div
class="css-1vr131n-TableBodyColumnContainer e1luu51r0"
width="14%"
>
FB4A
</div>
<div
class="css-1vr131n-TableBodyColumnContainer e1luu51r0"
width="14%"
>
unique-string
</div>
<div
class="css-1vr131n-TableBodyColumnContainer e1luu51r0"
width="14%"
/>
<div
class="css-1vr131n-TableBodyColumnContainer e1luu51r0"
width="14%"
/>
<div
class="css-1vr131n-TableBodyColumnContainer e1luu51r0"
width="14%"
>
toClient
</div>
</div>
`);
});