From e09121d854e98245143cf2025601b158916003ea Mon Sep 17 00:00:00 2001 From: ogerly Date: Thu, 2 Dec 2021 08:17:56 +0100 Subject: [PATCH 01/23] Admin sends confirmPendingCreation to apollo. --- admin/src/components/UserTable.vue | 28 +++++++++++++-------- admin/src/graphql/confirmPendingCreation.js | 7 ++++++ 2 files changed, 24 insertions(+), 11 deletions(-) create mode 100644 admin/src/graphql/confirmPendingCreation.js diff --git a/admin/src/components/UserTable.vue b/admin/src/components/UserTable.vue index e47963159..fd02a08db 100644 --- a/admin/src/components/UserTable.vue +++ b/admin/src/components/UserTable.vue @@ -132,6 +132,7 @@ From 9c0bd490fab39aefe565d10d165badb9e21a0349 Mon Sep 17 00:00:00 2001 From: elweyn Date: Sat, 4 Dec 2021 11:39:00 +0100 Subject: [PATCH 13/23] Moved created method to the end. --- admin/src/components/EditCreationFormular.vue | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/admin/src/components/EditCreationFormular.vue b/admin/src/components/EditCreationFormular.vue index 9154a68fa..c46698b9d 100644 --- a/admin/src/components/EditCreationFormular.vue +++ b/admin/src/components/EditCreationFormular.vue @@ -166,30 +166,6 @@ export default { required: true, }, }, - created() { - this.searchModeratorData() - if (this.pagetype === 'PageCreationConfirm' && this.creationUserData.date) { - switch (this.$moment(this.creationUserData.date).format('MMMM')) { - case this.currentMonth.short: - this.createdIndex = 2 - this.radioSelected = this.currentMonth - break - case this.lastMonth.short: - this.createdIndex = 1 - this.radioSelected = this.lastMonth - break - case this.beforeLastMonth.short: - this.createdIndex = 0 - this.radioSelected = this.beforeLastMonth - break - default: - throw new Error('Something went wrong') - } - this.selectedOpenCreationAmount[this.createdIndex] = - this.creation[this.createdIndex] + this.creationUserData.amount - this.rangeMax = this.selectedOpenCreationAmount[this.createdIndex] - } - }, data() { return { radioSelected: '', @@ -293,5 +269,29 @@ export default { }) }, }, + created() { + this.searchModeratorData() + if (this.pagetype === 'PageCreationConfirm' && this.creationUserData.date) { + switch (this.$moment(this.creationUserData.date).format('MMMM')) { + case this.currentMonth.short: + this.createdIndex = 2 + this.radioSelected = this.currentMonth + break + case this.lastMonth.short: + this.createdIndex = 1 + this.radioSelected = this.lastMonth + break + case this.beforeLastMonth.short: + this.createdIndex = 0 + this.radioSelected = this.beforeLastMonth + break + default: + throw new Error('Something went wrong') + } + this.selectedOpenCreationAmount[this.createdIndex] = + this.creation[this.createdIndex] + this.creationUserData.amount + this.rangeMax = this.selectedOpenCreationAmount[this.createdIndex] + } + }, } From a5406286fe6666e68c37b5455952e2b838ea8790 Mon Sep 17 00:00:00 2001 From: elweyn Date: Sat, 4 Dec 2021 11:43:00 +0100 Subject: [PATCH 14/23] change logic need a if exists or if not exists to up and downgrade easily. --- database/migrations/0002-add_settings.ts | 4 +- .../migrations/0003-login_server_tables.ts | 40 +++++++++---------- database/migrations/0004-login_server_data.ts | 14 +------ database/migrations/0005-admin_tables.ts | 4 +- 4 files changed, 25 insertions(+), 37 deletions(-) diff --git a/database/migrations/0002-add_settings.ts b/database/migrations/0002-add_settings.ts index 1b3b8a1a4..5c1b4fbe7 100644 --- a/database/migrations/0002-add_settings.ts +++ b/database/migrations/0002-add_settings.ts @@ -14,7 +14,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promise>) { await queryFn(` - CREATE TABLE \`user_setting\` ( + CREATE TABLE IF NOT EXISTS \`user_setting\` ( \`id\` int(10) unsigned NOT NULL AUTO_INCREMENT, \`userId\` int(11) NOT NULL, \`key\` varchar(255) NOT NULL, @@ -25,5 +25,5 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { // write downgrade logic as parameter of queryFn - await queryFn(`DROP TABLE \`user_setting\`;`) + await queryFn(`DROP TABLE IF EXISTS \`user_setting\`;`) } diff --git a/database/migrations/0003-login_server_tables.ts b/database/migrations/0003-login_server_tables.ts index 54e7bca54..d3d720c97 100644 --- a/database/migrations/0003-login_server_tables.ts +++ b/database/migrations/0003-login_server_tables.ts @@ -14,7 +14,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promise>) { await queryFn(` - CREATE TABLE \`login_app_access_tokens\` ( + CREATE TABLE IF NOT EXISTS \`login_app_access_tokens\` ( \`id\` int unsigned NOT NULL AUTO_INCREMENT, \`user_id\` int NOT NULL, \`access_code\` bigint unsigned NOT NULL, @@ -25,7 +25,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; `) await queryFn(` - CREATE TABLE \`login_elopage_buys\` ( + CREATE TABLE IF NOT EXISTS \`login_elopage_buys\` ( \`id\` int unsigned NOT NULL AUTO_INCREMENT, \`elopage_user_id\` int DEFAULT NULL, \`affiliate_program_id\` int NOT NULL, @@ -42,7 +42,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; `) await queryFn(` - CREATE TABLE \`login_email_opt_in_types\` ( + CREATE TABLE IF NOT EXISTS \`login_email_opt_in_types\` ( \`id\` int unsigned NOT NULL AUTO_INCREMENT, \`name\` varchar(255) NOT NULL, \`description\` varchar(255) NOT NULL, @@ -50,7 +50,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; `) await queryFn(` - CREATE TABLE \`login_email_opt_in\` ( + CREATE TABLE IF NOT EXISTS \`login_email_opt_in\` ( \`id\` int unsigned NOT NULL AUTO_INCREMENT, \`user_id\` int NOT NULL, \`verification_code\` bigint unsigned NOT NULL, @@ -63,7 +63,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; `) await queryFn(` - CREATE TABLE \`login_groups\` ( + CREATE TABLE IF NOT EXISTS \`login_groups\` ( \`id\` int unsigned NOT NULL AUTO_INCREMENT, \`alias\` varchar(190) NOT NULL, \`name\` varchar(255) NOT NULL, @@ -76,7 +76,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; `) await queryFn(` - CREATE TABLE \`login_pending_tasks\` ( + CREATE TABLE IF NOT EXISTS \`login_pending_tasks\` ( \`id\` int UNSIGNED NOT NULL AUTO_INCREMENT, \`user_id\` int UNSIGNED DEFAULT 0, \`request\` varbinary(2048) NOT NULL, @@ -91,7 +91,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis ) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4; `) await queryFn(` - CREATE TABLE \`login_roles\` ( + CREATE TABLE IF NOT EXISTS \`login_roles\` ( \`id\` int unsigned NOT NULL AUTO_INCREMENT, \`name\` varchar(255) NOT NULL, \`description\` varchar(255) NOT NULL, @@ -100,7 +100,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; `) await queryFn(` - CREATE TABLE \`login_user_backups\` ( + CREATE TABLE IF NOT EXISTS \`login_user_backups\` ( \`id\` int unsigned NOT NULL AUTO_INCREMENT, \`user_id\` int NOT NULL, \`passphrase\` text NOT NULL, @@ -109,7 +109,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; `) await queryFn(` - CREATE TABLE \`login_user_roles\` ( + CREATE TABLE IF NOT EXISTS \`login_user_roles\` ( \`id\` int unsigned NOT NULL AUTO_INCREMENT, \`user_id\` int NOT NULL, \`role_id\` int NOT NULL, @@ -117,7 +117,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; `) await queryFn(` - CREATE TABLE \`login_users\` ( + CREATE TABLE IF NOT EXISTS \`login_users\` ( \`id\` int unsigned NOT NULL AUTO_INCREMENT, \`email\` varchar(191) NOT NULL, \`first_name\` varchar(150) NOT NULL, @@ -143,14 +143,14 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { // write downgrade logic as parameter of queryFn - await queryFn(`DROP TABLE \`login_app_access_tokens\`;`) - await queryFn(`DROP TABLE \`login_elopage_buys\`;`) - await queryFn(`DROP TABLE \`login_email_opt_in_types\`;`) - await queryFn(`DROP TABLE \`login_email_opt_in\`;`) - await queryFn(`DROP TABLE \`login_groups\`;`) - await queryFn(`DROP TABLE \`login_pending_tasks\`;`) - await queryFn(`DROP TABLE \`login_roles\`;`) - await queryFn(`DROP TABLE \`login_user_backups\`;`) - await queryFn(`DROP TABLE \`login_user_roles\`;`) - await queryFn(`DROP TABLE \`login_users\`;`) + await queryFn(`DROP TABLE IF EXISTS \`login_app_access_tokens\`;`) + await queryFn(`DROP TABLE IF EXISTS \`login_elopage_buys\`;`) + await queryFn(`DROP TABLE IF EXISTS \`login_email_opt_in_types\`;`) + await queryFn(`DROP TABLE IF EXISTS \`login_email_opt_in\`;`) + await queryFn(`DROP TABLE IF EXISTS \`login_groups\`;`) + await queryFn(`DROP TABLE IF EXISTS \`login_pending_tasks\`;`) + await queryFn(`DROP TABLE IF EXISTS \`login_roles\`;`) + await queryFn(`DROP TABLE IF EXISTS \`login_user_backups\`;`) + await queryFn(`DROP TABLE IF EXISTS \`login_user_roles\`;`) + await queryFn(`DROP TABLE IF EXISTS \`login_users\`;`) } diff --git a/database/migrations/0004-login_server_data.ts b/database/migrations/0004-login_server_data.ts index f319b16ab..b69283ad7 100644 --- a/database/migrations/0004-login_server_data.ts +++ b/database/migrations/0004-login_server_data.ts @@ -62,16 +62,4 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis `) } -export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { - // write downgrade logic as parameter of queryFn - await queryFn(`DELETE FROM \`login_app_access_tokens\`;`) - await queryFn(`DELETE FROM \`login_elopage_buys\`;`) - await queryFn(`DELETE FROM \`login_email_opt_in_types\`;`) - await queryFn(`DELETE FROM \`login_email_opt_in\`;`) - await queryFn(`DELETE FROM \`login_groups\`;`) - await queryFn(`DELETE FROM \`login_pending_tasks\`;`) - await queryFn(`DELETE FROM \`login_roles\`;`) - await queryFn(`DELETE FROM \`login_user_backups\`;`) - await queryFn(`DELETE FROM \`login_user_roles\`;`) - await queryFn(`DELETE FROM \`login_users\`;`) -} +export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) {} diff --git a/database/migrations/0005-admin_tables.ts b/database/migrations/0005-admin_tables.ts index 6398b22fc..bd325678f 100644 --- a/database/migrations/0005-admin_tables.ts +++ b/database/migrations/0005-admin_tables.ts @@ -11,7 +11,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promise>) { await queryFn(` - CREATE TABLE \`login_pending_tasks_admin\` ( + CREATE TABLE IF NOT EXISTS \`login_pending_tasks_admin\` ( \`id\` int UNSIGNED NOT NULL AUTO_INCREMENT, \`userId\` int UNSIGNED DEFAULT 0, \`created\` datetime NOT NULL, @@ -25,5 +25,5 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis } export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { - await queryFn(`DROP TABLE \`login_pending_tasks_admin\`;`) + await queryFn(`DROP TABLE IF EXISTS \`login_pending_tasks_admin\`;`) } From c7633bb1eb4047c3a572572f79506a54a787edf4 Mon Sep 17 00:00:00 2001 From: elweyn Date: Sat, 4 Dec 2021 12:22:48 +0100 Subject: [PATCH 15/23] Test submit of EditCreationFormular, remove getCountPendingCreations. --- .../components/EditCreationFormular.spec.js | 38 +++++++++++++++++++ admin/src/components/EditCreationFormular.vue | 1 + admin/src/graphql/getCountPendingCreations.js | 7 ---- 3 files changed, 39 insertions(+), 7 deletions(-) delete mode 100644 admin/src/graphql/getCountPendingCreations.js diff --git a/admin/src/components/EditCreationFormular.spec.js b/admin/src/components/EditCreationFormular.spec.js index 8f8103b06..dd503411a 100644 --- a/admin/src/components/EditCreationFormular.spec.js +++ b/admin/src/components/EditCreationFormular.spec.js @@ -39,6 +39,12 @@ const mocks = { mutate: apolloMutateMock, }, $store: { + state: { + moderator: { + id: 0, + name: 'test moderator', + }, + }, commit: stateCommitMock, }, } @@ -92,6 +98,8 @@ describe('EditCreationFormular', () => { jest.clearAllMocks() await wrapper.setProps({ type: 'singleCreation', creation: [200, 400, 600] }) await wrapper.setData({ rangeMin: 180 }) + await wrapper.setData({ text: 'Test create coins' }) + await wrapper.setData({ value: 90 }) }) describe('first radio button', () => { @@ -106,6 +114,16 @@ describe('EditCreationFormular', () => { it('sets rangeMax to 200', () => { expect(wrapper.vm.rangeMax).toBe(200) }) + + describe('sendForm', () => { + beforeEach(async () => { + await wrapper.find('.test-submit').trigger('click') + }) + + it('sends ... to apollo', () => { + expect(apolloMutateMock).toBeCalled() + }) + }) }) describe('second radio button', () => { @@ -120,6 +138,16 @@ describe('EditCreationFormular', () => { it('sets rangeMax to 400', () => { expect(wrapper.vm.rangeMax).toBe(400) }) + + describe('sendForm', () => { + beforeEach(async () => { + await wrapper.find('.test-submit').trigger('click') + }) + + it('sends ... to apollo', () => { + expect(apolloMutateMock).toBeCalled() + }) + }) }) describe('third radio button', () => { @@ -134,6 +162,16 @@ describe('EditCreationFormular', () => { it('sets rangeMax to 400', () => { expect(wrapper.vm.rangeMax).toBe(600) }) + + describe('sendForm', () => { + beforeEach(async () => { + await wrapper.find('.test-submit').trigger('click') + }) + + it('sends ... to apollo', () => { + expect(apolloMutateMock).toBeCalled() + }) + }) }) }) }) diff --git a/admin/src/components/EditCreationFormular.vue b/admin/src/components/EditCreationFormular.vue index c46698b9d..5e1bf4be1 100644 --- a/admin/src/components/EditCreationFormular.vue +++ b/admin/src/components/EditCreationFormular.vue @@ -106,6 +106,7 @@ diff --git a/admin/src/graphql/getCountPendingCreations.js b/admin/src/graphql/getCountPendingCreations.js deleted file mode 100644 index f8593ee59..000000000 --- a/admin/src/graphql/getCountPendingCreations.js +++ /dev/null @@ -1,7 +0,0 @@ -import gql from 'graphql-tag' - -export const countPendingCreations = gql` - query { - countPendingCreations - } -` From 16fa3de5736ad3c6157c8ec028a1f6b59dcf1fa7 Mon Sep 17 00:00:00 2001 From: elweyn Date: Sat, 4 Dec 2021 12:29:38 +0100 Subject: [PATCH 16/23] click on months in the creation form if index 0, and id set for the label --- admin/src/components/CreationFormular.vue | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/admin/src/components/CreationFormular.vue b/admin/src/components/CreationFormular.vue index dd19ef7ca..41eeef6a3 100644 --- a/admin/src/components/CreationFormular.vue +++ b/admin/src/components/CreationFormular.vue @@ -6,6 +6,7 @@ - +
@@ -92,6 +95,7 @@ v-if="pagetype === 'PageCreationConfirm'" type="button" variant="success" + class="test-submit" @click="submitCreation" :disabled="radioSelected === '' || value <= 0 || text.length < 10" > @@ -183,7 +187,9 @@ export default { methods: { // Auswählen eines Zeitraumes updateRadioSelected(name, index, openCreation) { + console.log('this.createdIndex befor', this.createdIndex) this.createdIndex = index + console.log('this.createdIndex last', this.createdIndex) // Wenn Mehrfachschöpfung if (this.type === 'massCreation') { // An Creation.vue emitten und radioSelectedMass aktualisieren From f5572febee74cffecfbd5a4b31581a5e55dc17c3 Mon Sep 17 00:00:00 2001 From: elweyn Date: Sat, 4 Dec 2021 13:27:10 +0100 Subject: [PATCH 17/23] Testing Creation and EditCreation formulars. --- admin/src/components/CreationFormular.spec.js | 186 ++++++++++++++++++ admin/src/components/CreationFormular.vue | 20 +- admin/src/components/EditCreationFormular.vue | 23 +-- 3 files changed, 192 insertions(+), 37 deletions(-) diff --git a/admin/src/components/CreationFormular.spec.js b/admin/src/components/CreationFormular.spec.js index 01faaed39..f167d48a1 100644 --- a/admin/src/components/CreationFormular.spec.js +++ b/admin/src/components/CreationFormular.spec.js @@ -11,7 +11,14 @@ const apolloMock = jest.fn().mockResolvedValue({ }, }, }) +const apolloMutateMock = jest.fn().mockResolvedValue({ + data: { + createPendingCreation: [0, 0, 0], + }, +}) const stateCommitMock = jest.fn() +const toastedErrorMock = jest.fn() +const toastedSuccessMock = jest.fn() const mocks = { $moment: jest.fn(() => { @@ -26,9 +33,20 @@ const mocks = { }), $apollo: { query: apolloMock, + mutate: apolloMutateMock, }, $store: { commit: stateCommitMock, + state: { + moderator: { + id: 0, + name: 'test moderator', + }, + }, + }, + $toasted: { + error: toastedErrorMock, + success: toastedSuccessMock, }, } @@ -124,6 +142,8 @@ describe('CreationFormular', () => { jest.clearAllMocks() await wrapper.setProps({ type: 'singleCreation', creation: [200, 400, 600] }) await wrapper.setData({ rangeMin: 180 }) + await wrapper.setData({ text: 'Test create coins' }) + await wrapper.setData({ value: 90 }) }) describe('first radio button', () => { @@ -138,6 +158,66 @@ describe('CreationFormular', () => { it('sets rangeMax to 200', () => { expect(wrapper.vm.rangeMax).toBe(200) }) + + describe('sendForm', () => { + beforeEach(async () => { + await wrapper.find('.test-submit').trigger('click') + }) + + it('sends ... to apollo', () => { + expect(apolloMutateMock).toBeCalled() + }) + }) + + describe('sendForm', () => { + beforeEach(async () => { + apolloMutateMock.mockRejectedValueOnce({ message: 'Ouch!' }) + await wrapper.find('.test-submit').trigger('click') + }) + + it('sends ... to apollo', () => { + expect(toastedErrorMock).toBeCalled() + }) + }) + + describe('Negativ value', () => { + beforeEach(async () => { + jest.clearAllMocks() + await wrapper.setProps({ type: 'singleCreation', creation: [200, 400, 600] }) + await wrapper.setData({ rangeMin: 180 }) + await wrapper.setData({ value: -20 }) + }) + + it('has no submit button', async () => { + expect(await wrapper.find('.test-submit').attributes('disabled')).toBe('disabled') + }) + }) + + describe('Empty text', () => { + beforeEach(async () => { + jest.clearAllMocks() + await wrapper.setProps({ type: 'singleCreation', creation: [200, 400, 600] }) + await wrapper.setData({ rangeMin: 180 }) + await wrapper.setData({ text: '' }) + }) + + it('has no submit button', async () => { + expect(await wrapper.find('.test-submit').attributes('disabled')).toBe('disabled') + }) + }) + + describe('Text length less than 10', () => { + beforeEach(async () => { + jest.clearAllMocks() + await wrapper.setProps({ type: 'singleCreation', creation: [200, 400, 600] }) + await wrapper.setData({ rangeMin: 180 }) + await wrapper.setData({ text: 'Try this' }) + }) + + it('has no submit button', async () => { + expect(await wrapper.find('.test-submit').attributes('disabled')).toBe('disabled') + }) + }) }) describe('second radio button', () => { @@ -152,6 +232,55 @@ describe('CreationFormular', () => { it('sets rangeMax to 400', () => { expect(wrapper.vm.rangeMax).toBe(400) }) + + describe('sendForm', () => { + beforeEach(async () => { + await wrapper.find('.test-submit').trigger('click') + }) + + it('sends ... to apollo', () => { + expect(apolloMutateMock).toBeCalled() + }) + }) + + describe('Negativ value', () => { + beforeEach(async () => { + jest.clearAllMocks() + await wrapper.setProps({ type: 'singleCreation', creation: [200, 400, 600] }) + await wrapper.setData({ rangeMin: 180 }) + await wrapper.setData({ value: -20 }) + }) + + it('has no submit button', async () => { + expect(await wrapper.find('.test-submit').attributes('disabled')).toBe('disabled') + }) + }) + + describe('Empty text', () => { + beforeEach(async () => { + jest.clearAllMocks() + await wrapper.setProps({ type: 'singleCreation', creation: [200, 400, 600] }) + await wrapper.setData({ rangeMin: 180 }) + await wrapper.setData({ text: '' }) + }) + + it('has no submit button', async () => { + expect(await wrapper.find('.test-submit').attributes('disabled')).toBe('disabled') + }) + }) + + describe('Text length less than 10', () => { + beforeEach(async () => { + jest.clearAllMocks() + await wrapper.setProps({ type: 'singleCreation', creation: [200, 400, 600] }) + await wrapper.setData({ rangeMin: 180 }) + await wrapper.setData({ text: 'Try this' }) + }) + + it('has no submit button', async () => { + expect(await wrapper.find('.test-submit').attributes('disabled')).toBe('disabled') + }) + }) }) describe('third radio button', () => { @@ -166,6 +295,63 @@ describe('CreationFormular', () => { it('sets rangeMax to 400', () => { expect(wrapper.vm.rangeMax).toBe(600) }) + + describe('sendForm', () => { + beforeEach(async () => { + await wrapper.find('.test-submit').trigger('click') + }) + + it('sends mutation to apollo', () => { + expect(apolloMutateMock).toBeCalled() + }) + + it('toast success message', () => { + expect(toastedSuccessMock).toBeCalled() + }) + + it('store commit openCreationPlus', () => { + expect(stateCommitMock).toBeCalledWith('openCreationsPlus', 1) + }) + }) + + describe('Negativ value', () => { + beforeEach(async () => { + jest.clearAllMocks() + await wrapper.setProps({ type: 'singleCreation', creation: [200, 400, 600] }) + await wrapper.setData({ rangeMin: 180 }) + await wrapper.setData({ value: -20 }) + }) + + it('has no submit button', async () => { + expect(await wrapper.find('.test-submit').attributes('disabled')).toBe('disabled') + }) + }) + + describe('Empty text', () => { + beforeEach(async () => { + jest.clearAllMocks() + await wrapper.setProps({ type: 'singleCreation', creation: [200, 400, 600] }) + await wrapper.setData({ rangeMin: 180 }) + await wrapper.setData({ text: '' }) + }) + + it('has no submit button', async () => { + expect(await wrapper.find('.test-submit').attributes('disabled')).toBe('disabled') + }) + }) + + describe('Text length less than 10', () => { + beforeEach(async () => { + jest.clearAllMocks() + await wrapper.setProps({ type: 'singleCreation', creation: [200, 400, 600] }) + await wrapper.setData({ rangeMin: 180 }) + await wrapper.setData({ text: 'Try this' }) + }) + + it('has no submit button', async () => { + expect(await wrapper.find('.test-submit').attributes('disabled')).toBe('disabled') + }) + }) }) }) }) diff --git a/admin/src/components/CreationFormular.vue b/admin/src/components/CreationFormular.vue index 41eeef6a3..5b131dca8 100644 --- a/admin/src/components/CreationFormular.vue +++ b/admin/src/components/CreationFormular.vue @@ -106,6 +106,7 @@ v-else type="button" variant="success" + class="test-submit" @click="submitCreation" :disabled="radioSelected === '' || value <= 0 || text.length < 10" > @@ -187,9 +188,7 @@ export default { methods: { // Auswählen eines Zeitraumes updateRadioSelected(name, index, openCreation) { - console.log('this.createdIndex befor', this.createdIndex) this.createdIndex = index - console.log('this.createdIndex last', this.createdIndex) // Wenn Mehrfachschöpfung if (this.type === 'massCreation') { // An Creation.vue emitten und radioSelectedMass aktualisieren @@ -201,23 +200,6 @@ export default { } }, submitCreation() { - // Formular Prüfen ob ein Zeitraum ausgewählt wurde. Ansonsten abbrechen und Hinweis anzeigen - if (this.radioSelected === '') { - return this.$toasted.error('Bitte wähle einen Zeitraum!') - } - // Formular Prüfen ob der GDD Betrag grösser 0 ist. Ansonsten abbrechen und Hinweis anzeigen - if (this.value <= 0) { - return this.$toasted.error('Bitte gib einen GDD Betrag an!') - } - // Formular Prüfen ob der Text vorhanden ist. Ansonsten abbrechen und Hinweis anzeigen - if (this.text === '') { - return this.$toasted.error('Bitte gib einen Text ein!') - } - // Formular Prüfen ob der Text länger als 10 Zeichen hat. Ansonsten abbrechen und Hinweis anzeigen - if (this.text.length < 10) { - return this.$toasted.error('Bitte gib einen Text ein der länger als 10 Zeichen ist!') - } - if (this.type === 'massCreation') { // Die anzahl der Mitglieder aus der Mehrfachschöpfung const i = Object.keys(this.itemsMassCreation).length diff --git a/admin/src/components/EditCreationFormular.vue b/admin/src/components/EditCreationFormular.vue index 5e1bf4be1..bda48569a 100644 --- a/admin/src/components/EditCreationFormular.vue +++ b/admin/src/components/EditCreationFormular.vue @@ -6,6 +6,7 @@ Date: Sat, 4 Dec 2021 13:38:53 +0100 Subject: [PATCH 18/23] test ok for Overview.spec.js --- admin/src/pages/Overview.spec.js | 52 ++++++++++++++++++++++++++++++++ admin/src/pages/Overview.vue | 2 +- 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 admin/src/pages/Overview.spec.js diff --git a/admin/src/pages/Overview.spec.js b/admin/src/pages/Overview.spec.js new file mode 100644 index 000000000..7f0a2b3cc --- /dev/null +++ b/admin/src/pages/Overview.spec.js @@ -0,0 +1,52 @@ +import { mount } from '@vue/test-utils' +import Overview from './Overview.vue' + +const localVue = global.localVue + +const apolloQueryMock = jest.fn().mockResolvedValue({ + data: { + searchUsers: [ + { + firstName: 'Bibi', + lastName: 'Bloxberg', + email: 'bibi@bloxberg.de', + creation: [200, 400, 600], + }, + ], + }, +}) + +const toastErrorMock = jest.fn() + +const mocks = { + $store: { + state: { + openCreations: 0, + }, + commit: jest.fn(), + }, + $apollo: { + query: apolloQueryMock, + }, + $toasted: { + error: toastErrorMock, + }, +} + +describe('Overview', () => { + let wrapper + + const Wrapper = () => { + return mount(Overview, { localVue, mocks }) + } + + describe('mount', () => { + beforeEach(() => { + wrapper = Wrapper() + }) + + it('has a DIV element with the class.admin-overview', () => { + expect(wrapper.find('div.admin-overview').exists()).toBeTruthy() + }) + }) +}) diff --git a/admin/src/pages/Overview.vue b/admin/src/pages/Overview.vue index 8d05e03e8..f45f588e5 100644 --- a/admin/src/pages/Overview.vue +++ b/admin/src/pages/Overview.vue @@ -1,5 +1,5 @@