Guest User

Untitled

a guest
Dec 1st, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. import { mount, createLocalVue } from 'vue-test-utils';
  2. import Vuex from 'vuex';
  3. import { amw } from 'App/helpers/globals';
  4. import personalInformationModule from 'App/store/modules/personal-information';
  5. import communicationPreferencesModule from 'App/store/modules/communication-preferences';
  6. import { mockModules } from 'App/__test-utils__/helpers';
  7. import AmwCommunicationPreferencesPage from './communication-preferences.vue';
  8.  
  9. const localVue = createLocalVue();
  10.  
  11. jest.mock('App/helpers/globals', () => ({
  12. amw: {
  13. l10n: {},
  14. urls: {
  15. baseUrl: '/en/',
  16. },
  17. currency: {
  18. symbol: 'kr',
  19. },
  20. },
  21. ACC: {
  22. config: {
  23. amwayGlobalEndpoint: 'amwayGlobalEndpoint',
  24. },
  25. registrationVars: {},
  26. },
  27. }));
  28.  
  29. describe('AmwCommunicationPreferencesPage', () => {
  30. describe('login and communicational emails story', () => {
  31. let wrapper;
  32. let store;
  33. let mockedModules;
  34. let syncEmailCheckbox;
  35. let additionalEmailBlock;
  36. let editEmailsLinks;
  37.  
  38. const renderWrapper = (userLoginEmail, userCommunicationEmail) => {
  39. mockedModules = mockModules({
  40. personalInformationModule,
  41. communicationPreferencesModule,
  42. });
  43. mockedModules.communicationPreferencesModule.getters.emailLanguages.mockReturnValue([]);
  44. mockedModules.personalInformationModule.getters.getUserPersonalDetails.mockReturnValue({
  45. email: userCommunicationEmail || '',
  46. });
  47. mockedModules.personalInformationModule.getters.getUserLoginEmail.mockReturnValue(userLoginEmail || '');
  48.  
  49. store = new Vuex.Store({
  50. modules: mockedModules,
  51. });
  52.  
  53. localVue.use({
  54. install(V) {
  55. V.prototype.amw = amw;
  56. },
  57. });
  58. wrapper = mount(AmwCommunicationPreferencesPage, {
  59. localVue,
  60. store,
  61. });
  62. syncEmailCheckbox = wrapper.find('.aqa-sync-email-checkbox');
  63. additionalEmailBlock = wrapper.find('.aqa-additional-email-block');
  64. editEmailsLinks = wrapper.findAll('.aqa-email-can-change');
  65. };
  66.  
  67. afterEach(() => {
  68. wrapper.vm.$destroy();
  69. });
  70.  
  71. it('calls action to fetch email on mount', () => {
  72. renderWrapper();
  73. expect(mockedModules.personalInformationModule.actions.fetchUserLoginEmail).toBeCalled();
  74. });
  75.  
  76. describe('user have different emails for login & communication', () => {
  77. it('shows additional email block, emails possible to edit', () => {
  78. renderWrapper('test@email.com', 'test2@email.com');
  79. expect(additionalEmailBlock.element).toBeDefined();
  80. expect(editEmailsLinks.length).toBe(2);
  81. });
  82. });
  83.  
  84. describe('user have same email for login & communication', () => {
  85. it('do not show additional email block, cannot edit email', () => {
  86. renderWrapper('test@email.com', 'test@email.com');
  87. expect(additionalEmailBlock.element).not.toBeDefined();
  88. expect(editEmailsLinks.length).toBe(0);
  89. });
  90.  
  91. it('shows input for communication email if sync emails checkbox unclicked', async () => {
  92. // todo check email block
  93. renderWrapper('test@email.com', 'test@email.com');
  94. syncEmailCheckbox.trigger('click');
  95. expect(wrapper.vm.emailUnsyncProcess).toBe(true);
  96. });
  97. });
  98. });
  99. });
Add Comment
Please, Sign In to add comment