Skip to content

Commit

Permalink
Chat testcafe tests: mock new Date() to demonstrate 'Today' and 'Yest…
Browse files Browse the repository at this point in the history
…erday' texts inside day headers (#28218)

Signed-off-by: EugeniyKiyashko <EugeniyKiyashko@users.noreply.github.com>
  • Loading branch information
EugeniyKiyashko authored Oct 23, 2024
1 parent 19bd42e commit ac0ab57
Show file tree
Hide file tree
Showing 4 changed files with 368 additions and 338 deletions.
3 changes: 3 additions & 0 deletions e2e/testcafe-devextreme/helpers/themeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export async function testScreenshot(
theme?: string;
shouldTestInCompact?: boolean;
compactCallBack?: () => Promise<unknown>;
themeChanged?: () => Promise<unknown>;
},

): Promise<void> {
Expand All @@ -37,10 +38,12 @@ export async function testScreenshot(
theme,
shouldTestInCompact = false,
compactCallBack,
themeChanged,
} = options ?? {};

if (isString(theme)) {
await changeTheme(theme);
await themeChanged?.();
}

await t
Expand Down
1 change: 1 addition & 0 deletions e2e/testcafe-devextreme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"devextreme-screenshot-comparer": "2.0.17",
"devextreme-testcafe-models": "workspace:*",
"minimist": "1.2.8",
"mockdate": "3.0.5",
"nconf": "0.12.1",
"testcafe": "2.5.0"
}
Expand Down
25 changes: 22 additions & 3 deletions e2e/testcafe-devextreme/tests/chat/errorList.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createScreenshotsComparer } from 'devextreme-screenshot-comparer';
import Chat from 'devextreme-testcafe-models/chat';
import { ClientFunction } from 'testcafe';
import { createUser } from './data';
import url from '../../helpers/getPageUrl';
import { createWidget } from '../../helpers/createWidget';
Expand All @@ -8,7 +9,10 @@ import { getFullThemeName, testScreenshot } from '../../helpers/themeUtils';
fixture.disablePageReloads`ChatErrorList`
.page(url(__dirname, '../container.html'));

test.skip('Errorlist appearance', async (t) => {
test.clientScripts([
{ module: 'mockdate' },
{ content: 'window.MockDate = MockDate;' },
])('Errorlist appearance', async (t) => {
const { takeScreenshot, compareResults } = createScreenshotsComparer(t);
const chat = new Chat('#container');

Expand All @@ -29,7 +33,13 @@ test.skip('Errorlist appearance', async (t) => {
});

const darkTheme = getFullThemeName().replace('light', 'dark');
await testScreenshot(t, takeScreenshot, 'Errorlist with long text in error.png', { element: '#container', theme: darkTheme });
await testScreenshot(t, takeScreenshot, 'Errorlist with long text in error.png', {
element: '#container',
theme: darkTheme,
themeChanged: async () => {
await chat.repaint();
},
});

await chat.option('rtlEnabled', true);

Expand All @@ -39,10 +49,14 @@ test.skip('Errorlist appearance', async (t) => {
.expect(compareResults.isValid())
.ok(compareResults.errorMessages());
}).before(async () => {
await ClientFunction(() => {
(window as any).MockDate.set('2024/10/18');
})();

const userFirst = createUser(1, 'First');
const userSecond = createUser(2, 'Second');
const msInDay = 86400000;
const today = new Date().setHours(7, 22, 0, 0);
const today = new Date('2024/10/18').setHours(7, 22, 0, 0);
const yesterday = today - msInDay;

const items = [{
Expand Down Expand Up @@ -74,4 +88,9 @@ test.skip('Errorlist appearance', async (t) => {
height: 600,
errors: [{ id: 1, message: 'Error Message 1. Error Description...' }],
});
// eslint-disable-next-line @typescript-eslint/require-await
}).after(async () => {
await ClientFunction(() => {
(window as any).MockDate.reset();
})();
});
Loading

0 comments on commit ac0ab57

Please sign in to comment.