Skip to content

Commit b5a0274

Browse files
author
Dohyung Ahn
authored
Merge pull request #1242 from nhn/fix/horizontal-grid-selection-with-options
2 parents b1ee6a7 + 00e54db commit b5a0274

File tree

7 files changed

+400
-323
lines changed

7 files changed

+400
-323
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ module.exports = {
110110
files: ['apps/calendar/playwright/**/*.ts'],
111111
extends: ['plugin:playwright/playwright-test'],
112112
rules: {
113+
'playwright/no-force-option': 'off',
113114
'max-nested-callbacks': ['error', { max: 5 }],
114115
'dot-notation': ['error', { allowKeywords: true }],
115116
},

apps/calendar/playwright/assertions.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import type { Page } from '@playwright/test';
1+
import type { Locator, Page } from '@playwright/test';
22
import { expect } from '@playwright/test';
33

4+
import type { FormattedTimeString } from '@t/time/datetime';
5+
46
import type { BoundingBox } from './types';
57
import { getBoundingBox } from './utils';
68

@@ -118,3 +120,33 @@ export function assertBoundingBoxIncluded(targetBox: BoundingBox, wrappingBox: B
118120
expect(targetBox.x + targetBox.width).toBeLessThanOrEqual(wrappingBox.x + wrappingBox.width);
119121
expect(targetBox.y + targetBox.height).toBeLessThanOrEqual(wrappingBox.y + wrappingBox.height);
120122
}
123+
124+
export async function assertTimeGridSelection(
125+
selectionLocator: Locator,
126+
expected: {
127+
startTop: number;
128+
endBottom: number;
129+
totalElements?: number; // not used in day view tests
130+
formattedTimes: FormattedTimeString[];
131+
}
132+
) {
133+
const timeGridSelectionElements = (await selectionLocator.evaluateAll(
134+
(selection) => selection
135+
)) as HTMLElement[];
136+
const expectedFormattedTime = expected.formattedTimes.join(' - ');
137+
138+
if (expected.totalElements) {
139+
expect(timeGridSelectionElements).toHaveLength(expected.totalElements);
140+
}
141+
142+
await expect(selectionLocator.first()).toHaveText(expectedFormattedTime);
143+
144+
const firstElementBoundingBox = await getBoundingBox(selectionLocator.first());
145+
expect(firstElementBoundingBox.y).toBeCloseTo(expected.startTop, 0);
146+
147+
const lastElementBoundingBox = await getBoundingBox(selectionLocator.last());
148+
expect(lastElementBoundingBox.y + lastElementBoundingBox.height).toBeCloseTo(
149+
expected.endBottom,
150+
0
151+
);
152+
}

apps/calendar/playwright/configs.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ export const WEEK_VIEW_DUPLICATE_EVENTS_PAGE_URL = generatePageUrl(
1515
'e2e-week-view--duplicate-events'
1616
);
1717

18+
export const WEEK_VIEW_HOUR_START_OPTION_PAGE_URL = generatePageUrl(
19+
'e2e-week-view--hour-start-option'
20+
);
21+
1822
export const MONTH_VIEW_EMPTY_PAGE_URL = generatePageUrl('e2e-month-view--empty');
1923

2024
export const MONTH_VIEW_PAGE_URL = generatePageUrl('e2e-month-view--fixed-events');

apps/calendar/playwright/day/timeGridSelection.e2e.ts

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import type { Locator } from '@playwright/test';
21
import { expect, test } from '@playwright/test';
32

4-
import type { FormattedTimeString } from '../../src/types/time/datetime';
3+
import { assertTimeGridSelection } from '../assertions';
54
import { DAY_VIEW_PAGE_URL } from '../configs';
65
import { ClickDelay } from '../constants';
76
import {
@@ -17,30 +16,6 @@ test.beforeEach(async ({ page }) => {
1716

1817
const GRID_SELECTION_SELECTOR = '[data-testid*="time-grid-selection"]';
1918

20-
async function assertTimeGridSelection(
21-
selectionLocator: Locator,
22-
expected: {
23-
startTop: number;
24-
endBottom: number;
25-
formattedTimes: FormattedTimeString[];
26-
}
27-
) {
28-
await waitForSingleElement(selectionLocator);
29-
30-
const expectedFormattedTime = expected.formattedTimes.join(' - ');
31-
32-
await expect(selectionLocator.first()).toHaveText(expectedFormattedTime);
33-
34-
const firstElementBoundingBox = await getBoundingBox(selectionLocator.first());
35-
expect(firstElementBoundingBox.y).toBeCloseTo(expected.startTop, 0);
36-
37-
const lastElementBoundingBox = await getBoundingBox(selectionLocator.last());
38-
expect(lastElementBoundingBox.y + lastElementBoundingBox.height).toBeCloseTo(
39-
expected.endBottom,
40-
0
41-
);
42-
}
43-
4419
// NOTE: Only firefox automatically scrolls into view at some random tests, so narrowing the range of movement.
4520
// Maybe `scrollIntoViewIfNeeded` is not supported in the firefox?
4621
// reference: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoViewIfNeeded

0 commit comments

Comments
 (0)