Skip to content

Commit

Permalink
Chat: Add screenshot tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marker-dao authored Sep 13, 2024
1 parent 5c4f164 commit 4e7d2fa
Show file tree
Hide file tree
Showing 62 changed files with 353 additions and 72 deletions.
44 changes: 44 additions & 0 deletions e2e/testcafe-devextreme/tests/chat/avatar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { createScreenshotsComparer } from 'devextreme-screenshot-comparer';
import Chat from 'devextreme-testcafe-models/chat';
import { createUser, generateMessages, avatarUrl } from './data';
import url from '../../helpers/getPageUrl';
import { createWidget } from '../../helpers/createWidget';
import { testScreenshot } from '../../helpers/themeUtils';
import { appendElementTo } from '../../helpers/domUtils';

fixture.disablePageReloads`ChatAvatar`
.page(url(__dirname, '../container.html'));

test('Chat: avatar', async (t) => {
const { takeScreenshot, compareResults } = createScreenshotsComparer(t);
await testScreenshot(t, takeScreenshot, 'Avatar with initials.png', { element: '#chat' });

const chat = new Chat('#chat');

const userFirst = createUser(1, 'First', avatarUrl);
const userSecond = createUser(2, 'Second', avatarUrl);

const items = generateMessages(2, userFirst, userSecond, false, false, 2);

await chat.option('items', items);

await testScreenshot(t, takeScreenshot, 'Avatar with image.png', { element: '#chat' });

await t
.expect(compareResults.isValid())
.ok(compareResults.errorMessages());
}).before(async () => {
await appendElementTo('#container', 'div', 'chat');

const userFirst = createUser(1, 'First');
const userSecond = createUser(2, 'Second');

const items = generateMessages(2, userFirst, userSecond, false, false, 2);

return createWidget('dxChat', {
width: 400,
height: 600,
user: userSecond,
items,
}, '#chat');
});
72 changes: 0 additions & 72 deletions e2e/testcafe-devextreme/tests/chat/common.ts

This file was deleted.

67 changes: 67 additions & 0 deletions e2e/testcafe-devextreme/tests/chat/data/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
interface User {
id: number;
name: string;
avatarUrl: string;
}

export const avatarUrl = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJgAAACRCAYAAAA/zXH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PWZAMFmPqYhAYKFAK3PBAg28zENCRAsBGh9JkCwmY9pSIBgIUDrMwGCzXxMQwIECwFanwkQbOZjGhIgWAjQ+kyAYDMf05AAwUKA1mcCvwEk7hCO5l/PKgAAAABJRU5ErkJggg==';
export const lineBreaks = '\n\n';

export const createUser = (id: number, name: string, url = ''): User => ({
id,
name,
avatarUrl: url,
});

export const timestamp = new Date(1721747399083);

export const getLongText = (useLineBreaks = false, length = 1): string => {
const UUID = '9138cf2e-ced3-426a-bb53-4478536f690b';
const longItem = '1826403415222858765740359115719081097182452189907242163763639765588452014727158270738379423360950761826403415222858765740359115719081097182452189907';
const longItemArray = Array(length).fill(longItem);
const longString = longItemArray.join('');

const result = `${UUID}:${useLineBreaks ? lineBreaks : ''}${longString}`;

return result;
};

export const getShortText = (useLineBreaks = false): string => {
const value = `Short${useLineBreaks ? lineBreaks : ' '}text`;

return value;
};

export const generateMessages = (
length: number,
userFirst: User,
userSecond = userFirst,
useLongText = false,
useLineBreaks = false,
coefficient = 4,
n = 1,
): any => {
const messages = Array.from({ length: length * n }, (_, i) => {
const text = useLongText
? getLongText(useLineBreaks)
: getShortText(useLineBreaks);

const getAuthor = () => {
if (n > 1) {
return i >= length ? userSecond : userFirst;
}

return i % coefficient === 0 ? userFirst : userSecond;
};

const item = {
timestamp,
author: getAuthor(),
text,
};

return item;
});

return messages;
};
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions e2e/testcafe-devextreme/tests/chat/messageBox.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { createScreenshotsComparer } from 'devextreme-screenshot-comparer';
import Chat from 'devextreme-testcafe-models/chat';
import { getShortText, getLongText } from './data';
import url from '../../helpers/getPageUrl';
import { createWidget } from '../../helpers/createWidget';
import { testScreenshot } from '../../helpers/themeUtils';
import { appendElementTo } from '../../helpers/domUtils';

fixture.disablePageReloads`ChatMessageBox`
.page(url(__dirname, '../container.html'));

test('Chat: messagebox', async (t) => {
const { takeScreenshot, compareResults } = createScreenshotsComparer(t);

const chat = new Chat('#chat');
const shortText = getShortText();
const longText = getLongText(false, 5);

await chat.focus();
await testScreenshot(t, takeScreenshot, 'Messagebox when chat has focus.png', { element: '#chat' });

await t.typeText(chat.getInput(), shortText);
await testScreenshot(t, takeScreenshot, 'Messagebox when input contains short text.png', { element: '#chat' });

await t.typeText(chat.getInput(), longText);
await testScreenshot(t, takeScreenshot, 'Messagebox when input contains long text.png', { element: '#chat' });

await t.pressKey('tab');
await testScreenshot(t, takeScreenshot, 'Messagebox when send button has focus.png', { element: '#chat' });

await t
.expect(compareResults.isValid())
.ok(compareResults.errorMessages());
}).before(async () => {
await appendElementTo('#container', 'div', 'chat');

return createWidget('dxChat', {
width: 400,
height: 600,
}, '#chat');
});
40 changes: 40 additions & 0 deletions e2e/testcafe-devextreme/tests/chat/messageBubble.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { createScreenshotsComparer } from 'devextreme-screenshot-comparer';
import Chat from 'devextreme-testcafe-models/chat';
import { createUser, generateMessages } from './data';
import url from '../../helpers/getPageUrl';
import { createWidget } from '../../helpers/createWidget';
import { testScreenshot } from '../../helpers/themeUtils';
import { appendElementTo } from '../../helpers/domUtils';

