|
| 1 | +// Libraries |
| 2 | +const fs = require('fs'); |
| 3 | +const jsdom = require('jsdom'); |
| 4 | +const { assert } = require('chai'); |
| 5 | + |
| 6 | +// HTML |
| 7 | +const srcHtml = fs.readFileSync('./src/index.html'); |
| 8 | +const doc = jsdom.jsdom(srcHtml); |
| 9 | + |
| 10 | +// Tests |
| 11 | +describe('The webpage', () => { |
| 12 | + |
| 13 | + /** |
| 14 | + * HEADER |
| 15 | + */ |
| 16 | + describe('header', () => { |
| 17 | + it('should exist @header', () => { |
| 18 | + const header = doc.querySelector('.header'); |
| 19 | + assert.isOk(header, 'We need a `.header` element.'); |
| 20 | + }); |
| 21 | + |
| 22 | + it('should have a non-empty title @h1', () => { |
| 23 | + const h1 = doc.querySelector('.header h1'); |
| 24 | + assert.isOk(h1, 'We need an `h1` element inside `.header`.'); |
| 25 | + assert.isOk(h1.textContent, 'Our header\'s `h1` element cannot be empty.'); |
| 26 | + }); |
| 27 | + |
| 28 | + it('should have a non-empty description @h2', () => { |
| 29 | + const h2 = doc.querySelector('.header h2'); |
| 30 | + assert.isOk(h2, 'We need an `h2` element inside `.header`.'); |
| 31 | + assert.isOk(h2.textContent, 'Our header\'s `h2` element cannot be empty.'); |
| 32 | + }); |
| 33 | + }); |
| 34 | + |
| 35 | + |
| 36 | + /** |
| 37 | + * TAGLINE |
| 38 | + */ |
| 39 | + describe('tagline', () => { |
| 40 | + it('should exist @tagline', () => { |
| 41 | + const tagline = doc.querySelector('.tagline'); |
| 42 | + assert.isOk(tagline, 'We need a `.tagline` element.'); |
| 43 | + }); |
| 44 | + |
| 45 | + it('should have a non-empty h3 tag @tagline-content', () => { |
| 46 | + const h3 = doc.querySelector('.tagline h3'); |
| 47 | + assert.isOk(h3, 'We need an `h3` element inside `.tagline`.'); |
| 48 | + assert.isOk(h3.textContent, 'Our tagline\'s `h3` element cannot be empty.'); |
| 49 | + }); |
| 50 | + |
| 51 | + it('should have a descriptive paragraph @tagline-content', () => { |
| 52 | + const p = doc.querySelector('.tagline p'); |
| 53 | + assert.isOk(p, 'We need a `p` element inside `.tagline`.'); |
| 54 | + assert.isOk(p.textContent, 'Our tagline\'s `p` element cannot be empty.'); |
| 55 | + }); |
| 56 | + }); |
| 57 | + |
| 58 | + |
| 59 | + /** |
| 60 | + * SKILLS |
| 61 | + */ |
| 62 | + describe('skills', () => { |
| 63 | + it('should exist @skills', () => { |
| 64 | + const skills = doc.querySelector('.skills'); |
| 65 | + assert.isOk(skills, 'We need a `.skills` element.'); |
| 66 | + }); |
| 67 | + |
| 68 | + it('should have a non-empty h3 tag @skills-content', () => { |
| 69 | + const h3 = doc.querySelector('.skills h3'); |
| 70 | + assert.isOk(h3, 'We need an `h3` element inside `.skills`.'); |
| 71 | + assert.isOk(h3.textContent, 'Our skills\' `h3` element cannot be empty.'); |
| 72 | + }); |
| 73 | + |
| 74 | + it('should have a descriptive paragraph @skills-content', () => { |
| 75 | + const p = doc.querySelector('.skills p'); |
| 76 | + assert.isOk(p, 'We need a `p` element inside `.skills`.'); |
| 77 | + assert.isOk(p.textContent, 'Our skills\' `p` element cannot be empty.'); |
| 78 | + }); |
| 79 | + |
| 80 | + it('should have an unordered list of your skills @skills-list', () => { |
| 81 | + const ul = doc.querySelector('.skills ul'); |
| 82 | + assert.isOk(ul, 'We need a `ul` element inside `.skills`.'); |
| 83 | + }); |
| 84 | + |
| 85 | + it('should have at least 3 skills @skills-list', () => { |
| 86 | + const skillItems = doc.querySelectorAll('.skills ul li'); |
| 87 | + assert.isAtLeast(skillItems.length, 3, 'We need at least 3 `li` elements inside the skills\' `ul`.'); |
| 88 | + }); |
| 89 | + |
| 90 | + it('should have one skill that contains HTML @skills-list', () => { |
| 91 | + const skillItems = Array.from(doc.querySelectorAll('.skills ul li')); |
| 92 | + const htmlRegex = /html/i; |
| 93 | + |
| 94 | + const skillsWithHtml = skillItems |
| 95 | + .map(li => li.textContent) |
| 96 | + .filter(skill => htmlRegex.test(skill)); |
| 97 | + |
| 98 | + assert.equal(skillsWithHtml.length, 1, 'HTML needs be part of one of your skills.'); |
| 99 | + }); |
| 100 | + }); |
| 101 | + |
| 102 | + |
| 103 | + /** |
| 104 | + * CONTACT |
| 105 | + */ |
| 106 | + describe('contact', () => { |
| 107 | + it('should exist @contact', () => { |
| 108 | + const contact = doc.querySelector('.contact'); |
| 109 | + assert.isOk(contact, 'We need a `.contact` element.'); |
| 110 | + }); |
| 111 | + |
| 112 | + it('should have a non-empty h3 tag @contact-content', () => { |
| 113 | + const h3 = doc.querySelector('.contact h3'); |
| 114 | + assert.isOk(h3, 'We need an `h3` element inside `.contact`.'); |
| 115 | + assert.isOk(h3.textContent, 'Our contact\'s `h3` element cannot be empty.'); |
| 116 | + }); |
| 117 | + |
| 118 | + it('should have a descriptive paragraph @contact-content', () => { |
| 119 | + const p = doc.querySelector('.contact p'); |
| 120 | + assert.isOk(p, 'We need a `p` element inside `.contact`.'); |
| 121 | + assert.isOk(p.textContent, 'Our contact\'s `p` element cannot be empty.'); |
| 122 | + }); |
| 123 | + |
| 124 | + it('should have a link with an href within the paragraph @contact-link', () => { |
| 125 | + const a = doc.querySelector('.contact p a'); |
| 126 | + assert.isOk(a, 'We need a `a` element our inside contact\'s `p` element.'); |
| 127 | + assert.isOk(a.textContent, 'Our contact\'s `a` element cannot be empty.'); |
| 128 | + assert.isOk(a.getAttribute('href'), 'Our contact\'s `a` element needs a non-empty `href` attribute.'); |
| 129 | + }); |
| 130 | + }); |
| 131 | + |
| 132 | +}); |
0 commit comments