From 1b40d6aaeebff2091f3c563a82f53051fd1c0ed3 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Sun, 13 Nov 2022 13:18:41 +0100 Subject: [PATCH] unit tests for HISTORY type contribution messages --- .../ContributionMessagesListItem.spec.js | 63 ++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/ContributionMessages/ContributionMessagesListItem.spec.js b/frontend/src/components/ContributionMessages/ContributionMessagesListItem.spec.js index 2dc9fb3ce..1a918747f 100644 --- a/frontend/src/components/ContributionMessages/ContributionMessagesListItem.spec.js +++ b/frontend/src/components/ContributionMessages/ContributionMessagesListItem.spec.js @@ -5,9 +5,11 @@ import ContributionMessagesListItem from './ContributionMessagesListItem.vue' const localVue = global.localVue let wrapper +const dateMock = jest.fn((d) => d) + const mocks = { $t: jest.fn((t) => t), - $d: jest.fn((d) => d), + $d: dateMock, $store: { state: { firstName: 'Peter', @@ -239,4 +241,63 @@ and here is the link to the repository: https://github.com/gradido/gradido`) }) }) }) + + describe('contribution message type HISTORY', () => { + const propsData = { + message: { + id: 111, + message: `Sun Nov 13 2022 13:05:48 GMT+0100 (Central European Standard Time) +--- +This message also contains a link: https://gradido.net/de/ +--- +350.00`, + createdAt: '2022-08-29T12:23:27.000Z', + updatedAt: null, + type: 'HISTORY', + userFirstName: 'Peter', + userLastName: 'Lustig', + userId: 107, + __typename: 'ContributionMessage', + }, + } + + const itemWrapper = () => { + return mount(ContributionMessagesListItem, { + localVue, + mocks, + propsData, + }) + } + + let messageField + + describe('render HISTORY message', () => { + beforeEach(() => { + jest.clearAllMocks() + wrapper = itemWrapper() + messageField = wrapper.find('div.is-not-moderator.text-right > div:nth-child(4)') + }) + + it('renders the date', () => { + expect(dateMock).toBeCalledWith( + new Date('Sun Nov 13 2022 13:05:48 GMT+0100 (Central European Standard Time'), + 'short', + ) + }) + + it('renders the amount', () => { + expect(messageField.text()).toContain('350.00 GDD') + }) + + it('contains the link as text', () => { + expect(messageField.text()).toContain( + 'This message also contains a link: https://gradido.net/de/', + ) + }) + + it('contains a link to the given address', () => { + expect(messageField.find('a').attributes('href')).toBe('https://gradido.net/de/') + }) + }) + }) })