diff --git a/frontend/src/components/DecayInformations/CollapseLinksList.spec.js b/frontend/src/components/DecayInformations/CollapseLinksList.spec.js new file mode 100644 index 000000000..5407df2fe --- /dev/null +++ b/frontend/src/components/DecayInformations/CollapseLinksList.spec.js @@ -0,0 +1,112 @@ +import { mount } from '@vue/test-utils' +import CollapseLinksList from './CollapseLinksList' + +const localVue = global.localVue + +const mocks = { + $i18n: { + locale: 'en', + }, + $tc: jest.fn((tc) => tc), + $t: jest.fn((t) => t), +} + +const propsData = { + transactionLinks: [ + { + amount: '5', + code: 'ce28664b5308c17f931c0367', + createdAt: '2022-03-16T14:22:40.000Z', + holdAvailableAmount: '5.13109484759482747111', + id: 87, + memo: 'asdasdaadsdd asd asdadss', + redeemedAt: null, + validUntil: '2022-03-30T14:22:40.000Z', + }, + ], + transactionLinkCount: 3, + value: { currentPage: 1, pending: false, pageSize: 5, itemsShown: 0 }, +} + +describe('CollapseLinksList', () => { + let wrapper + + const Wrapper = () => { + return mount(CollapseLinksList, { localVue, mocks, propsData }) + } + describe('mount', () => { + beforeEach(() => { + wrapper = Wrapper() + }) + + it('renders the component div.collapse-links-list', () => { + expect(wrapper.find('div.collapse-links-list').exists()).toBeTruthy() + }) + + describe('load more links', () => { + beforeEach(async () => { + await wrapper.find('button.test-button-load-more').trigger('click') + }) + + it('emits input', () => { + expect(wrapper.emitted('input')).toEqual([ + [{ currentPage: 2, itemsShown: 0, pageSize: 5, pending: false }], + ]) + }) + }) + + describe('reset transaction link list', () => { + beforeEach(async () => { + await wrapper + .findComponent({ name: 'TransactionLink' }) + .vm.$emit('reset-transaction-link-list') + }) + + it('emits input ', () => { + expect(wrapper.emitted('input')).toEqual([ + [{ currentPage: 0, itemsShown: 0, pageSize: 5, pending: false }], + ]) + }) + }) + + describe('button text', () => { + describe('one more link to load', () => { + beforeEach(async () => { + await wrapper.setProps({ + value: { currentPage: 1, pending: false, pageSize: 5, itemsShown: 2 }, + }) + }) + + it('renders text in singular', () => { + expect(mocks.$tc).toBeCalledWith('link-load', 0) + }) + }) + + describe('less than pageSize links to load', () => { + beforeEach(async () => { + await wrapper.setProps({ + value: { currentPage: 1, pending: false, pageSize: 5, itemsShown: 2 }, + transactionLinkCount: 6, + }) + }) + + it('renders text in singular', () => { + expect(mocks.$tc).toBeCalledWith('link-load', 1, { n: 4 }) + }) + }) + + describe('more than pageSize links to load', () => { + beforeEach(async () => { + await wrapper.setProps({ + value: { currentPage: 1, pending: false, pageSize: 5, itemsShown: 2 }, + transactionLinkCount: 16, + }) + }) + + it('renders text in singular', () => { + expect(mocks.$tc).toBeCalledWith('link-load', 2, { n: 5 }) + }) + }) + }) + }) +})