connector-wordpress/source/front/events-displayer-test.js

82 lines
2.3 KiB
JavaScript
Raw Normal View History

2021-05-05 10:02:57 +02:00
import test from 'ava'
import { JSDOM } from 'jsdom'
import { displayEvents, displayErrorMessage } from './events-displayer.js'
2021-05-05 10:02:57 +02:00
let document
test.before(() => {
document = new JSDOM().window.document
})
2021-12-09 19:46:19 +01:00
test.beforeEach((t) => {
2021-05-05 10:02:57 +02:00
t.context.list = document.createElement('ul')
t.context.list.setAttribute('data-locale', 'en-GB')
t.context.list.setAttribute('data-maximum', '2')
t.context.list.setAttribute('data-time-zone', 'utc')
2021-05-05 10:02:57 +02:00
const listElement = document.createElement('li')
listElement.setAttribute('style', 'display: none;')
t.context.list.appendChild(listElement)
2021-12-09 19:02:49 +01:00
const listElement2 = document.createElement('li')
listElement2.setAttribute('style', 'display: none;')
t.context.list.appendChild(listElement2)
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 list = t.context.list
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
}
displayEvents({ data, document, list })
2021-12-09 19:02:49 +01:00
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')
2021-05-05 10:02:57 +02:00
})
2021-12-09 19:46:19 +01:00
test('#displayErrorMessage no children added', (t) => {
2021-05-05 10:02:57 +02:00
const list = t.context.list
displayErrorMessage({ data: '', list })
2021-12-09 19:02:49 +01:00
t.is(list.children.length, 2)
2021-05-05 10:02:57 +02:00
})
2021-12-09 19:46:19 +01:00
test('#displayErrorMessage error message display', (t) => {
2021-05-05 10:02:57 +02:00
const list = t.context.list
displayErrorMessage({ data: '', list })
t.is(list.children[0].style.display, 'block')
2021-12-09 19:02:49 +01:00
t.is(list.children[1].style.display, 'none')
})
2021-12-09 19:46:19 +01:00
test('#displayErrorMessage group not found error message display', (t) => {
2021-12-09 19:02:49 +01:00
const list = t.context.list
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
}
displayErrorMessage({ data, list })
2021-12-09 19:02:49 +01:00
t.is(list.children[0].style.display, 'none')
t.is(list.children[1].style.display, 'block')
2021-05-05 10:02:57 +02:00
})