|
| 1 | +/** |
| 2 | + * @jest-environment jsdom |
| 3 | + */ |
| 4 | + |
| 5 | +/* Keep the above exactly as-is! |
| 6 | + * https://jestjs.io/docs/configuration#testenvironment-string |
| 7 | + * https://jestjs.io/docs/configuration#testenvironmentoptions-object |
| 8 | + */ |
| 9 | + |
| 10 | +"use strict"; |
| 11 | + |
| 12 | +beforeEach(() => { |
| 13 | + jest.resetModules(); |
| 14 | + document.body.innerHTML = ''; |
| 15 | +}); |
| 16 | + |
| 17 | +test('Website field hidden when website-field=false', () => { |
| 18 | + document.body.innerHTML = |
| 19 | + '<div id="isso-thread"></div>' + |
| 20 | + '<script src="http://isso.api/js/embed.min.js" data-isso="/"></script>'; |
| 21 | + |
| 22 | + const isso = require("app/isso"); |
| 23 | + const $ = require("app/dom"); |
| 24 | + |
| 25 | + const config = Object.assign({}, require("app/config"), {'website-field': false}); |
| 26 | + |
| 27 | + const i18n = require("app/i18n"); |
| 28 | + const svg = require("app/svg"); |
| 29 | + const template = require("app/template"); |
| 30 | + |
| 31 | + template.set("conf", config); |
| 32 | + template.set("i18n", i18n.translate); |
| 33 | + template.set("pluralize", i18n.pluralize); |
| 34 | + template.set("svg", svg); |
| 35 | + |
| 36 | + const isso_thread = $('#isso-thread'); |
| 37 | + isso_thread.append('<div id="isso-root"></div>'); |
| 38 | + isso_thread.append(new isso.Postbox(null)); |
| 39 | + |
| 40 | + // Website input should not be present |
| 41 | + expect(document.querySelector('#isso-postbox-website')).toBeNull(); |
| 42 | + expect(document.querySelector('[name=website]')).toBeNull(); |
| 43 | + |
| 44 | + // Author and email fields should still be present |
| 45 | + expect(document.querySelector('#isso-postbox-author')).not.toBeNull(); |
| 46 | + expect(document.querySelector('#isso-postbox-email')).not.toBeNull(); |
| 47 | +}); |
| 48 | + |
| 49 | +test('Website field shown when website-field=true (default)', () => { |
| 50 | + document.body.innerHTML = |
| 51 | + '<div id="isso-thread"></div>' + |
| 52 | + '<script src="http://isso.api/js/embed.min.js" data-isso="/"></script>'; |
| 53 | + |
| 54 | + const isso = require("app/isso"); |
| 55 | + const $ = require("app/dom"); |
| 56 | + |
| 57 | + const config = Object.assign({}, require("app/config"), {'website-field': true}); |
| 58 | + |
| 59 | + const i18n = require("app/i18n"); |
| 60 | + const svg = require("app/svg"); |
| 61 | + const template = require("app/template"); |
| 62 | + |
| 63 | + template.set("conf", config); |
| 64 | + template.set("i18n", i18n.translate); |
| 65 | + template.set("pluralize", i18n.pluralize); |
| 66 | + template.set("svg", svg); |
| 67 | + |
| 68 | + const isso_thread = $('#isso-thread'); |
| 69 | + isso_thread.append('<div id="isso-root"></div>'); |
| 70 | + isso_thread.append(new isso.Postbox(null)); |
| 71 | + |
| 72 | + // Website input should be present |
| 73 | + expect(document.querySelector('#isso-postbox-website')).not.toBeNull(); |
| 74 | + expect(document.querySelector('[name=website]')).not.toBeNull(); |
| 75 | +}); |
0 commit comments