Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { mount, createLocalVue } from 'vue-test-utils';
- import Vuex from 'vuex';
- import { amw } from 'App/helpers/globals';
- import personalInformationModule from 'App/store/modules/personal-information';
- import communicationPreferencesModule from 'App/store/modules/communication-preferences';
- import { mockModules } from 'App/__test-utils__/helpers';
- import AmwCommunicationPreferencesPage from './communication-preferences.vue';
- const localVue = createLocalVue();
- jest.mock('App/helpers/globals', () => ({
- amw: {
- l10n: {},
- urls: {
- baseUrl: '/en/',
- },
- currency: {
- symbol: 'kr',
- },
- },
- ACC: {
- config: {
- amwayGlobalEndpoint: 'amwayGlobalEndpoint',
- },
- registrationVars: {},
- },
- }));
- describe('AmwCommunicationPreferencesPage', () => {
- describe('login and communicational emails story', () => {
- let wrapper;
- let store;
- let mockedModules;
- let syncEmailCheckbox;
- let additionalEmailBlock;
- let editEmailsLinks;
- const renderWrapper = (userLoginEmail, userCommunicationEmail) => {
- mockedModules = mockModules({
- personalInformationModule,
- communicationPreferencesModule,
- });
- mockedModules.communicationPreferencesModule.getters.emailLanguages.mockReturnValue([]);
- mockedModules.personalInformationModule.getters.getUserPersonalDetails.mockReturnValue({
- email: userCommunicationEmail || '',
- });
- mockedModules.personalInformationModule.getters.getUserLoginEmail.mockReturnValue(userLoginEmail || '');
- store = new Vuex.Store({
- modules: mockedModules,
- });
- localVue.use({
- install(V) {
- V.prototype.amw = amw;
- },
- });
- wrapper = mount(AmwCommunicationPreferencesPage, {
- localVue,
- store,
- });
- syncEmailCheckbox = wrapper.find('.aqa-sync-email-checkbox');
- additionalEmailBlock = wrapper.find('.aqa-additional-email-block');
- editEmailsLinks = wrapper.findAll('.aqa-email-can-change');
- };
- afterEach(() => {
- wrapper.vm.$destroy();
- });
- it('calls action to fetch email on mount', () => {
- renderWrapper();
- expect(mockedModules.personalInformationModule.actions.fetchUserLoginEmail).toBeCalled();
- });
- describe('user have different emails for login & communication', () => {
- it('shows additional email block, emails possible to edit', () => {
- renderWrapper('test@email.com', 'test2@email.com');
- expect(additionalEmailBlock.element).toBeDefined();
- expect(editEmailsLinks.length).toBe(2);
- });
- });
- describe('user have same email for login & communication', () => {
- it('do not show additional email block, cannot edit email', () => {
- renderWrapper('test@email.com', 'test@email.com');
- expect(additionalEmailBlock.element).not.toBeDefined();
- expect(editEmailsLinks.length).toBe(0);
- });
- it('shows input for communication email if sync emails checkbox unclicked', async () => {
- // todo check email block
- renderWrapper('test@email.com', 'test@email.com');
- syncEmailCheckbox.trigger('click');
- expect(wrapper.vm.emailUnsyncProcess).toBe(true);
- });
- });
- });
- });
Add Comment
Please, Sign In to add comment