-
+
{{ text }}
+
+ {{ $d(new Date(text), 'short') }}
+
+
+
+
+ {{ `${$n(Number(text), 'decimal')} GDD` }}
+
{{ text }}
@@ -12,17 +20,28 @@ const LINK_REGEX_PATTERN =
/(https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*))/i
export default {
- name: 'LinkifyMessage',
+ name: 'ParseMessage',
props: {
message: {
type: String,
required: true,
},
+ type: {
+ type: String,
+ reuired: true,
+ },
},
computed: {
- linkifiedMessage() {
- const linkified = []
+ parsedMessage() {
let string = this.message
+ const linkified = []
+ let amount
+ if (this.type === 'HISTORY') {
+ const split = string.split(/\n\s*---\n\s*/)
+ string = split[1]
+ linkified.push({ type: 'date', text: split[0].trim() })
+ amount = split[2].trim()
+ }
let match
while ((match = string.match(LINK_REGEX_PATTERN))) {
if (match.index > 0)
@@ -31,6 +50,7 @@ export default {
string = string.substring(match.index + match[0].length)
}
if (string.length > 0) linkified.push({ type: 'text', text: string })
+ if (amount) linkified.push({ type: 'amount', text: amount })
return linkified
},
},
diff --git a/admin/src/components/ContributionMessages/slots/ContributionMessagesListItem.spec.js b/admin/src/components/ContributionMessages/slots/ContributionMessagesListItem.spec.js
index c1a4e65c6..1b4f963e8 100644
--- a/admin/src/components/ContributionMessages/slots/ContributionMessagesListItem.spec.js
+++ b/admin/src/components/ContributionMessages/slots/ContributionMessagesListItem.spec.js
@@ -3,12 +3,16 @@ import ContributionMessagesListItem from './ContributionMessagesListItem.vue'
const localVue = global.localVue
+const dateMock = jest.fn((d) => d)
+const numberMock = jest.fn((n) => n)
+
describe('ContributionMessagesListItem', () => {
let wrapper
const mocks = {
$t: jest.fn((t) => t),
- $d: jest.fn((d) => d),
+ $d: dateMock,
+ $n: numberMock,
}
describe('if message author has moderator role', () => {
@@ -189,4 +193,64 @@ 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-left > 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(numberMock).toBeCalledWith(350, 'decimal')
+ expect(messageField.text()).toContain('350 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/')
+ })
+ })
+ })
})
diff --git a/admin/src/components/ContributionMessages/slots/ContributionMessagesListItem.vue b/admin/src/components/ContributionMessages/slots/ContributionMessagesListItem.vue
index 30960bd33..53006cff5 100644
--- a/admin/src/components/ContributionMessages/slots/ContributionMessagesListItem.vue
+++ b/admin/src/components/ContributionMessages/slots/ContributionMessagesListItem.vue
@@ -5,23 +5,23 @@
{{ message.userFirstName }} {{ message.userLastName }}
{{ $d(new Date(message.createdAt), 'short') }}
{{ $t('moderator') }}
-
+
{{ message.userFirstName }} {{ message.userLastName }}
{{ $d(new Date(message.createdAt), 'short') }}
-
+