import * as React from 'react';
import UserMenu from '../UserMenu';
import {act, fireEvent, render} from '../../../test-utils';
import {ProfileMenu} from '../../types';
import {ProfileButtonContainer} from '../../../ProfileButton/ProfileButton';
import { NavigationProvider } from '../../../Navigation/NavigationProvider';
describe('UserMenu', () => {
const navProps = {
currentPath: '',
isActiveRoute: () => false,
navigate: (path: string, isExternal: boolean) => {}
};
it('should render profile icon', function () {
const props: ProfileMenu = {
user: {
firstName: 'John',
lastName: 'Doe',
email: 'email'
},
sections: []
}
const wrapper = render();
expect(wrapper.container.querySelectorAll(`${ProfileButtonContainer}`)).toHaveLength(1);
wrapper.unmount();
});
it('should render label', function () {
const props: ProfileMenu = {
user: {
firstName: 'John',
lastName: 'Doe',
email: 'email'
},
sections: [],
label: 'label'
}
const wrapper = render();
expect(wrapper.findByText('label')).toBeDefined();
wrapper.unmount();
});
it('should render sign out button', function () {
const props: ProfileMenu = {
user: {
firstName: 'John',
lastName: 'Doe',
email: 'email'
},
sections: [],
signOut: {
action: jest.fn(),
label: 'sign out'
}
}
const wrapper = render();
expect(wrapper.findByText('sign out')).toBeDefined();
wrapper.unmount();
});
it('should render sections', function () {
const props: ProfileMenu = {
user: {
firstName: 'John',
lastName: 'Doe',
email: 'email'
},
sections: [{
label: 'label',
items: [{
label: 'item1',
to: '#'
}]
}],
}
const wrapper = render(
);
expect(wrapper.getByText('item1')).toBeDefined();
expect(wrapper.getByText('label')).toBeDefined();
wrapper.unmount();
});
it('should close when item is clicked', async function () {
const props: ProfileMenu = {
user: {
firstName: 'John',
lastName: 'Doe',
email: 'email'
},
sections: [{
label: 'label',
items: [{
label: 'item1',
to: 'http://localhost',
external: true
}]
}],
};
const onClose = jest.fn();
const wrapper = render( );
act(() => {
fireEvent.click(wrapper.getByText('item1'));
})
expect(onClose).toHaveBeenCalled();
wrapper.unmount();
});
});