2021-05-05 10:02:57 +02:00
|
|
|
import test from 'ava'
|
2022-06-03 23:48:19 +02:00
|
|
|
import browserEnv from 'browser-env'
|
2021-05-05 10:02:57 +02:00
|
|
|
|
2022-06-03 23:48:19 +02:00
|
|
|
import {
|
|
|
|
displayEvents,
|
|
|
|
displayErrorMessage,
|
|
|
|
hideErrorMessages,
|
|
|
|
showLoadingIndicator,
|
|
|
|
} from './events-displayer.js'
|
2021-05-05 10:02:57 +02:00
|
|
|
|
|
|
|
test.before(() => {
|
2022-06-03 23:48:19 +02:00
|
|
|
browserEnv()
|
|
|
|
window.MOBILIZON_CONNECTOR = {
|
|
|
|
locale: 'en-GB',
|
|
|
|
timeZone: 'utc',
|
|
|
|
}
|
2021-05-05 10:02:57 +02:00
|
|
|
})
|
|
|
|
|
2021-12-09 19:46:19 +01:00
|
|
|
test.beforeEach((t) => {
|
2022-06-03 23:48:19 +02:00
|
|
|
t.context.container = document.createElement('div')
|
|
|
|
t.context.container.setAttribute('data-maximum', '2')
|
|
|
|
|
|
|
|
const errorMessageGeneral = document.createElement('div')
|
|
|
|
errorMessageGeneral.setAttribute('class', 'general-error')
|
|
|
|
errorMessageGeneral.setAttribute('style', 'display: none;')
|
|
|
|
t.context.container.appendChild(errorMessageGeneral)
|
|
|
|
|
|
|
|
const errorMessageGroupNotFound = document.createElement('div')
|
|
|
|
errorMessageGroupNotFound.setAttribute('class', 'group-not-found')
|
|
|
|
errorMessageGroupNotFound.setAttribute('style', 'display: none;')
|
|
|
|
t.context.container.appendChild(errorMessageGroupNotFound)
|
|
|
|
|
|
|
|
const loadingIndicator = document.createElement('div')
|
|
|
|
loadingIndicator.setAttribute('class', 'loading-indicator')
|
|
|
|
loadingIndicator.setAttribute('style', 'display: none;')
|
|
|
|
t.context.container.appendChild(loadingIndicator)
|
|
|
|
|
|
|
|
const list = document.createElement('ul')
|
|
|
|
t.context.container.appendChild(list)
|
2021-05-05 10:02:57 +02:00
|
|
|
})
|
|
|
|
|
2021-12-09 19:46:19 +01:00
|
|
|
test('#displayEvents one event', (t) => {
|
2021-05-05 10:02:57 +02:00
|
|
|
const data = {
|
|
|
|
events: {
|
|
|
|
elements: [
|
|
|
|
{
|
|
|
|
title: 'a',
|
|
|
|
url: 'b',
|
|
|
|
beginsOn: '2021-04-15T10:30:00Z',
|
|
|
|
endsOn: '2021-04-15T15:30:00Z',
|
|
|
|
physicalAddress: {
|
|
|
|
description: 'c',
|
2021-12-09 19:46:19 +01:00
|
|
|
locality: 'd',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2021-05-05 10:02:57 +02:00
|
|
|
}
|
2022-06-03 23:48:19 +02:00
|
|
|
const container = t.context.container
|
|
|
|
displayEvents({ data, document, container })
|
|
|
|
const list = container.querySelector('ul')
|
|
|
|
t.is(list.children[0].childNodes[0].tagName, 'A')
|
|
|
|
t.is(list.children[0].childNodes[0].getAttribute('href'), 'b')
|
|
|
|
t.is(list.children[0].childNodes[0].childNodes[0].nodeValue, 'a')
|
|
|
|
t.is(list.children[0].childNodes[1].tagName, 'BR')
|
|
|
|
t.is(list.children[0].childNodes[2].nodeValue, '15/04/2021 10:30 - 15:30')
|
|
|
|
t.is(list.children[0].childNodes[3].tagName, 'BR')
|
|
|
|
t.is(list.children[0].childNodes[4].nodeValue, 'c, d')
|
2021-05-05 10:02:57 +02:00
|
|
|
})
|
|
|
|
|
2022-06-03 23:48:19 +02:00
|
|
|
test('#displayErrorMessage no list entries shown', (t) => {
|
|
|
|
const container = t.context.container
|
|
|
|
displayErrorMessage({ data: '', container })
|
|
|
|
const list = container.querySelector('ul')
|
|
|
|
t.is(list.children.length, 0)
|
2021-05-05 10:02:57 +02:00
|
|
|
})
|
|
|
|
|
2022-06-03 23:48:19 +02:00
|
|
|
test('#displayErrorMessage general error message display', (t) => {
|
|
|
|
const container = t.context.container
|
|
|
|
displayErrorMessage({ data: '', container })
|
|
|
|
t.is(container.querySelector('.general-error').style.display, 'block')
|
|
|
|
t.is(container.querySelector('.group-not-found').style.display, 'none')
|
|
|
|
t.is(container.querySelector('.loading-indicator').style.display, 'none')
|
2021-12-09 19:02:49 +01:00
|
|
|
})
|
|
|
|
|
2021-12-09 19:46:19 +01:00
|
|
|
test('#displayErrorMessage group not found error message display', (t) => {
|
2022-06-03 23:48:19 +02:00
|
|
|
const container = t.context.container
|
2021-12-09 19:05:29 +01:00
|
|
|
const data = {
|
|
|
|
response: {
|
|
|
|
errors: [
|
|
|
|
{
|
2021-12-09 19:46:19 +01:00
|
|
|
code: 'group_not_found',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2021-12-09 19:05:29 +01:00
|
|
|
}
|
2022-06-03 23:48:19 +02:00
|
|
|
displayErrorMessage({ data, container })
|
|
|
|
t.is(container.querySelector('.general-error').style.display, 'none')
|
|
|
|
t.is(container.querySelector('.group-not-found').style.display, 'block')
|
|
|
|
t.is(container.querySelector('.loading-indicator').style.display, 'none')
|
|
|
|
})
|
|
|
|
|
|
|
|
test('#showLoadingIndicator remove events', (t) => {
|
|
|
|
const container = t.context.container
|
|
|
|
const loadingIndicator = container.querySelector('.loading-indicator')
|
|
|
|
t.is(loadingIndicator.style.display, 'none')
|
|
|
|
showLoadingIndicator(container)
|
|
|
|
t.is(loadingIndicator.style.display, 'block')
|
|
|
|
})
|
|
|
|
|
|
|
|
test('#hideErrorMessages remove events', (t) => {
|
|
|
|
const container = t.context.container
|
|
|
|
const generalErrorMessage = container.querySelector('.general-error')
|
|
|
|
const groupNotFoundErrorMessage = container.querySelector('.group-not-found')
|
|
|
|
generalErrorMessage.style.display = 'block'
|
|
|
|
groupNotFoundErrorMessage.style.display = 'block'
|
|
|
|
t.is(generalErrorMessage.style.display, 'block')
|
|
|
|
t.is(groupNotFoundErrorMessage.style.display, 'block')
|
|
|
|
hideErrorMessages(container)
|
|
|
|
t.is(generalErrorMessage.style.display, 'none')
|
|
|
|
t.is(groupNotFoundErrorMessage.style.display, 'none')
|
2021-05-05 10:02:57 +02:00
|
|
|
})
|