Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: calculate endRowIndex properly when week.hourStart/hourEnd option is applied (fix #1238) #1242

Merged
merged 3 commits into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ module.exports = {
files: ['apps/calendar/playwright/**/*.ts'],
extends: ['plugin:playwright/playwright-test'],
rules: {
'playwright/no-force-option': 'off',
'max-nested-callbacks': ['error', { max: 5 }],
'dot-notation': ['error', { allowKeywords: true }],
},
Expand Down
34 changes: 33 additions & 1 deletion apps/calendar/playwright/assertions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { Page } from '@playwright/test';
import type { Locator, Page } from '@playwright/test';
import { expect } from '@playwright/test';

import type { FormattedTimeString } from '@t/time/datetime';

import type { BoundingBox } from './types';
import { getBoundingBox } from './utils';

Expand Down Expand Up @@ -118,3 +120,33 @@ export function assertBoundingBoxIncluded(targetBox: BoundingBox, wrappingBox: B
expect(targetBox.x + targetBox.width).toBeLessThanOrEqual(wrappingBox.x + wrappingBox.width);
expect(targetBox.y + targetBox.height).toBeLessThanOrEqual(wrappingBox.y + wrappingBox.height);
}

export async function assertTimeGridSelection(
selectionLocator: Locator,
expected: {
startTop: number;
endBottom: number;
totalElements?: number; // not used in day view tests
formattedTimes: FormattedTimeString[];
}
) {
const timeGridSelectionElements = (await selectionLocator.evaluateAll(
(selection) => selection
)) as HTMLElement[];
const expectedFormattedTime = expected.formattedTimes.join(' - ');

if (expected.totalElements) {
expect(timeGridSelectionElements).toHaveLength(expected.totalElements);
}

await expect(selectionLocator.first()).toHaveText(expectedFormattedTime);

const firstElementBoundingBox = await getBoundingBox(selectionLocator.first());
expect(firstElementBoundingBox.y).toBeCloseTo(expected.startTop, 0);

const lastElementBoundingBox = await getBoundingBox(selectionLocator.last());
expect(lastElementBoundingBox.y + lastElementBoundingBox.height).toBeCloseTo(
expected.endBottom,
0
);
}
4 changes: 4 additions & 0 deletions apps/calendar/playwright/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export const WEEK_VIEW_DUPLICATE_EVENTS_PAGE_URL = generatePageUrl(
'e2e-week-view--duplicate-events'
);

export const WEEK_VIEW_HOUR_START_OPTION_PAGE_URL = generatePageUrl(
'e2e-week-view--hour-start-option'
);

export const MONTH_VIEW_EMPTY_PAGE_URL = generatePageUrl('e2e-month-view--empty');

export const MONTH_VIEW_PAGE_URL = generatePageUrl('e2e-month-view--fixed-events');
27 changes: 1 addition & 26 deletions apps/calendar/playwright/day/timeGridSelection.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { Locator } from '@playwright/test';
import { expect, test } from '@playwright/test';

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

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

async function assertTimeGridSelection(
selectionLocator: Locator,
expected: {
startTop: number;
endBottom: number;
formattedTimes: FormattedTimeString[];
}
) {
await waitForSingleElement(selectionLocator);

const expectedFormattedTime = expected.formattedTimes.join(' - ');

await expect(selectionLocator.first()).toHaveText(expectedFormattedTime);

const firstElementBoundingBox = await getBoundingBox(selectionLocator.first());
expect(firstElementBoundingBox.y).toBeCloseTo(expected.startTop, 0);

const lastElementBoundingBox = await getBoundingBox(selectionLocator.last());
expect(lastElementBoundingBox.y + lastElementBoundingBox.height).toBeCloseTo(
expected.endBottom,
0
);
}

// NOTE: Only firefox automatically scrolls into view at some random tests, so narrowing the range of movement.
// Maybe `scrollIntoViewIfNeeded` is not supported in the firefox?
// reference: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoViewIfNeeded
Expand Down
Loading