diff --git a/admin/src/components/ContributionMessages/ContributionMessagesFormular.spec.js b/admin/src/components/ContributionMessages/ContributionMessagesFormular.spec.js new file mode 100644 index 000000000..62fcab505 --- /dev/null +++ b/admin/src/components/ContributionMessages/ContributionMessagesFormular.spec.js @@ -0,0 +1,111 @@ +import { mount } from '@vue/test-utils' +import ContributionMessagesFormular from './ContributionMessagesFormular.vue' +import { toastErrorSpy, toastSuccessSpy } from '../../../test/testSetup' + +const localVue = global.localVue + +const apolloMutateMock = jest.fn().mockResolvedValue() + +describe('ContributionMessagesFormular', () => { + let wrapper + + const propsData = { + contributionId: 42, + } + + const mocks = { + $t: jest.fn((t) => t), + $apollo: { + mutate: apolloMutateMock, + }, + $i18n: { + locale: 'en', + }, + } + + const Wrapper = () => { + return mount(ContributionMessagesFormular, { + localVue, + mocks, + propsData, + }) + } + + describe('mount', () => { + beforeEach(() => { + wrapper = Wrapper() + }) + + it('has a DIV .contribution-messages-formular', () => { + expect(wrapper.find('div.contribution-messages-formular').exists()).toBe(true) + }) + + describe('on trigger reset', () => { + beforeEach(async () => { + wrapper.setData({ + form: { + text: 'text form message', + }, + }) + await wrapper.find('form').trigger('reset') + }) + + it('form has empty text', () => { + expect(wrapper.vm.form).toEqual({ + text: '', + }) + }) + }) + + describe('on trigger submit', () => { + beforeEach(async () => { + wrapper.setData({ + form: { + text: 'text form message', + }, + }) + await wrapper.find('form').trigger('submit') + }) + + it('emitted "get-list-contribution-messages" with data', async () => { + expect(wrapper.emitted('get-list-contribution-messages')).toEqual( + expect.arrayContaining([expect.arrayContaining([42])]), + ) + }) + + it('emitted "update-state" with data', async () => { + expect(wrapper.emitted('update-state')).toEqual( + expect.arrayContaining([expect.arrayContaining([42])]), + ) + }) + }) + + describe('send contribution message with error', () => { + beforeEach(async () => { + apolloMutateMock.mockRejectedValue({ message: 'OUCH!' }) + wrapper = Wrapper() + await wrapper.find('form').trigger('submit') + }) + + it('toasts an error message', () => { + expect(toastErrorSpy).toBeCalledWith('OUCH!') + }) + }) + + describe('send contribution message with success', () => { + beforeEach(async () => { + wrapper.setData({ + form: { + text: 'text form message', + }, + }) + wrapper = Wrapper() + await wrapper.find('form').trigger('submit') + }) + + it('toasts an success message', () => { + expect(toastSuccessSpy).toBeCalledWith('message.request') + }) + }) + }) +}) diff --git a/admin/src/components/ContributionMessages/ContributionMessagesFormular.vue b/admin/src/components/ContributionMessages/ContributionMessagesFormular.vue new file mode 100644 index 000000000..15fc4f78d --- /dev/null +++ b/admin/src/components/ContributionMessages/ContributionMessagesFormular.vue @@ -0,0 +1,67 @@ + + diff --git a/admin/src/components/ContributionMessages/ContributionMessagesList.spec.js b/admin/src/components/ContributionMessages/ContributionMessagesList.spec.js new file mode 100644 index 000000000..0bca08b2a --- /dev/null +++ b/admin/src/components/ContributionMessages/ContributionMessagesList.spec.js @@ -0,0 +1,56 @@ +import { mount } from '@vue/test-utils' +import ContributionMessagesList from './ContributionMessagesList.vue' + +const localVue = global.localVue + +const apolloQueryMock = jest.fn().mockResolvedValue() + +describe('ContributionMessagesList', () => { + let wrapper + + const propsData = { + contributionId: 42, + } + + const mocks = { + $t: jest.fn((t) => t), + $i18n: { + locale: 'en', + }, + $apollo: { + query: apolloQueryMock, + }, + } + + const Wrapper = () => { + return mount(ContributionMessagesList, { + localVue, + mocks, + propsData, + }) + } + + describe('mount', () => { + beforeEach(() => { + wrapper = Wrapper() + }) + + it('sends query to Apollo when created', () => { + expect(apolloQueryMock).toBeCalledWith( + expect.objectContaining({ + variables: { + contributionId: propsData.contributionId, + }, + }), + ) + }) + + it('has a DIV .contribution-messages-list', () => { + expect(wrapper.find('div.contribution-messages-list').exists()).toBe(true) + }) + + it('has a Component ContributionMessagesFormular', () => { + expect(wrapper.findComponent({ name: 'ContributionMessagesFormular' }).exists()).toBe(true) + }) + }) +}) diff --git a/admin/src/components/ContributionMessages/ContributionMessagesList.vue b/admin/src/components/ContributionMessages/ContributionMessagesList.vue new file mode 100644 index 000000000..8f5a3e119 --- /dev/null +++ b/admin/src/components/ContributionMessages/ContributionMessagesList.vue @@ -0,0 +1,69 @@ + + + diff --git a/admin/src/components/ContributionMessages/slots/ContributionMessagesListItem.spec.js b/admin/src/components/ContributionMessages/slots/ContributionMessagesListItem.spec.js new file mode 100644 index 000000000..7cca315d7 --- /dev/null +++ b/admin/src/components/ContributionMessages/slots/ContributionMessagesListItem.spec.js @@ -0,0 +1,58 @@ +import { mount } from '@vue/test-utils' +import ContributionMessagesListItem from './ContributionMessagesListItem.vue' + +const localVue = global.localVue + +describe('ContributionMessagesListItem', () => { + let wrapper + + const mocks = { + $t: jest.fn((t) => t), + $d: jest.fn((d) => d), + $store: { + state: { + moderator: { + id: 107, + }, + }, + }, + } + + const propsData = { + contributionId: 42, + state: 'PENDING0', + message: { + id: 111, + message: 'asd asda sda sda', + createdAt: '2022-08-29T12:23:27.000Z', + updatedAt: null, + type: 'DIALOG', + userFirstName: 'Peter', + userLastName: 'Lustig', + userId: 107, + __typename: 'ContributionMessage', + }, + } + + const Wrapper = () => { + return mount(ContributionMessagesListItem, { + localVue, + mocks, + propsData, + }) + } + + describe('mount', () => { + beforeEach(() => { + wrapper = Wrapper() + }) + + it('has a DIV .contribution-messages-list-item', () => { + expect(wrapper.find('div.contribution-messages-list-item').exists()).toBe(true) + }) + + it('props.message.default', () => { + expect(wrapper.vm.$options.props.message.default.call()).toEqual({}) + }) + }) +}) diff --git a/admin/src/components/ContributionMessages/slots/ContributionMessagesListItem.vue b/admin/src/components/ContributionMessages/slots/ContributionMessagesListItem.vue new file mode 100644 index 000000000..7ee0134ac --- /dev/null +++ b/admin/src/components/ContributionMessages/slots/ContributionMessagesListItem.vue @@ -0,0 +1,32 @@ + + diff --git a/admin/src/components/ContributionMessages/slots/IsModerator.spec.js b/admin/src/components/ContributionMessages/slots/IsModerator.spec.js new file mode 100644 index 000000000..b1e09da94 --- /dev/null +++ b/admin/src/components/ContributionMessages/slots/IsModerator.spec.js @@ -0,0 +1,49 @@ +import { mount } from '@vue/test-utils' +import IsModerator from './IsModerator.vue' + +const localVue = global.localVue + +describe('IsModerator', () => { + let wrapper + + const mocks = { + $t: jest.fn((t) => t), + $d: jest.fn((d) => d), + } + + const propsData = { + message: { + id: 111, + message: 'asd asda sda sda', + createdAt: '2022-08-29T12:23:27.000Z', + updatedAt: null, + type: 'DIALOG', + userFirstName: 'Peter', + userLastName: 'Lustig', + userId: 107, + __typename: 'ContributionMessage', + }, + } + + const Wrapper = () => { + return mount(IsModerator, { + localVue, + mocks, + propsData, + }) + } + + describe('mount', () => { + beforeEach(() => { + wrapper = Wrapper() + }) + + it('has a DIV .slot-is-moderator', () => { + expect(wrapper.find('div.slot-is-moderator').exists()).toBe(true) + }) + + it('props.message.default', () => { + expect(wrapper.vm.$options.props.message.default.call()).toEqual({}) + }) + }) +}) diff --git a/admin/src/components/ContributionMessages/slots/IsModerator.vue b/admin/src/components/ContributionMessages/slots/IsModerator.vue new file mode 100644 index 000000000..37db5402e --- /dev/null +++ b/admin/src/components/ContributionMessages/slots/IsModerator.vue @@ -0,0 +1,37 @@ + + + diff --git a/admin/src/components/ContributionMessages/slots/IsNotModerator.spec.js b/admin/src/components/ContributionMessages/slots/IsNotModerator.spec.js new file mode 100644 index 000000000..24152ad1e --- /dev/null +++ b/admin/src/components/ContributionMessages/slots/IsNotModerator.spec.js @@ -0,0 +1,49 @@ +import { mount } from '@vue/test-utils' +import IsNotModerator from './IsNotModerator.vue' + +const localVue = global.localVue + +describe('IsNotModerator', () => { + let wrapper + + const mocks = { + $t: jest.fn((t) => t), + $d: jest.fn((d) => d), + } + + const propsData = { + message: { + id: 113, + message: 'asda sdad ad asdasd ', + createdAt: '2022-08-29T12:25:34.000Z', + updatedAt: null, + type: 'DIALOG', + userFirstName: 'Bibi', + userLastName: 'Bloxberg', + userId: 108, + __typename: 'ContributionMessage', + }, + } + + const Wrapper = () => { + return mount(IsNotModerator, { + localVue, + mocks, + propsData, + }) + } + + describe('mount', () => { + beforeEach(() => { + wrapper = Wrapper() + }) + + it('has a DIV .slot-is-not-moderator', () => { + expect(wrapper.find('div.slot-is-not-moderator').exists()).toBe(true) + }) + + it('props.message.default', () => { + expect(wrapper.vm.$options.props.message.default.call()).toEqual({}) + }) + }) +}) diff --git a/admin/src/components/ContributionMessages/slots/IsNotModerator.vue b/admin/src/components/ContributionMessages/slots/IsNotModerator.vue new file mode 100644 index 000000000..8828fe5b0 --- /dev/null +++ b/admin/src/components/ContributionMessages/slots/IsNotModerator.vue @@ -0,0 +1,36 @@ + + + diff --git a/admin/src/components/Tables/OpenCreationsTable.vue b/admin/src/components/Tables/OpenCreationsTable.vue index 3ebc81fba..86c5ecce6 100644 --- a/admin/src/components/Tables/OpenCreationsTable.vue +++ b/admin/src/components/Tables/OpenCreationsTable.vue @@ -21,6 +21,19 @@ > + + + + +