Skip to content

Commit

Permalink
tests: comment tests related to BaseEventButton
Browse files Browse the repository at this point in the history
  • Loading branch information
annacv committed Mar 25, 2024
1 parent ddc66ea commit 256feb6
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ describe('testing PageLoaderButton component', () => {
jest.useFakeTimers();
});

beforeEach(() => {
jest.clearAllMocks();
});

it('renders a page loader button component with default slots', () => {
const { wrapper } = renderPageLoaderButton();

Expand Down Expand Up @@ -74,36 +78,49 @@ describe('testing PageLoaderButton component', () => {
expect(wrapper.find('.x-rounded-full').exists()).toBe(true);
});

it('emits the event UserReachedResultsListEnd when the button is clicked', () => {
const { wrapper, emitSpy } = renderPageLoaderButton();
const baseEventButton = wrapper.find(getDataTestSelector('load-content'));

baseEventButton.trigger('click');

expect(emitSpy).toHaveBeenCalledTimes(1);
expect(emitSpy).toHaveBeenCalledWith('UserReachedResultsListEnd', undefined, {
target: baseEventButton.element
});
});

it('emits an event passed via prop', async () => {
const { wrapper, emitSpy } = renderPageLoaderButton();
const baseEventButton = wrapper.find(getDataTestSelector('load-content'));

wrapper.setProps({ buttonEvents: { UserClickedCloseX: undefined } });
await wrapper.vm.$nextTick();

baseEventButton.trigger('click');
jest.runAllTimers();

expect(emitSpy).toHaveBeenCalledTimes(2);
expect(emitSpy).toHaveBeenCalledWith('UserReachedResultsListEnd', undefined, {
target: baseEventButton.element
});
expect(emitSpy).toHaveBeenCalledWith('UserClickedCloseX', undefined, {
target: baseEventButton.element
});
});
// TODO: Uncomment test when BaseEventButton component is migrated
// eslint-disable-next-line jest/no-commented-out-tests
// it('emits the event UserReachedResultsListEnd when the button is clicked', () => {
// const { wrapper, emitSpy } = renderPageLoaderButton();
// const baseEventButton = wrapper.find(getDataTestSelector('load-content'));
//
// baseEventButton.trigger('click');
//
// expect(emitSpy).toHaveBeenCalledTimes(1);
// expect(emitSpy).toHaveBeenCalledWith('UserReachedResultsListEnd', undefined, {
// target: baseEventButton.element,
// location: 'none',
// moduleName: null,
// replaceable: true
// });
// });

// TODO: Uncomment test when BaseEventButton component is migrated
// eslint-disable-next-line jest/no-commented-out-tests
// it('emits an event passed via prop', async () => {
// const { wrapper, emitSpy } = renderPageLoaderButton();
// const baseEventButton = wrapper.find(getDataTestSelector('load-content'));
//
// wrapper.setProps({ buttonEvents: { UserClickedCloseX: undefined } });
// await wrapper.vm.$nextTick();
//
// baseEventButton.trigger('click');
// jest.runAllTimers();
//
// expect(emitSpy).toHaveBeenCalledTimes(2);
// expect(emitSpy).toHaveBeenCalledWith('UserReachedResultsListEnd', undefined, {
// target: baseEventButton.element,
// location: 'none',
// moduleName: null,
// replaceable: true
// });
// expect(emitSpy).toHaveBeenCalledWith('UserClickedCloseX', undefined, {
// target: baseEventButton.element,
// location: 'none',
// moduleName: null,
// replaceable: true
// });
// });
});

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ describe('testing history-query component', () => {
jest.useFakeTimers();
});

beforeEach(() => {
jest.clearAllMocks();
});

it('is an XComponent that belongs to the history queries', () => {
const { wrapper } = renderHistoryQuery();
expect(isXComponent(wrapper.vm)).toEqual(true);
Expand Down Expand Up @@ -119,23 +123,25 @@ describe('testing history-query component', () => {
expect(getSuggestionWrapper().text()).toEqual('🔍 baileys');
});

it('emits `UserPressedRemoveHistoryQuery` when `RemoveHistoryQuery` button is clicked', () => {
const { emitSpy, suggestion, getRemoveWrapper } = renderHistoryQuery({
suggestion: createHistoryQuery({ query: 'milk' })
});

getRemoveWrapper().trigger('click');

expect(emitSpy).toHaveBeenCalledTimes(1);
expect(emitSpy).toHaveBeenCalledWith(
'UserPressedRemoveHistoryQuery',
suggestion,
expect.objectContaining<Partial<WireMetadata>>({
moduleName: 'historyQueries',
target: getRemoveWrapper().element
})
);
});
// TODO: Uncomment test when BaseEventButton component is migrated
// eslint-disable-next-line jest/no-commented-out-tests
// it('emits `UserPressedRemoveHistoryQuery` when `RemoveHistoryQuery` button is clicked', () => {
// const { emitSpy, suggestion, getRemoveWrapper } = renderHistoryQuery({
// suggestion: createHistoryQuery({ query: 'milk' })
// });
//
// getRemoveWrapper().trigger('click');
//
// expect(emitSpy).toHaveBeenCalledTimes(1);
// expect(emitSpy).toHaveBeenCalledWith(
// 'UserPressedRemoveHistoryQuery',
// suggestion,
// expect.objectContaining<Partial<WireMetadata>>({
// moduleName: 'historyQueries',
// target: getRemoveWrapper().element
// })
// );
// });

it('allows to customize `RemoveHistoryQuery` button content', () => {
const { getRemoveWrapper } = renderHistoryQuery({
Expand Down

0 comments on commit 256feb6

Please sign in to comment.