/
embedded-comments-category-refs.2browsers.test.ts
265 lines (202 loc) · 8.2 KB
/
embedded-comments-category-refs.2browsers.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/// <reference path="../test-types.ts"/>
import * as _ from 'lodash';
import assert = require('../utils/ty-assert');
import fs = require('fs');
import server = require('../utils/server');
import utils = require('../utils/utils');
import { buildSite } from '../utils/site-builder';
import { TyE2eTestBrowser, TyAllE2eTestBrowsers } from '../utils/pages-for';
import settings = require('../utils/settings');
import lad = require('../utils/log-and-die');
import c = require('../test-constants');
let richBrowserA: TyE2eTestBrowser;
let richBrowserB: TyE2eTestBrowser;
let owen: Member;
let owensBrowser: TyE2eTestBrowser;
let maria: Member;
let mariasBrowser: TyE2eTestBrowser;
let siteIdAddress: IdAddress;
let siteId: SiteId;
let forum: TwoPagesTestForum;
const localHostname = 'comments-for-e2e-test-custcat-localhost-8080';
const embeddingOrigin = 'http://e2e-test-custcat.localhost:8080';
let catB: CategoryJustAdded;
const catBId = 5;
const catBExtId = 'cat_b_ext_id-with-dashes';
let catC: CategoryJustAdded;
const catCId = 6;
const catCExtId = 'cat_c_ext_id';
let catD: CategoryJustAdded;
const catDId = 7;
const catDExtId = 'cat_d_ext_id';
// Cat wit notfs.
let catN: CategoryJustAdded;
const catNId = 8;
const catNExtId = 'cat NN ext id w spaces';
const staffCatExtId = 'staff cat ext id';;
const pageNoCatSlug = 'cats-nocat.html';
const pageBbbSlug = 'cats-bbb.html';
const pageCccSlug = 'cats-ccc.html';
const pageDddSlug = 'cats-ddd.html';
const pageNnnSlug = 'cats-nnn.html';
const pageSssSlug = 'cats-sss.html';
const mariasReplyToNnn = 'mariasReplyToNnn';
const mariasReplyToNoCatPage_mentionsOwen = 'mariasReplyToNoCatPage Hi @owen_owner';
describe("emb-disc-cats TyT03RKHJF59", () => {
it("import a site", () => {
const builder = buildSite();
forum = builder.addTwoPagesForum({
title: "Cust Emb Cat Id E2E Test",
members: ['maria', 'memah', 'michael'],
});
forum.siteData.meta.localHostname = localHostname;
forum.siteData.settings.allowEmbeddingFrom = embeddingOrigin;
catB = builder.addCategoryWithAboutPage(forum.forumPage, {
id: catBId,
extId: catBExtId,
parentCategoryId: forum.categories.rootCategory.id,
name: "Category B",
slug: 'cat-b-slug',
aboutPageText: "About Cat B",
});
builder.addDefaultCatPerms(forum.siteData, catBId, catBId * 100);
catC = builder.addCategoryWithAboutPage(forum.forumPage, {
id: catCId,
extId: catCExtId,
parentCategoryId: forum.categories.rootCategory.id,
name: "Category C",
slug: 'cat-c-slug',
aboutPageText: "About Cat C",
});
builder.addDefaultCatPerms(forum.siteData, catCId, catCId * 100);
catD = builder.addCategoryWithAboutPage(forum.forumPage, {
id: catDId,
extId: catDExtId,
parentCategoryId: forum.categories.rootCategory.id,
name: "Category D ",
slug: 'cat-d-slug',
aboutPageText: "About Cat D",
});
builder.addDefaultCatPerms(forum.siteData, catDId, catDId * 100);
catN = builder.addCategoryWithAboutPage(forum.forumPage, {
id: catNId,
extId: catNExtId,
parentCategoryId: forum.categories.rootCategory.id,
name: "Category N",
slug: 'cat-n-slug',
aboutPageText: "About Cat N",
});
builder.addDefaultCatPerms(forum.siteData, catNId, catNId * 100);
// If a non-staff member posts a comment on a data-category= staf cat,
// then that shouldn't be allowed.
// (Likely that'd be a config error by the forum admins — but shouldn't
// be a security hole.) e2emap
forum.categories.staffOnlyCategory.extId = staffCatExtId;
// Disable notifications, or notf email counts will be off (since Owen would get emails).
builder.settings({ numFirstPostsToReview: 0, numFirstPostsToApprove: 0 });
builder.getSite().pageNotfPrefs = [{
memberId: forum.members.owen.id,
notfLevel: c.TestPageNotfLevel.Muted,
wholeSite: true,
}];
// But enable notifications, for cat N, for Memah.
builder.getSite().pageNotfPrefs = [{
memberId: forum.members.memah.id,
notfLevel: c.TestPageNotfLevel.NewTopics,
pagesInCategoryId: catNId,
}];
assert.refEq(builder.getSite(), forum.siteData);
siteIdAddress = server.importSiteData(forum.siteData);
siteId = siteIdAddress.id;
server.skipRateLimits(siteId);
});
it("Create embedding pages", () => {
const dir = 'target';
// No custom category — cat A is the default.
fs.writeFileSync(`${dir}/${pageNoCatSlug}`, makeHtml('nocat', '', '#500'));
// Custom category id.
fs.writeFileSync(`${dir}/${pageBbbSlug}`, makeHtml('bbb', `extid:${catBExtId}`, '#040'));
fs.writeFileSync(`${dir}/${pageCccSlug}`, makeHtml('ccc', `extid:${catCExtId}`, '#005'));
fs.writeFileSync(`${dir}/${pageDddSlug}`, makeHtml('ddd', `extid:${catDExtId}`, '#005'));
// Custom category, and Memah gets notified.
fs.writeFileSync(`${dir}/${pageNnnSlug}`, makeHtml('nnn', `extid:${catNExtId}`, '#405'));
// Staff, restricted.
fs.writeFileSync(`${dir}/${pageSssSlug}`, makeHtml('sss', `extid:${staffCatExtId}`, '#022'));
function makeHtml(pageName: string, categoryRef: string, bgColor: string): string {
return utils.makeEmbeddedCommentsHtml({
pageName, discussionId: '', categoryRef, localHostname, bgColor});
}
});
it("initialize people", () => {
richBrowserA = new TyE2eTestBrowser(wdioBrowserA);
richBrowserB = new TyE2eTestBrowser(wdioBrowserB);
owen = forum.members.owen;
owensBrowser = richBrowserA;
maria = forum.members.maria;
mariasBrowser = richBrowserB;
});
it("Owen logs in to the categories page, ... ", () => {
owensBrowser.go2(siteIdAddress.origin + '/categories');
owensBrowser.complex.loginWithPasswordViaTopbar(owen);
});
// ----- Lazy-reply create page in custom category
it("Maria opens embedding page B", () => {
mariasBrowser.go2(embeddingOrigin + '/' + pageBbbSlug);
});
it("... clicks Reply and logs in", () => {
mariasBrowser.switchToEmbeddedCommentsIrame();
mariasBrowser.topic.clickReplyToEmbeddingBlogPost();
mariasBrowser.loginDialog.loginWithPasswordInPopup(maria);
});
it("... writes and submits a comment", () => {
mariasBrowser.switchToEmbeddedEditorIrame();
mariasBrowser.editor.editText('B comment');
mariasBrowser.editor.save();
});
// ----- Lazy-vote create page in custom category
it("Maria opens embedding page C", () => {
mariasBrowser.go2(embeddingOrigin + '/' + pageCccSlug);
});
it("... Like votes page C", () => {
mariasBrowser.topic.toggleLikeVote(c.BodyNr);
});
// ----- Lazy-notf-prefs create page in custom category
it("Maria opens embedding page D", () => {
mariasBrowser.go2(embeddingOrigin + '/' + pageDddSlug);
});
it("... Like votes page D", () => {
mariasBrowser.topic.toggleLikeVote(c.BodyNr);
});
// ----- New topic notifications work with category=... TyT063AKDGW60
it("Maria opens embedding page N", () => {
mariasBrowser.go2(embeddingOrigin + '/' + pageNnnSlug);
});
it("... Replies to N", () => {
mariasBrowser.complex.replyToEmbeddingBlogPost(mariasReplyToNnn);
});
it("Memah gets a notf email — she's subscribed to Cateory N", () => {
server.waitUntilLastEmailMatches(
siteId, forum.members.memah.emailAddress, mariasReplyToNnn, oneWdioBrowser);
});
it("... no one else", () => {
const { num, addrsByTimeAsc } = server.getEmailsSentToAddrs(siteId);
assert.eq(num, 1, `Emails sent to: ${addrsByTimeAsc}`);
});
// ----- Default category still works
it("Maria opens embedding page No-Cat", () => {
mariasBrowser.go2(embeddingOrigin + '/' + pageNoCatSlug);
});
it("... Replies to No-Cat page", () => {
mariasBrowser.complex.replyToEmbeddingBlogPost(mariasReplyToNoCatPage_mentionsOwen);
});
it("Owen gets a notf email", () => {
server.waitUntilLastEmailMatches(
siteId, forum.members.owen.emailAddress,
mariasReplyToNoCatPage_mentionsOwen, oneWdioBrowser);
});
it("... no one else", () => {
const { num, addrsByTimeAsc } = server.getEmailsSentToAddrs(siteId);
assert.eq(num, 2, `Emails sent to: ${addrsByTimeAsc}`);
});
// Todo: Have a look the pages are now in the correct categories !
});