Skip to content

Commit

Permalink
ci(linter): fix linter issues to pass the CI (empathyco#1606)
Browse files Browse the repository at this point in the history
  • Loading branch information
joseacabaneros authored Sep 3, 2024
1 parent b3cc3f5 commit aff3151
Show file tree
Hide file tree
Showing 42 changed files with 215 additions and 296 deletions.
13 changes: 11 additions & 2 deletions packages/x-components/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
module.exports = {
extends: ['plugin:@empathyco/x/all'],
ignorePatterns: ['cypress.config.ts'],
// TODO - Reactivate linter for unit and e2e tests once they pass.
ignorePatterns: [
'cypress.config.ts',
'**/__tests__/**/*.spec.ts',
'**/tests/**/*.spec.ts',
'**/__tests__/**/utils.ts',
'**/tests/**/utils.ts'
],
parserOptions: {
tsconfigRootDir: __dirname,
project: 'tsconfig.eslint.json'
},
rules: {
'no-dupe-class-members': 'off',
'@typescript-eslint/no-unused-vars-experimental': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'vue/require-default-prop': 'off',
'@typescript-eslint/explicit-function-return-type': 'off'
'vue/multi-word-component-names': 'off',
'vue/no-v-for-template-key': 'off'
},
overrides: [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { mount, VueWrapper } from '@vue/test-utils';
import { mount } from '@vue/test-utils';
import { defineComponent, inject } from 'vue';
import { FeatureLocation } from '../../types';
import LocationProvider from '../location-provider.vue';

const Child = defineComponent({
name: 'Child',
template: `{{ injectedLocation }}`,
setup() {
const injectedLocation = inject<FeatureLocation>('location');
return { injectedLocation };
}
name: 'ChildItem',
setup: () => ({ injectedLocation: inject<FeatureLocation>('location') }),
template: `{{ injectedLocation }}`
});

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { mount, VueWrapper } from '@vue/test-utils';
import { mount } from '@vue/test-utils';
import { baseSnippetConfig } from '../../views/base-config';
import { XEventListeners } from '../../x-installer/api/api.types';
import SnippetCallbacks from '../snippet-callbacks.vue';
import { bus } from '../../plugins/x-bus';
import { dummyCreateEmitter } from '../../__tests__/bus.dummy';

// Making bus not repeat subjects
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
jest.spyOn(bus, 'createEmitter' as any).mockImplementation(dummyCreateEmitter.bind(bus) as any);

function renderSnippetCallbacks({
callbacks = {}
}: RenderSnippetCallbacksOptions = {}): RenderSnippetCallbacksAPI {
function renderSnippetCallbacks({ callbacks = {} } = {}) {
const wrapper = mount(SnippetCallbacks, {
global: {
provide: {
Expand Down Expand Up @@ -95,19 +93,3 @@ describe('testing SnippetCallbacks component', () => {
});
});
});

/**
* Options to configure how the snippet callbacks component should be rendered.
*/
interface RenderSnippetCallbacksOptions {
/** The callbacks value to be provided. */
callbacks?: XEventListeners;
}

/**
* Tools to test how the snippet callbacks component behaves.
*/
interface RenderSnippetCallbacksAPI {
/** The wrapper of the container element. */
wrapper: VueWrapper;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { mount } from '@vue/test-utils';
import { defineComponent, provide, ref, h, Transition } from 'vue';
import { defineComponent, provide, ref, h, TransitionGroup } from 'vue';
import { DISABLE_ANIMATIONS_KEY } from '../../decorators/injection.consts';
import { useDisableAnimation } from '../use-disable-animation';
import { TransitionGroup } from 'vue';

// eslint-disable-next-line vue/one-component-per-file
const Provider = defineComponent({
props: {
disableAnimation: Boolean
Expand All @@ -13,30 +14,27 @@ const Provider = defineComponent({
}
});

// eslint-disable-next-line vue/one-component-per-file
const Animation = defineComponent({
setup() {
return useDisableAnimation('x-animation');
},
template: `
<transition-group :name="name">
<TransitionGroup :name="name">
<p>Animation</p>
</transition-group>
</TransitionGroup>
`
});

function renderDisableAnimation({ disableAnimation = true }: DisableAnimationOptions = {}) {
function renderDisableAnimation({ disableAnimation = true } = {}) {
const wrapper = mount({
template: `
<Provider :disableAnimation="disableAnimation">
<Animation/>
</Provider>
`,
<Provider :disableAnimation="disableAnimation">
<Animation/>
</Provider>
`,
components: { Provider, Animation },
data() {
return {
disableAnimation
};
}
data: () => ({ disableAnimation })
});

return {
Expand All @@ -58,7 +56,3 @@ describe('testing disable animation', () => {
expect(transitionGroup.attributes('name')).toBe('x-animation');
});
});

interface DisableAnimationOptions {
disableAnimation?: boolean;
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { DOMWrapper, mount, VueWrapper } from '@vue/test-utils';
import { nextTick } from 'vue';
import { getDataTestSelector, installNewXPlugin } from '../../../__tests__/utils';
import BaseEventsModal from '../base-events-modal.vue';
import { PropsWithType } from '../../../utils/types';
import { XEventsTypes, XEvent } from '../../../wiring/events.types';
import { XPlugin } from '../../../plugins/index';
import { nextTick } from 'vue';
import { XPlugin } from '../../../plugins';

/**
* Mounts a {@link BaseEventsModal} component with the provided options and offers an API to easily
* test it.
Expand Down Expand Up @@ -108,7 +109,7 @@ describe('testing Base Events Modal component', () => {
it('allows to customize the events listened for opening & closing', async () => {
const eventToOpen = 'UserFocusedSearchBox';
const eventToClose = 'UserPressedClearSearchBoxButton';
const { emit, getModalContent, wrapper } = mountBaseEventsModal({
const { emit, getModalContent } = mountBaseEventsModal({
eventsToOpenModal: [eventToOpen],
eventsToCloseModal: [eventToClose]
});
Expand All @@ -129,7 +130,7 @@ describe('testing Base Events Modal component', () => {

it('allows to customize the event emitted when clicking out of the modal', async () => {
const bodyClickEvent = 'UserClickedASimpleFilter';
const { wrapper, clickModalOverlay, emit, getModalContent } = mountBaseEventsModal({
const { clickModalOverlay, emit, getModalContent } = mountBaseEventsModal({
bodyClickEvent,
eventsToCloseModal: [bodyClickEvent]
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { mount, VueWrapper } from '@vue/test-utils';
import { defineComponent } from 'vue';
import { getDataTestSelector, installNewXPlugin } from '../../../__tests__/utils';
import BaseIdModalClose from '../base-id-modal-close.vue';
import { XPlugin } from '../../../plugins/index';
import { defineComponent } from 'vue';

/**
* Renders the {@link BaseIdModalClose} with the provided options.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mount, VueWrapper } from '@vue/test-utils';
import { mount } from '@vue/test-utils';
import { getDataTestSelector, installNewXPlugin } from '../../../__tests__/utils';
import BaseIdModalOpen from '../base-id-modal-open.vue';
import { bus } from '../../../plugins/x-bus';
Expand All @@ -12,34 +12,31 @@ import { XPlugin } from '../../../plugins/index';
* @returns An small API to test the component.
*/
function renderBaseIdModalOpen({
id = 'myModal',
template = `<BaseIdModalOpen modalId="${id}" v-bind="$attrs"/>`
}: RenderBaseIdModalOpenOptions = {}): RenderBaseIdModalOpenAPI {
template = `<BaseIdModalOpen :modalId="modalId" v-bind="$attrs"/>`
} = {}) {
// Making bus not repeat subjects
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
jest.spyOn(bus, 'createEmitter' as any).mockImplementation(dummyCreateEmitter.bind(bus) as any);

const modalId = 'myModal';

const containerWrapper = mount(
{
components: {
BaseIdModalOpen
},
components: { BaseIdModalOpen },
template
},
{
props: { modalId: id },
props: { modalId },
global: { plugins: [installNewXPlugin()] }
}
);

const wrapper = containerWrapper.findComponent(BaseIdModalOpen);
const modalId = wrapper.props('modalId');

return {
wrapper,
modalId,
async click() {
await wrapper.trigger('click');
}
click: async () => await wrapper.trigger('click')
};
}

Expand All @@ -63,16 +60,16 @@ describe('testing Open Button component', () => {
expect(wrapper.text()).toEqual('Open');
});

// eslint-disable-next-line max-len
it('renders custom content replacing the default exposing the function that opens the modal', async () => {
const { wrapper, click, modalId } = renderBaseIdModalOpen({
template: `<BaseIdModalOpen modalId="modal" v-bind="$attrs">
<template #opening-element="{ openModal }">
<div>
Open <span data-test="custom-open-modal" @click="openModal">HERE</span>
</div>
</template>
</BaseIdModalOpen>`
template: `
<BaseIdModalOpen modalId="modal" v-bind="$attrs">
<template #opening-element="{ openModal }">
<div>
Open <span data-test="custom-open-modal" @click="openModal">HERE</span>
</div>
</template>
</BaseIdModalOpen>`
});

const listener = jest.fn();
Expand All @@ -82,25 +79,9 @@ describe('testing Open Button component', () => {

expect(listener).toHaveBeenCalledTimes(0);

wrapper.find(getDataTestSelector('custom-open-modal')).trigger('click');
await wrapper.find(getDataTestSelector('custom-open-modal')).trigger('click');

expect(listener).toHaveBeenCalledTimes(1);
expect(listener).toHaveBeenCalledWith(modalId);
});
});

interface RenderBaseIdModalOpenOptions {
/** The id of the modal to open. */
id?: string;
/** The template to render. */
template?: string;
}

interface RenderBaseIdModalOpenAPI {
/** The wrapper for the modal component. */
wrapper: VueWrapper;
/** The modal id. */
modalId: string;
/** Clicks the button. */
click: () => Promise<void>;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DOMWrapper, mount, VueWrapper } from '@vue/test-utils';
import Vue, { nextTick } from 'vue';
import { nextTick } from 'vue';
import { getDataTestSelector, installNewXPlugin } from '../../../__tests__/utils';
import { XEvent } from '../../../wiring/events.types';
import BaseIdModal from '../base-id-modal.vue';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { mount, VueWrapper } from '@vue/test-utils';
import Vue, { defineComponent } from 'vue';
import { defineComponent } from 'vue';
import { AnyFunction } from '@empathyco/x-utils';
import { installNewXPlugin } from '../../../__tests__/utils';
import CloseMainModal from '../close-main-modal.vue';
Expand All @@ -19,25 +19,22 @@ function renderCloseMainModal({
components: {
CloseMainModal
},

template,
methods
methods,
template
});
const wrapper = mount(containerWrapper, {
global: { plugins: [installNewXPlugin()] }
});

return {
wrapper: wrapper.findComponent(CloseMainModal),
async click() {
await wrapper.trigger('click');
}
click: async () => await wrapper.trigger('click')
};
}

describe('testing Close Main Modal button component', () => {
it('emits UserClickedCloseX by default when clicked', async () => {
const { wrapper, click } = renderCloseMainModal();
const { click } = renderCloseMainModal();
const onUserClickedCloseX = jest.fn();
XPlugin.bus.on('UserClickedCloseX').subscribe(onUserClickedCloseX);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { DOMWrapper, mount, VueWrapper } from '@vue/test-utils';
import { defineComponent, nextTick } from 'vue';
import { getDataTestSelector, installNewXPlugin } from '../../../__tests__/utils';
import MainModal from '../main-modal.vue';
import { PropsWithType } from '../../../utils/types';
import { XEventsTypes } from '../../../wiring/events.types';
import { XPlugin } from '../../../plugins/index';
import { defineComponent, nextTick } from 'vue';
import { XEventsTypes } from '../../../wiring';
import { XPlugin } from '../../../plugins';

/**
* Renders a {@link MainModal} component with the provided options and offers an API to easily
* test it.
Expand All @@ -24,7 +25,6 @@ function renderMainModal({

template,
global: { plugins: [installNewXPlugin()] },

attachTo: parent // necessary to make the focus on body event to work in some environments.
});
const wrapper = mount(containerWrapper, {
Expand All @@ -37,7 +37,7 @@ function renderMainModal({
await wrapper.find(getDataTestSelector('modal-overlay'))?.trigger('click');
},
async emit(event) {
XPlugin.bus.emit(event);
await XPlugin.bus.emit(event);
await nextTick();
},
getModalContent() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { mount, VueWrapper } from '@vue/test-utils';
import Vue, { defineComponent } from 'vue';
import { defineComponent } from 'vue';
import { AnyFunction } from '@empathyco/x-utils';
import { installNewXPlugin } from '../../../__tests__/utils';
import OpenMainModal from '../open-main-modal.vue';
Expand All @@ -19,8 +19,8 @@ function renderOpenMainModal({
components: {
OpenMainModal
},
template,
methods
methods,
template
});

const wrapper = mount(containerWrapper, {
Expand All @@ -37,7 +37,7 @@ function renderOpenMainModal({

describe('testing Open Main Modal button component', () => {
it('emits UserClickedOpenX by default when clicked', async () => {
const { wrapper, click } = renderOpenMainModal();
const { click } = renderOpenMainModal();
const onUserClickedOpenX = jest.fn();
XPlugin.bus.on('UserClickedOpenX').subscribe(onUserClickedOpenX);

Expand Down
Loading

0 comments on commit aff3151

Please sign in to comment.