Skip to content

Open-source live-chat, email support, omni-channel desk. An alternative to Intercom, Zendesk, Salesforce Service Cloud etc. 🔥💬

2.1 KB
Raw Blame
import { shallowMount } from '@vue/test-utils';

import Signup from './Index.vue';
import SignupForm from './components/Signup/Form.vue';

vi.mock('vuex', () => ({
  useStore: () => ({
    getters: {
      'globalConfig/get': {
        installationName: 'Chatwoot',
        logo: '/logo.svg',
        logoDark: '/logo-dark.svg',
      },
    },
  }),
}));
vi.mock('shared/composables/useBranding', () => ({
  useBranding: () => ({
    replaceInstallationName: text => text.replace(/chatwoot/gi, 'Acme'),
  }),
}));

const mountComponent = props =>
  shallowMount(Signup, {
    props,
    global: {
      mocks: {
        $t: key => {
          const translations = {
            'REGISTER.SHOPIFY.TITLE': 'Set up Chatwoot for your Shopify store',
            'REGISTER.SHOPIFY.DESCRIPTION':
              'Create your Chatwoot account to continue.',
          };
          return translations[key] || key;
        },
      },
      stubs: {
        RouterLink: {
          template: '<a><slot /></a>',
        },
      },
    },
  });

describe('Shopify signup', () => {
  it('passes the pending install token to the signup form', () => {
    const pendingInstallToken = 'a'.repeat(32);
    const wrapper = mountComponent({
      shopifyPendingInstall: pendingInstallToken,
    });

    expect(
      wrapper.findComponent(SignupForm).props('shopifyPendingInstall')
    ).toBe(pendingInstallToken);
    expect(wrapper.text()).toContain('Set up Acme for your Shopify store');
    expect(wrapper.text()).toContain('Create your Acme account to continue.');
    expect(wrapper.text()).not.toContain('Chatwoot');
    expect(wrapper.vm.loginRoute).toEqual({
      name: 'login',
      query: {
        redirect_url: `settings/integrations/shopify?shopify_pending_install=${pendingInstallToken}`,
      },
    });
    expect(wrapper.find('a').exists()).toBe(true);
  });

  it('preserves the regular signup experience without a token', () => {
    const wrapper = mountComponent({});

    expect(
      wrapper.findComponent(SignupForm).props('shopifyPendingInstall')
    ).toBe('');
    expect(wrapper.text()).toContain('REGISTER.GET_STARTED');
    expect(wrapper.find('a').exists()).toBe(true);
  });
});