From 34aaaa7db9e7ce9e0fc9b4d756ef56ffebe7ac90 Mon Sep 17 00:00:00 2001 From: Daniel Waxweiler Date: Thu, 9 Dec 2021 19:02:49 +0100 Subject: [PATCH] add group not found error message #11 --- source/connector-mobilizon/changelog.txt | 1 + .../front/events-displayer-test.js | 29 +++++++++++++------ .../front/events-displayer.js | 10 ++++++- .../connector-mobilizon/view/events-list.php | 1 + 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/source/connector-mobilizon/changelog.txt b/source/connector-mobilizon/changelog.txt index 8bad48e..d1d1ff2 100644 --- a/source/connector-mobilizon/changelog.txt +++ b/source/connector-mobilizon/changelog.txt @@ -1,5 +1,6 @@ ### [Unreleased] #### Added +- Add specific error message for the case the group is not found #### Changed - Set minimum PHP version to oldest officially supported 7.4 - Update dependencies diff --git a/source/connector-mobilizon/front/events-displayer-test.js b/source/connector-mobilizon/front/events-displayer-test.js index fc1ff2b..13bd113 100644 --- a/source/connector-mobilizon/front/events-displayer-test.js +++ b/source/connector-mobilizon/front/events-displayer-test.js @@ -17,6 +17,9 @@ test.beforeEach(t => { const listElement = document.createElement('li') listElement.setAttribute('style', 'display: none;') t.context.list.appendChild(listElement) + const listElement2 = document.createElement('li') + listElement2.setAttribute('style', 'display: none;') + t.context.list.appendChild(listElement2) }) test('#displayEvents one event', t => { @@ -38,24 +41,32 @@ test('#displayEvents one event', t => { } } displayEvents({ data, document, list }) - t.is(list.children.length, 2) - t.is(list.children[1].childNodes[0].tagName, 'A') - t.is(list.children[1].childNodes[0].getAttribute('href'), 'b') - t.is(list.children[1].childNodes[0].childNodes[0].nodeValue, 'a') - t.is(list.children[1].childNodes[1].tagName, 'BR') - t.is(list.children[1].childNodes[2].nodeValue, '15/04/2021 10:30 - 15:30') - t.is(list.children[1].childNodes[3].tagName, 'BR') - t.is(list.children[1].childNodes[4].nodeValue, 'c, d') + t.is(list.children.length, 3) + t.is(list.children[2].childNodes[0].tagName, 'A') + t.is(list.children[2].childNodes[0].getAttribute('href'), 'b') + t.is(list.children[2].childNodes[0].childNodes[0].nodeValue, 'a') + t.is(list.children[2].childNodes[1].tagName, 'BR') + t.is(list.children[2].childNodes[2].nodeValue, '15/04/2021 10:30 - 15:30') + t.is(list.children[2].childNodes[3].tagName, 'BR') + t.is(list.children[2].childNodes[4].nodeValue, 'c, d') }) test('#displayErrorMessage no children added', t => { const list = t.context.list displayErrorMessage({ data: '', list }) - t.is(list.children.length, 1) + t.is(list.children.length, 2) }) test('#displayErrorMessage error message display', t => { const list = t.context.list displayErrorMessage({ data: '', list }) t.is(list.children[0].style.display, 'block') + t.is(list.children[1].style.display, 'none') +}) + +test('#displayErrorMessage group not found error message display', t => { + const list = t.context.list + displayErrorMessage({ data: 'group_not_found', list }) + t.is(list.children[0].style.display, 'none') + t.is(list.children[1].style.display, 'block') }) diff --git a/source/connector-mobilizon/front/events-displayer.js b/source/connector-mobilizon/front/events-displayer.js index dde67dd..3cd4888 100644 --- a/source/connector-mobilizon/front/events-displayer.js +++ b/source/connector-mobilizon/front/events-displayer.js @@ -47,5 +47,13 @@ export function displayEvents({ data, document, list }) { export function displayErrorMessage({ data, list }) { console.error(data) - list.children[0].style.display = 'block' + if (Object.prototype.hasOwnProperty.call(data, 'response') && + Object.prototype.hasOwnProperty.call(data.response, 'errors') && + data.response.errors.length > 0 && + Object.prototype.hasOwnProperty.call(data.response.errors[0], 'code') && + data.response.errors[0].code === 'group_not_found') { + list.children[1].style.display = 'block' + } else { + list.children[0].style.display = 'block' + } } diff --git a/source/connector-mobilizon/view/events-list.php b/source/connector-mobilizon/view/events-list.php index 739e146..6f9c358 100644 --- a/source/connector-mobilizon/view/events-list.php +++ b/source/connector-mobilizon/view/events-list.php @@ -12,4 +12,5 @@ if (!defined('ABSPATH')) { data-time-zone="" >
  • +