add group not found error message #11

This commit is contained in:
Daniel Waxweiler 2021-12-09 19:02:49 +01:00
parent 80dd0c9c50
commit 34aaaa7db9
4 changed files with 31 additions and 10 deletions

View File

@ -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

View File

@ -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')
})

View File

@ -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'
}
}

View File

@ -12,4 +12,5 @@ if (!defined('ABSPATH')) {
data-time-zone="<?php echo esc_attr($timeZone); ?>"
<?php echo $isShortOffsetNameShown ? 'data-is-short-offset-name-shown' : ''; ?>>
<li style="display: none;"><?php esc_html_e('The events could not be loaded!', 'connector-mobilizon'); ?></li>
<li style="display: none;"><?php esc_html_e('The group could not be found!', 'connector-mobilizon'); ?></li>
</ul>