|
| 1 | +/** |
| 2 | + * @jest-environment jsdom |
| 3 | + */ |
| 4 | + |
| 5 | +"use strict"; |
| 6 | + |
| 7 | +describe('Isso read-only mode', () => { |
| 8 | + beforeEach(() => { |
| 9 | + jest.resetModules(); |
| 10 | + |
| 11 | + // globals.offset.localTime() will be passed to i18n.ago() |
| 12 | + // localTime param will then be called as localTime.getTime() |
| 13 | + jest.mock('app/globals', () => ({ |
| 14 | + offset: { |
| 15 | + localTime: jest.fn(() => ({ |
| 16 | + getTime: jest.fn(() => 0), |
| 17 | + })), |
| 18 | + }, |
| 19 | + })); |
| 20 | + |
| 21 | + document.body.innerHTML = |
| 22 | + '<div id="isso-thread"></div>' + |
| 23 | + '<script src="http://isso.api/js/embed.min.js"' + |
| 24 | + ' data-isso="/"' + |
| 25 | + ' data-isso-read-only="true"></script>'; |
| 26 | + }); |
| 27 | + |
| 28 | + test('should not render postbox in read-only mode', () => { |
| 29 | + const $ = require("app/dom"); |
| 30 | + const config = require("app/config"); |
| 31 | + const template = require("app/template"); |
| 32 | + const i18n = require("app/i18n"); |
| 33 | + const svg = require("app/svg"); |
| 34 | + |
| 35 | + template.set("conf", config); |
| 36 | + template.set("i18n", i18n.translate); |
| 37 | + template.set("pluralize", i18n.pluralize); |
| 38 | + template.set("svg", svg); |
| 39 | + |
| 40 | + let isso_thread = $('#isso-thread'); |
| 41 | + isso_thread.append('<div id="isso-root"></div>'); |
| 42 | + |
| 43 | + expect($('.isso-postbox')).toBeNull(); |
| 44 | + }); |
| 45 | + |
| 46 | + test('should not render reply, edit, and delete buttons in read-only mode', () => { |
| 47 | + const isso = require("app/isso"); |
| 48 | + const $ = require("app/dom"); |
| 49 | + const config = require("app/config"); |
| 50 | + const template = require("app/template"); |
| 51 | + const i18n = require("app/i18n"); |
| 52 | + const svg = require("app/svg"); |
| 53 | + |
| 54 | + template.set("conf", config); |
| 55 | + template.set("i18n", i18n.translate); |
| 56 | + template.set("pluralize", i18n.pluralize); |
| 57 | + template.set("svg", svg); |
| 58 | + |
| 59 | + let isso_thread = $('#isso-thread'); |
| 60 | + isso_thread.append('<div id="isso-root"></div>'); |
| 61 | + |
| 62 | + // Simulate a comment object |
| 63 | + let comment = { |
| 64 | + id: 1, |
| 65 | + hash: "abc123", |
| 66 | + author: "TestUser", |
| 67 | + website: null, |
| 68 | + created: 1651788192.4473603, |
| 69 | + mode: 1, |
| 70 | + text: "Test comment", |
| 71 | + likes: 0, |
| 72 | + dislikes: 0, |
| 73 | + replies: [], |
| 74 | + hidden_replies: 0, |
| 75 | + parent: null |
| 76 | + }; |
| 77 | + |
| 78 | + // Render comment |
| 79 | + isso.insert({comment, scrollIntoView: false, offset: 0}); |
| 80 | + |
| 81 | + // Verify that interactive buttons are not rendered in read-only mode |
| 82 | + expect($('a.isso-reply')).toBeNull(); |
| 83 | + expect($('a.isso-edit')).toBeNull(); |
| 84 | + expect($('a.isso-delete')).toBeNull(); |
| 85 | + }); |
| 86 | +}); |
0 commit comments