Skip to content

Commit

Permalink
js: tests/unit: Add test for Postbox labels
Browse files Browse the repository at this point in the history
Should vanish when `require-author`/email is set in config.
  • Loading branch information
ix5 committed May 5, 2022
1 parent ff51892 commit 3980b1e
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions isso/js/tests/unit/postbox-labels-optional.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* @jest-environment jsdom
*/

/* Keep the above exactly as-is!
* https://jestjs.io/docs/configuration#testenvironment-string
* https://jestjs.io/docs/configuration#testenvironmentoptions-object
*/

"use strict";

test('"(optional)" labels in Postox vanish if require-author/-email set', () => {
// Set up our document body
document.body.innerHTML =
'<div id=isso-thread></div>' +
'<script src="http://isso.api/js/embed.min.js"'
+ 'data-isso="/"'
+ 'data-isso-lang="de"' // falls back to "en" for placeholders
+ '></script>';

const isso = require("app/isso");
const $ = require("app/dom");

var config = require("app/config");
config['require-author'] = true;
config['require-email'] = true;

const i18n = require("app/i18n");
const svg = require("app/svg");

const template = require("app/template");

template.set("conf", config);
template.set("i18n", i18n.translate);
template.set("pluralize", i18n.pluralize);
template.set("svg", svg);

var isso_thread = $('#isso-thread');
isso_thread.append('<div id="isso-root"></div>');
isso_thread.append(new isso.Postbox(null));

expect($("#isso-postbox-author").placeholder).toBe('John Doe');
expect($("#isso-postbox-email").placeholder).toBe('[email protected]');
// Instead of "Name (optional)"
expect($("[for='isso-postbox-author']").textContent).toBe('Name');
// Instead of "E-mail (optional)"
expect($("[for='isso-postbox-email']").textContent).toBe('E-Mail');
});

0 comments on commit 3980b1e

Please sign in to comment.