2018-12-13 13:39:08 +05:30
|
|
|
import Vue from 'vue';
|
2020-04-22 19:07:51 +05:30
|
|
|
import mountComponent from 'helpers/vue_mount_component_helper';
|
2020-01-01 13:55:28 +05:30
|
|
|
import toggleRepliesWidget from '~/notes/components/toggle_replies_widget.vue';
|
2018-12-13 13:39:08 +05:30
|
|
|
import { note } from '../mock_data';
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
const deepCloneObject = (obj) => JSON.parse(JSON.stringify(obj));
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
|
|
describe('toggle replies widget for notes', () => {
|
|
|
|
let vm;
|
|
|
|
let ToggleRepliesWidget;
|
|
|
|
const noteFromOtherUser = deepCloneObject(note);
|
|
|
|
noteFromOtherUser.author.username = 'fatihacet';
|
|
|
|
|
|
|
|
const noteFromAnotherUser = deepCloneObject(note);
|
|
|
|
noteFromAnotherUser.author.username = 'mgreiling';
|
|
|
|
noteFromAnotherUser.author.name = 'Mike Greiling';
|
|
|
|
|
|
|
|
const replies = [note, note, note, noteFromOtherUser, noteFromAnotherUser];
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
ToggleRepliesWidget = Vue.extend(toggleRepliesWidget);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('collapsed state', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
vm = mountComponent(ToggleRepliesWidget, {
|
|
|
|
replies,
|
|
|
|
collapsed: true,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render the collapsed', () => {
|
|
|
|
const vmTextContent = vm.$el.textContent.replace(/\s\s+/g, ' ');
|
|
|
|
|
|
|
|
expect(vm.$el.classList.contains('collapsed')).toEqual(true);
|
|
|
|
expect(vm.$el.querySelectorAll('.user-avatar-link').length).toEqual(3);
|
|
|
|
expect(vm.$el.querySelector('time')).not.toBeNull();
|
|
|
|
expect(vmTextContent).toContain('5 replies');
|
|
|
|
expect(vmTextContent).toContain(`Last reply by ${noteFromAnotherUser.author.name}`);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should emit toggle event when the replies text clicked', () => {
|
2020-04-22 19:07:51 +05:30
|
|
|
const spy = jest.spyOn(vm, '$emit');
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
|
|
vm.$el.querySelector('.js-replies-text').click();
|
|
|
|
|
|
|
|
expect(spy).toHaveBeenCalledWith('toggle');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('expanded state', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
vm = mountComponent(ToggleRepliesWidget, {
|
|
|
|
replies,
|
|
|
|
collapsed: false,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render expanded state', () => {
|
|
|
|
const vmTextContent = vm.$el.textContent.replace(/\s\s+/g, ' ');
|
|
|
|
|
|
|
|
expect(vm.$el.querySelector('.collapse-replies-btn')).not.toBeNull();
|
|
|
|
expect(vmTextContent).toContain('Collapse replies');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should emit toggle event when the collapse replies text called', () => {
|
2020-04-22 19:07:51 +05:30
|
|
|
const spy = jest.spyOn(vm, '$emit');
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
|
|
vm.$el.querySelector('.js-collapse-replies').click();
|
|
|
|
|
|
|
|
expect(spy).toHaveBeenCalledWith('toggle');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|