fixture.disablePageReloads`ChatMessageBubble`
.page(url(__dirname, '../container.html'));

test('Chat: messagebubble', async (t) => {
const { takeScreenshot, compareResults } = createScreenshotsComparer(t);

const chat = new Chat('#chat');

const userFirst = createUser(1, 'First');
const userSecond = createUser(2, 'Second');

let items = generateMessages(2, userFirst, userSecond, true, false, 2);

await chat.option({ items, user: userSecond });
await testScreenshot(t, takeScreenshot, 'Bubbles with long text.png', { element: '#chat' });

items = generateMessages(2, userFirst, userSecond, true, true, 2);

await chat.option({ items });
await testScreenshot(t, takeScreenshot, 'Bubbles with long text with line breaks.png', { element: '#chat' });

await t
.expect(compareResults.isValid())
.ok(compareResults.errorMessages());
}).before(async () => {
await appendElementTo('#container', 'div', 'chat');

return createWidget('dxChat', {
width: 400,
height: 600,
}, '#chat');
});
105 changes: 105 additions & 0 deletions e2e/testcafe-devextreme/tests/chat/messageGroup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { Selector } from 'testcafe';
import { createScreenshotsComparer } from 'devextreme-screenshot-comparer';
import Chat from 'devextreme-testcafe-models/chat';
import {
createUser,
generateMessages,
getLongText,
} from './data';
import url from '../../helpers/getPageUrl';
import { createWidget } from '../../helpers/createWidget';
import { testScreenshot } from '../../helpers/themeUtils';
import { appendElementTo, setStyleAttribute } from '../../helpers/domUtils';

const CHAT_AVATAR_SELECTOR = '.dx-chat-message-avatar';

fixture.disablePageReloads`ChatMessageGroup`
.page(url(__dirname, '../container.html'));

test('Chat: messagegroup, avatar rendering', async (t) => {
const { takeScreenshot, compareResults } = createScreenshotsComparer(t);

await testScreenshot(t, takeScreenshot, 'Avatar has correct position.png', { element: '#chat' });

await setStyleAttribute(Selector(CHAT_AVATAR_SELECTOR), 'width: 64px; height: 64px');
await testScreenshot(t, takeScreenshot, 'Avatar sizes do not affect indentation between bubbles.png', { element: '#chat' });

await t
.expect(compareResults.isValid())
.ok(compareResults.errorMessages());
}).before(async () => {
await appendElementTo('#container', 'div', 'chat');

const userFirst = createUser(1, 'First');
const items = generateMessages(3, userFirst);

return createWidget('dxChat', {
width: 400,
height: 600,
items,
}, '#chat');
});

test('Chat: messagegroup, information', async (t) => {
const { takeScreenshot, compareResults } = createScreenshotsComparer(t);

await testScreenshot(t, takeScreenshot, 'Information row with long user name.png', { element: '#chat' });

await t
.expect(compareResults.isValid())
.ok(compareResults.errorMessages());
}).before(async () => {
await appendElementTo('#container', 'div', 'chat');

const userFirst = createUser(1, getLongText());
const userSecond = createUser(2, getLongText());

const items = generateMessages(2, userFirst, userSecond, false, false, 2);

return createWidget('dxChat', {
width: 400,
height: 600,
user: userSecond,
items,
}, '#chat');
});

test('Chat: messagegroup, bubbles', async (t) => {
const { takeScreenshot, compareResults } = createScreenshotsComparer(t);

const chat = new Chat('#chat');

const userFirst = createUser(1, 'First');
const userSecond = createUser(2, 'Second');

let items = generateMessages(1, userFirst, userSecond, false, false, 4, 2);

await chat.option({ items, user: userSecond });
await testScreenshot(t, takeScreenshot, 'Messagegroup with 1 bubble.png', { element: '#chat' });

items = generateMessages(2, userFirst, userSecond, false, false, 4, 2);

await chat.option({ items });
await testScreenshot(t, takeScreenshot, 'Messagegroup with 2 bubbles.png', { element: '#chat' });

items = generateMessages(3, userFirst, userSecond, false, false, 4, 2);

await chat.option({ items });
await testScreenshot(t, takeScreenshot, 'Messagegroup with 3 bubbles.png', { element: '#chat' });

items = generateMessages(4, userFirst, userSecond, false, false, 4, 2);

await chat.option({ items });
await testScreenshot(t, takeScreenshot, 'Messagegroup with 4 bubbles.png', { element: '#chat' });

await t
.expect(compareResults.isValid())
.ok(compareResults.errorMessages());
}).before(async () => {
await appendElementTo('#container', 'div', 'chat');

return createWidget('dxChat', {
width: 400,
height: 600,
}, '#chat');
});
Loading

0 comments on commit 4e7d2fa

Please sign in to comment.