Skip to content

Commit

Permalink
tests: fixed tests after refactor [WTEL-3997]
Browse files Browse the repository at this point in the history
  • Loading branch information
dlohvinov committed Oct 26, 2023
1 parent f5c6286 commit 07e3b73
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 28 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Widget CI

on:
push:
branches: [ master ]
branches: [ main ]
pull_request:
branches: [ master ]
branches: [ main ]

jobs:
test:
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/__tests__/wt-omni-widget.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('WtOmniWidget Component', () => {
const wrapper = shallowMount(WtOmniWidget, {
computed,
});
wrapper.findComponent(WtOmniWidgetButtonsMenu).vm.$emit('open');
wrapper.findComponent(WtOmniWidgetButtonsMenu).vm.$emit('open', { channel: 'test' });
await wrapper.vm.$nextTick();
expect(wrapper.findComponent(WtOmniWidgetButtonsMenu).exists()).toBe(false);
expect(wrapper.findComponent(WtOmniWidgetWindow).isVisible()).toBe(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { shallowMount } from '@vue/test-utils';
import WtOmniWidgetButtonsMenu from '../wt-omni-widget-buttons-menu.vue';
import ChatChannel from '../../../enums/WidgetChannel.enum';
import AlternativeChannel from '../../../enums/AlternativeChannel.enum';
import WidgetChannel from '../../../enums/WidgetChannel.enum';

describe('WtOmniWidgetButtonsMenu', () => {
it('renders a component', () => {
Expand All @@ -18,7 +19,7 @@ describe('WtOmniWidgetButtonsMenu', () => {

it('correctly computes menu, processing urls: no "https" case', () => {
const alternativeChannels = {
[ChatChannel.VIBER]: 'viber://co',
[AlternativeChannel.VIBER]: 'viber://co',
};
const wrapper = shallowMount(WtOmniWidgetButtonsMenu, {
computed: {
Expand All @@ -27,12 +28,12 @@ describe('WtOmniWidgetButtonsMenu', () => {
},
},
});
expect(wrapper.vm.buttons).toEqual([{ type: ChatChannel.VIBER, url: 'viber://co' }]);
expect(wrapper.vm.buttons).toEqual([{ type: AlternativeChannel.VIBER, url: 'viber://co' }]);
});

it('correctly computes menu, processing urls: "https" case', () => {
const alternativeChannels = {
[ChatChannel.WHATSAPP]: 'https://whatsapp.co',
[AlternativeChannel.WHATSAPP]: 'https://whatsapp.co',
};
const wrapper = shallowMount(WtOmniWidgetButtonsMenu, {
computed: {
Expand All @@ -41,12 +42,12 @@ describe('WtOmniWidgetButtonsMenu', () => {
},
},
});
expect(wrapper.vm.buttons).toEqual([{type: ChatChannel.WHATSAPP, url: 'https://whatsapp.co' }]);
expect(wrapper.vm.buttons).toEqual([{type: AlternativeChannel.WHATSAPP, url: 'https://whatsapp.co' }]);
});

it('correctly computes menu, processing urls: no "mailto:" email case', () => {
const alternativeChannels = {
[ChatChannel.EMAIL]: '[email protected]',
[AlternativeChannel.EMAIL]: '[email protected]',
};
const wrapper = shallowMount(WtOmniWidgetButtonsMenu, {
computed: {
Expand All @@ -55,7 +56,7 @@ describe('WtOmniWidgetButtonsMenu', () => {
},
},
});
expect(wrapper.vm.buttons).toEqual([{ type: ChatChannel.EMAIL, url: 'mailto:[email protected]' }]);
expect(wrapper.vm.buttons).toEqual([{ type: AlternativeChannel.EMAIL, url: 'mailto:[email protected]' }]);
});

it('correctly computes menu, processing urls: "mailto:" email case', () => {
Expand Down Expand Up @@ -83,7 +84,7 @@ describe('WtOmniWidgetButtonsMenu', () => {
},
});
wrapper.findAllComponents({ name: 'wt-omni-widget-button' })
.wrappers.find((wrapper) => wrapper.vm.$props.type === ChatChannel.CHAT)
.wrappers.find((wrapper) => wrapper.vm.$props.type === WidgetChannel.CHAT)
.vm.$emit('click');
expect(wrapper.emitted().open).toBeTruthy();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,11 @@ import { shallowMount } from '@vue/test-utils';
import WtOmniWidgetWindow from '../wt-omni-widget-window.vue';

describe('WtOmniWidgetWindow', () => {
const initializeSession = jest.fn();
const listenOnMessage = jest.fn();
const onMessage = jest.fn();

jest.spyOn(WtOmniWidgetWindow.methods, 'initializeSession')
.mockImplementation(initializeSession);
jest.spyOn(WtOmniWidgetWindow.methods, 'listenOnMessage')
.mockImplementation(listenOnMessage);
jest.spyOn(WtOmniWidgetWindow.methods, 'onMessage')
.mockImplementation(onMessage);

beforeEach(() => {
initializeSession.mockClear();
listenOnMessage.mockClear();
onMessage.mockClear();
});

it('renders a component', () => {
const wrapper = shallowMount(WtOmniWidgetWindow, {
propsData: {
channel: 'chat',
},
computed: {
config() {
return {
Expand All @@ -35,6 +21,9 @@ describe('WtOmniWidgetWindow', () => {

it('renders a component in preview mode', () => {
const wrapper = shallowMount(WtOmniWidgetWindow, {
propsData: {
channel: 'chat',
},
computed: {
config() {
return {
Expand Down

0 comments on commit 07e3b73

Please sign in to comment.