Skip to content

Commit

Permalink
Merge branch 'master' into corinagum/1742
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyanziano authored Sep 4, 2019
2 parents 275f9b7 + cc73e75 commit fb78b3c
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,23 @@ describe('<ChatContainer />', () => {
});
});

describe('activityWrapper', () => {
it('Should display the context menu for the activities in default mode', () => {
const dispatchSpy: jest.SpyInstance = jest.spyOn(mockStore, 'dispatch').mockReturnValue(true);
const next = () => (kids: any) => kids;
const card = { activity: { id: 'activity-id' } };
const children = 'a child node';
const webChat = render({} as any).find(ReactWebChat);
const middleware = webChat.prop('activityMiddleware') as any;
const activityWrapper = mount(middleware()(next)(card)(children));

// show context menu for activity
dispatchSpy.mockClear();
activityWrapper.simulate('contextmenu', { target: { tagName: 'DIV', classList: [] } });
expect(dispatchSpy).toHaveBeenCalledWith(showContextMenuForActivity(card.activity));
});
});

describe('activity middleware', () => {
it('renders an ActivityWrapper with the contents as children', () => {
const next = () => (kids: any) => kids;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export class Chat extends Component<ChatProps, ChatState> {
data-activity-id={card.activity.id}
onClick={this.onItemRendererClick}
onKeyDown={this.onItemRendererKeyDown}
onContextMenu={this.onContextMenu}
isSelected={this.shouldBeSelected(card.activity)}
>
{next(card)(children)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
import * as Electron from 'electron';
import {
CommandServiceImpl,
CommandServiceInstance,
Expand Down Expand Up @@ -89,6 +90,7 @@ jest.mock('electron', () => ({
},
}
),
clipboard: { writeText: (textFromActivity: string) => true },
}));

const mockState = {
Expand Down Expand Up @@ -506,5 +508,26 @@ describe('The Inspector component', () => {
);
});
});

describe('should handle the accessory Click event', () => {
let instance;
let event;

beforeEach(() => {
instance = node.instance();
event = { channel: '', currentTarget: { dataset: { currentState: 'default' }, name: '' } };
});

it('"when the copy json button is clicked"', () => {
const spy = jest.spyOn(instance, 'accessoryClick');
const clipboardSpy = jest.spyOn(Electron.clipboard, 'writeText');

event.channel = 'proxy';
event.currentTarget.name = 'copyJson';
instance.accessoryClick(event);
expect(spy).toHaveBeenCalledWith(event);
expect(clipboardSpy).toHaveBeenCalledWith(JSON.stringify(instance.state.inspectObj, null, 2));
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

// Cheating here and pulling in a module from node. Can be easily replaced if we ever move the emulator to the web.
// @ts-ignore
import { clipboard } from 'electron';
import {
EmulatorChannel,
ExtensionChannel,
Expand Down Expand Up @@ -365,6 +366,11 @@ export class Inspector extends React.Component<InspectorProps, InspectorState> {

private accessoryClick = (event: MouseEvent<HTMLButtonElement>): void => {
const id = event.currentTarget.name;

if (id == 'copyJson') {
return clipboard.writeText(JSON.stringify(this.state.inspectObj, null, 2));
}

const { currentState } = event.currentTarget.dataset;
this.sendToExtension(ExtensionChannel.AccessoryClick, id, currentState);
};
Expand Down
12 changes: 12 additions & 0 deletions packages/extensions/json/bf-extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@
"aria-disabled": true
}
}
},
{
"id": "copyJson",
"states": {
"default": {
"label": "Copy json"
},
"selected": {
"label": "Copy json",
"aria-selected": true
}
}
}
]
}
Expand Down

0 comments on commit fb78b3c

Please sign in to comment.