|
1 | | -const { describe, it, expect, request, db, locale, checks, auth } = require('../base'); |
| 1 | +const { describe, it, expect, request, db, locale, checks, auth, dom } = require('../base'); |
2 | 2 |
|
3 | 3 | describe('/lists', () => { |
4 | 4 | describe('GET', () => { |
5 | | - const test = () => request().get('/lists'); |
6 | | - it('returns an OK status code', done => { |
7 | | - test().end((err, res) => { |
8 | | - expect(res).to.have.status(200); |
| 5 | + let res, page; |
| 6 | + before('fetch the page', done => { |
| 7 | + request().get('/lists').end((_, r) => { |
| 8 | + res = r; |
| 9 | + page = dom(r); |
9 | 10 | done(); |
10 | 11 | }); |
11 | 12 | }); |
| 13 | + it('returns an OK status code', done => { |
| 14 | + expect(res).to.have.status(200); |
| 15 | + done(); |
| 16 | + }); |
12 | 17 | it('has the correct page title', done => { |
13 | | - test().end((err, res) => { |
14 | | - expect(res).to.be.html; |
15 | | - checks.title(res, `All Bot Lists - ${locale('site_name')} - ${locale('short_desc')}`); |
16 | | - done(); |
17 | | - }); |
| 18 | + checks.title(res, `All Bot Lists - ${locale('site_name')} - ${locale('short_desc')}`); |
| 19 | + done(); |
18 | 20 | }); |
19 | | - it('renders the expected content', done => { |
20 | | - db.select('name', 'url').from('lists').where({ display: true, defunct: false }).then(lists => { |
21 | | - test().end((err, res) => { |
22 | | - expect(res).to.be.html; |
23 | 21 |
|
24 | | - // Confirm header |
25 | | - expect(res.text).to.include('All Bot Lists'); |
26 | | - |
27 | | - // Confirm footer stats |
28 | | - expect(res.text).to.include(`${locale('site_name')} - Bot List Stats`); |
| 22 | + describe('renders the expected content', () => { |
| 23 | + it('has the correct title', done => { |
| 24 | + expect(res.text).to.include('All Bot Lists'); |
| 25 | + done(); |
| 26 | + }); |
| 27 | + it('has the stats footer', done => { |
| 28 | + const footer = page.querySelector(".hero.card .hero-body.hero-stats.card-body"); |
| 29 | + expect(footer).to.exist; |
| 30 | + expect(footer.innerHTML).to.include(`${locale('site_name')} - Bot List Stats`); |
| 31 | + done(); |
| 32 | + }); |
29 | 33 |
|
30 | | - // Confirm list cards |
31 | | - lists.forEach(list => { |
| 34 | + describe('contains the list cards', () => { |
| 35 | + let listCards; |
| 36 | + before('fetch list cards', done => { |
| 37 | + db.select('id', 'name', 'url').from('lists').where({ display: true, defunct: false }).then(lists => { |
| 38 | + listCards = lists; |
| 39 | + done(); |
| 40 | + }); |
| 41 | + }); |
| 42 | + it('has the list names', done => { |
| 43 | + listCards.forEach(list => { |
32 | 44 | expect(res.text).to.include(list.name); |
| 45 | + }); |
| 46 | + done(); |
| 47 | + }); |
| 48 | + it('has the list urls', done => { |
| 49 | + listCards.forEach(list => { |
33 | 50 | expect(res.text).to.include(list.url); |
34 | 51 | }); |
35 | | - |
| 52 | + done(); |
| 53 | + }); |
| 54 | + it('has the list information button', done => { |
| 55 | + listCards.forEach(list => { |
| 56 | + expect(page.querySelector(`.card a.button[href="/lists/${list.id}"]`)).to.exist; |
| 57 | + }); |
36 | 58 | done(); |
37 | 59 | }); |
38 | 60 | }); |
|
0 commit comments