|
| 1 | +const { describe, it } = require('mocha'); |
1 | 2 | const { expect } = require('chai');
|
2 | 3 | const locale = require('../../src/Util/i18n').__;
|
3 | 4 | const { resetRatelimits } = require('./ratelimits');
|
| 5 | +const fetchPage = require('./fetchPage'); |
| 6 | +const auth = require('./auth'); |
4 | 7 |
|
5 | 8 | const ratelimit = (context, limit, test, done, status = 200) => {
|
6 | 9 | context.retries(0);
|
@@ -44,4 +47,130 @@ const title = (res, expectedTitle) => {
|
44 | 47 | expect(res.text).to.include(`<meta name="twitter:description" content="${locale('full_desc')}">`);
|
45 | 48 | };
|
46 | 49 |
|
47 |
| -module.exports = { ratelimit, authRequired, title }; |
| 50 | +const meta = expectedTitle => { |
| 51 | + describe('has the correct page metadata', () => { |
| 52 | + it('is a valid HTML page', function (done) { |
| 53 | + expect(this.res).to.be.html; |
| 54 | + done(); |
| 55 | + }); |
| 56 | + it('has the correct title', function (done) { |
| 57 | + const title = this.page.querySelector('title'); |
| 58 | + expect(title).to.exist; |
| 59 | + expect(title.textContent).to.eq(expectedTitle); |
| 60 | + done(); |
| 61 | + }); |
| 62 | + it('has the correct description', function (done) { |
| 63 | + const description = this.page.querySelector('meta[name="description"]'); |
| 64 | + expect(description).to.exist; |
| 65 | + expect(description.hasAttribute('content')).to.be.true; |
| 66 | + expect(description.getAttribute('content')).to.eq(`${locale('site_name')} - ${locale('full_desc')}`); |
| 67 | + done(); |
| 68 | + }); |
| 69 | + describe('OpenGraph', () => { |
| 70 | + it('has the correct title', function (done) { |
| 71 | + const title = this.page.querySelector('meta[property="og:title"]'); |
| 72 | + expect(title).to.exist; |
| 73 | + expect(title.hasAttribute('content')).to.be.true; |
| 74 | + expect(title.getAttribute('content')).to.eq(expectedTitle); |
| 75 | + done(); |
| 76 | + }); |
| 77 | + it('has the correct site name', function (done) { |
| 78 | + const title = this.page.querySelector('meta[property="og:site_name"]'); |
| 79 | + expect(title).to.exist; |
| 80 | + expect(title.hasAttribute('content')).to.be.true; |
| 81 | + expect(title.getAttribute('content')).to.eq(locale('site_name')); |
| 82 | + done(); |
| 83 | + }); |
| 84 | + it('has the correct description', function (done) { |
| 85 | + const description = this.page.querySelector('meta[property="og:description"]'); |
| 86 | + expect(description).to.exist; |
| 87 | + expect(description.hasAttribute('content')).to.be.true; |
| 88 | + expect(description.getAttribute('content')).to.eq(locale('full_desc')); |
| 89 | + done(); |
| 90 | + }); |
| 91 | + }); |
| 92 | + describe('Twitter', () => { |
| 93 | + it('has the correct title', function (done) { |
| 94 | + const title = this.page.querySelector('meta[name="twitter:title"]'); |
| 95 | + expect(title).to.exist; |
| 96 | + expect(title.hasAttribute('content')).to.be.true; |
| 97 | + expect(title.getAttribute('content')).to.eq(expectedTitle); |
| 98 | + done(); |
| 99 | + }); |
| 100 | + it('has the correct description', function (done) { |
| 101 | + const description = this.page.querySelector('meta[name="twitter:description"]'); |
| 102 | + expect(description).to.exist; |
| 103 | + expect(description.hasAttribute('content')).to.be.true; |
| 104 | + expect(description.getAttribute('content')).to.eq(locale('full_desc')); |
| 105 | + done(); |
| 106 | + }); |
| 107 | + }); |
| 108 | + }); |
| 109 | +}; |
| 110 | + |
| 111 | +const listCards = (test, db, where) => { |
| 112 | + describe('contains the list cards', () => { |
| 113 | + fetchPage(test); |
| 114 | + |
| 115 | + before('fetch list cards', function(done) { |
| 116 | + db.select('id', 'name', 'url').from('lists').where(where).then(lists => { |
| 117 | + this.listCards = lists; |
| 118 | + done(); |
| 119 | + }); |
| 120 | + }); |
| 121 | + |
| 122 | + it('has the list names', function(done) { |
| 123 | + this.listCards.forEach(list => { |
| 124 | + expect(this.res.text).to.include(list.name); |
| 125 | + }); |
| 126 | + done(); |
| 127 | + }); |
| 128 | + it('has the list urls', function(done) { |
| 129 | + this.listCards.forEach(list => { |
| 130 | + expect(this.res.text).to.include(list.url); |
| 131 | + }); |
| 132 | + done(); |
| 133 | + }); |
| 134 | + |
| 135 | + describe('card buttons', () => { |
| 136 | + it('has the list information button', function(done) { |
| 137 | + this.listCards.forEach(list => { |
| 138 | + expect(this.page.querySelector(`.card a.button[href="/lists/${list.id}"]`)).to.exist; |
| 139 | + }); |
| 140 | + done(); |
| 141 | + }); |
| 142 | + |
| 143 | + describe('as an anonymous user', () => { |
| 144 | + fetchPage(() => auth.asAnon(test())); |
| 145 | + it('does not have the edit button', function(done) { |
| 146 | + this.listCards.forEach(list => { |
| 147 | + expect(this.page.querySelector(`.card a.button[href="/lists/${list.id}/edit"]`)).to.not.exist; |
| 148 | + }); |
| 149 | + done(); |
| 150 | + }); |
| 151 | + }); |
| 152 | + |
| 153 | + describe('as a logged in user', () => { |
| 154 | + fetchPage(() => auth.asUser(test())); |
| 155 | + it('does not have the edit button', function(done) { |
| 156 | + this.listCards.forEach(list => { |
| 157 | + expect(this.page.querySelector(`.card a.button[href="/lists/${list.id}/edit"]`)).to.not.exist; |
| 158 | + }); |
| 159 | + done(); |
| 160 | + }); |
| 161 | + }); |
| 162 | + |
| 163 | + describe('as a moderator', () => { |
| 164 | + fetchPage(() => auth.asMod(test())); |
| 165 | + it('has the edit button', function(done) { |
| 166 | + this.listCards.forEach(list => { |
| 167 | + expect(this.page.querySelector(`.card a.button[href="/lists/${list.id}/edit"]`)).to.exist; |
| 168 | + }); |
| 169 | + done(); |
| 170 | + }); |
| 171 | + }); |
| 172 | + }); |
| 173 | + }); |
| 174 | +}; |
| 175 | + |
| 176 | +module.exports = { ratelimit, authRequired, title, meta, listCards }; |
0 commit comments