Skip to content

Commit 5c0f13c

Browse files
committed
Ported more tests.
1 parent 493005c commit 5c0f13c

File tree

8 files changed

+492
-540
lines changed

8 files changed

+492
-540
lines changed

src/tests/frontend-new/helper/padHelper.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,18 @@ export const appendQueryParams = async (page: Page, queryParameters: MapArrayTyp
115115

116116
export const goToNewPad = async (page: Page) => {
117117
// create a new pad before each test run
118-
await page.goto('http://localhost:9001/p/'+"FRONTEND_TESTS"+randomInt(0, 1000));
118+
const padId = "FRONTEND_TESTS"+randomInt(0, 1000);
119+
await page.goto('http://localhost:9001/p/'+padId);
119120
await page.waitForSelector('iframe[name="ace_outer"]');
121+
return padId;
120122
}
121123

124+
export const goToPad = async (page: Page, padId: string) => {
125+
await page.goto('http://localhost:9001/p/'+padId);
126+
await page.waitForSelector('iframe[name="ace_outer"]');
127+
}
128+
129+
122130
export const clearPadContent = async (page: Page) => {
123131
await page.keyboard.down('Control');
124132
await page.keyboard.press('A');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import {clearPadContent, getPadBody, goToNewPad, goToPad, writeToPad} from "../helper/padHelper";
2+
import {expect, Page, test} from "@playwright/test";
3+
4+
let padId = "";
5+
6+
test.beforeEach(async ({ page })=>{
7+
// create a new pad before each test run
8+
padId = await goToNewPad(page);
9+
const body = await getPadBody(page);
10+
await body.click();
11+
await clearPadContent(page);
12+
await writeToPad(page, "Hello World");
13+
await page.keyboard.press('Enter');
14+
await writeToPad(page, "Hello World");
15+
await page.keyboard.press('Enter');
16+
await writeToPad(page, "Hello World");
17+
await page.keyboard.press('Enter');
18+
await writeToPad(page, "Hello World");
19+
await page.keyboard.press('Enter');
20+
await writeToPad(page, "Hello World");
21+
await page.keyboard.press('Enter');
22+
})
23+
24+
test.describe('Messages in the COLLABROOM', function () {
25+
const user1Text = 'text created by user 1';
26+
const user2Text = 'text created by user 2';
27+
28+
const replaceLineText = async (lineNumber: number, newText: string, page: Page) => {
29+
const body = await getPadBody(page)
30+
31+
const div = body.locator('div').nth(lineNumber)
32+
33+
// simulate key presses to delete content
34+
await div.locator('span').selectText() // select all
35+
await page.keyboard.press('Backspace') // clear the first line
36+
await page.keyboard.type(newText) // insert the string
37+
};
38+
39+
test('bug #4978 regression test', async function ({browser}) {
40+
// The bug was triggered by receiving a change from another user while simultaneously composing
41+
// a character and waiting for an acknowledgement of a previously sent change.
42+
43+
// User 1
44+
const context1 = await browser.newContext();
45+
const page1 = await context1.newPage();
46+
await goToPad(page1, padId)
47+
const body1 = await getPadBody(page1)
48+
// Perform actions as User 1...
49+
50+
// User 2
51+
const context2 = await browser.newContext();
52+
const page2 = await context2.newPage();
53+
await goToPad(page2, padId)
54+
const body2 = await getPadBody(page1)
55+
56+
await replaceLineText(0, user1Text,page1);
57+
58+
const text = await body2.locator('div').nth(0).textContent()
59+
const res = text === user1Text
60+
expect(res).toBe(true)
61+
62+
// User 1 starts a character composition.
63+
64+
65+
await replaceLineText(1, user2Text, page2)
66+
67+
await expect(body1.locator('div').nth(1)).toHaveText(user2Text)
68+
69+
70+
// Users 1 and 2 make some more changes.
71+
await replaceLineText(3, user2Text, page2);
72+
73+
await expect(body1.locator('div').nth(3)).toHaveText(user2Text)
74+
75+
await replaceLineText(2, user1Text, page1);
76+
await expect(body2.locator('div').nth(2)).toHaveText(user1Text)
77+
78+
// All changes should appear in both views.
79+
const expectedLines = [
80+
user1Text,
81+
user2Text,
82+
user1Text,
83+
user2Text,
84+
];
85+
86+
for (let i=0;i<expectedLines.length;i++){
87+
expect(await body1.locator('div').nth(i).textContent()).toBe(expectedLines[i]);
88+
}
89+
90+
for (let i=0;i<expectedLines.length;i++){
91+
expect(await body2.locator('div').nth(i).textContent()).toBe(expectedLines[i]);
92+
}
93+
});
94+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
import {expect, Page, test} from "@playwright/test";
2+
import {goToNewPad} from "../helper/padHelper";
3+
4+
test.beforeEach(async ({ page })=>{
5+
// create a new pad before each test run
6+
await goToNewPad(page);
7+
})
8+
9+
test.describe('embed links', function () {
10+
const objectify = function (str: string) {
11+
const hash = {};
12+
const parts = str.split('&');
13+
for (let i = 0; i < parts.length; i++) {
14+
const keyValue = parts[i].split('=');
15+
// @ts-ignore
16+
hash[keyValue[0]] = keyValue[1];
17+
}
18+
return hash;
19+
};
20+
21+
const checkiFrameCode = async function (embedCode: string, readonly: boolean, page: Page) {
22+
// turn the code into an html element
23+
24+
await page.setContent(embedCode, {waitUntil: 'load'})
25+
const locator = page.locator('body').locator('iframe').last()
26+
27+
28+
// read and check the frame attributes
29+
const width = await locator.getAttribute('width');
30+
const height = await locator.getAttribute('height');
31+
const name = await locator.getAttribute('name');
32+
expect(width).toBe('100%');
33+
expect(height).toBe('600');
34+
expect(name).toBe(readonly ? 'embed_readonly' : 'embed_readwrite');
35+
36+
// parse the url
37+
const src = (await locator.getAttribute('src'))!;
38+
const questionMark = src.indexOf('?');
39+
const url = src.substring(0, questionMark);
40+
const paramsStr = src.substring(questionMark + 1);
41+
const params = objectify(paramsStr);
42+
43+
const expectedParams = {
44+
showControls: 'true',
45+
showChat: 'true',
46+
showLineNumbers: 'true',
47+
useMonospaceFont: 'false',
48+
};
49+
50+
// check the url
51+
if (readonly) {
52+
expect(url.indexOf('r.') > 0).toBe(true);
53+
} else {
54+
expect(url).toBe(await page.evaluate(() => window.location.href));
55+
}
56+
57+
// check if all parts of the url are like expected
58+
expect(params).toEqual(expectedParams);
59+
};
60+
61+
test.describe('read and write', function () {
62+
test.beforeEach(async ({ page })=>{
63+
// create a new pad before each test run
64+
await goToNewPad(page);
65+
})
66+
test.describe('the share link', function () {
67+
test('is the actual pad url', async function ({page}) {
68+
69+
const shareButton = page.locator('.buttonicon-embed')
70+
// open share dropdown
71+
await shareButton.click()
72+
73+
// get the link of the share field + the actual pad url and compare them
74+
const shareLink = await page.locator('#linkinput').inputValue()
75+
const padURL = page.url();
76+
expect(shareLink).toBe(padURL);
77+
});
78+
});
79+
80+
test.describe('the embed as iframe code', function () {
81+
test('is an iframe with the the correct url parameters and correct size', async function ({page}) {
82+
83+
const shareButton = page.locator('.buttonicon-embed')
84+
await shareButton.click()
85+
86+
// get the link of the share field + the actual pad url and compare them
87+
const embedCode = await page.locator('#embedinput').inputValue()
88+
89+
90+
await checkiFrameCode(embedCode, false, page);
91+
});
92+
});
93+
});
94+
95+
test.describe('when read only option is set', function () {
96+
test.beforeEach(async ({ page })=>{
97+
// create a new pad before each test run
98+
await goToNewPad(page);
99+
})
100+
101+
test.describe('the share link', function () {
102+
test('shows a read only url', async function ({page}) {
103+
104+
// open share dropdown
105+
const shareButton = page.locator('.buttonicon-embed')
106+
await shareButton.click()
107+
const readonlyCheckbox = page.locator('#readonlyinput')
108+
await readonlyCheckbox.click({
109+
force: true
110+
})
111+
await page.waitForSelector('#readonlyinput:checked')
112+
113+
// get the link of the share field + the actual pad url and compare them
114+
const shareLink = await page.locator('#linkinput').inputValue()
115+
const containsReadOnlyLink = shareLink.indexOf('r.') > 0;
116+
expect(containsReadOnlyLink).toBe(true);
117+
});
118+
});
119+
120+
test.describe('the embed as iframe code', function () {
121+
test('is an iframe with the the correct url parameters and correct size', async function ({page}) {
122+
123+
124+
// open share dropdown
125+
const shareButton = page.locator('.buttonicon-embed')
126+
await shareButton.click()
127+
128+
// check read only checkbox, a bit hacky
129+
const readonlyCheckbox = page.locator('#readonlyinput')
130+
await readonlyCheckbox.click({
131+
force: true
132+
})
133+
134+
await page.waitForSelector('#readonlyinput:checked')
135+
136+
137+
// get the link of the share field + the actual pad url and compare them
138+
const embedCode = await page.locator('#embedinput').inputValue()
139+
140+
await checkiFrameCode(embedCode, true, page);
141+
});
142+
});
143+
144+
})
145+
146+
})

0 commit comments

Comments
 (0)