baby_in_magento

vrvr

Apr 12th, 2024
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. import React from 'react';
  2. import { createTestInstance } from '@magento/peregrine';
  3. import { useAccountMenuItems } from '@magento/peregrine/lib/talons/AccountMenu/useAccountMenuItems';
  4.  
  5. import AccountMenuItems from '../accountMenuItems';
  6.  
  7. jest.mock('react-router-dom', () => ({
  8. Link: children => `<Link>${children.children}</Link>`
  9. }));
  10. jest.mock(
  11. '@magento/peregrine/lib/talons/AccountMenu/useAccountMenuItems',
  12. () => {
  13. return {
  14. useAccountMenuItems: jest.fn()
  15. };
  16. }
  17. );
  18.  
  19. const props = {
  20. onSignOut: jest.fn().mockName('onSignOut')
  21. };
  22. const talonProps = {
  23. handleSignOut: jest.fn().mockName('handleSignOut'),
  24. menuItems: []
  25. };
  26.  
  27. test('it renders correctly', () => {
  28. // Arrange.
  29. const myTalonProps = {
  30. ...talonProps,
  31. menuItems: [
  32. {
  33. name: 'Order History',
  34. id: 'accountMenu.orderHistoryLink',
  35. url: '/order-history'
  36. },
  37. {
  38. name: 'Store Credit & Gift Cards',
  39. id: 'accountMenu.storeCreditLink',
  40. url: ''
  41. },
  42. {
  43. name: 'Favorites Lists',
  44. id: 'accountMenu.favoritesListsLink',
  45. url: '/wishlist'
  46. },
  47. {
  48. name: 'Address Book',
  49. id: 'accountMenu.addressBookLink',
  50. url: ''
  51. },
  52. {
  53. name: 'Saved Payments',
  54. id: 'accountMenu.savedPaymentsLink',
  55. url: ''
  56. },
  57. {
  58. name: 'Communications',
  59. id: 'accountMenu.communicationsLink',
  60. url: '/communications'
  61. },
  62. {
  63. name: 'Account Information',
  64. id: 'accountMenu.accountInfoLink',
  65. url: ''
  66. }
  67. ]
  68. };
  69. useAccountMenuItems.mockReturnValueOnce(myTalonProps);
  70.  
  71. // Act.
  72. const instance = createTestInstance(<AccountMenuItems {...props} />);
  73.  
  74. // Assert.
  75. expect(instance.toJSON()).toMatchSnapshot();
  76. });
  77.  
Advertisement
Add Comment
Please, Sign In to add comment