Skip to content
Open
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
18 changes: 11 additions & 7 deletions e2e/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,18 @@ export const navigateFromMenu = async (page: Page, name: string): Promise<void>
};

/**
* Switches the schedule between its All and Favorites segments.
* Turns the filter's Favorites only toggle on or off and applies the filter.
*/
export const showSegment = async (page: Page, name: 'All' | 'Favorites'): Promise<void> => {
const schedule = visiblePage(page, 'schedule-page');
// The segment button's host receives the pointer events, not its inner tab element.
await schedule.locator('ion-segment-button', { hasText: name }).click();
// Wait for the switch so the other segment's sessions aren't matched while they're still showing.
await expect(schedule.getByRole('tab', { name })).toHaveAttribute('aria-selected', 'true');
export const showFavoritesOnly = async (page: Page, on: boolean): Promise<void> => {
await filterButton(page).click();
const modal = page.locator('ion-modal');
const toggle = modal.getByRole('switch', { name: 'Favorites only' });
if ((await toggle.isChecked()) !== on) {
await toggle.click();
}
await expect(toggle).toBeChecked({ checked: on });
await modal.getByRole('button', { name: 'Done' }).click();
await expect(modal).toBeHidden();
};

// The back button is labelled back in md and shows a Back label in iOS.
Expand Down
85 changes: 77 additions & 8 deletions e2e/schedule.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
openSchedule,
openSearch,
searchButton,
showSegment,
sessionLink,
showFavoritesOnly,
visiblePage,
} from './helpers';

Expand All @@ -22,6 +22,7 @@ const visibleSessions = (page: Page) => schedule(page).getByRole('link').filter(
const filterModal = (page: Page) => page.locator('ion-modal');
// The checkbox's host element receives the pointer events, not its inner checkbox element.
const trackCheckbox = (page: Page, track: string) => filterModal(page).locator('ion-checkbox', { hasText: track });
const favoritesOnlySwitch = (page: Page) => filterModal(page).getByRole('switch', { name: 'Favorites only' });

test.describe('Schedule', () => {
test.beforeEach(async ({ page }) => {
Expand Down Expand Up @@ -93,29 +94,88 @@ test.describe('Schedule', () => {
await expect(visibleSessions(page)).toHaveCount(0);
});

test('Favorites shows an empty state when nothing is favorited', async ({ page }) => {
await showSegment(page, 'Favorites');
test('Favorites only shows an empty state when nothing is favorited', async ({ page }) => {
await showFavoritesOnly(page, true);

await expect(schedule(page).getByText('No Sessions Found')).toBeVisible();
await expect(visibleSessions(page)).toHaveCount(0);
});

test('Favorites shows only the favorited sessions', async ({ page }) => {
test('Favorites only shows only the favorited sessions', async ({ page }) => {
await sessionLink(page, 'Ionic Tooling').click();
await favoriteButton(page).click();
await backButton(page, 'session-detail-page').click();

await showSegment(page, 'Favorites');
await showFavoritesOnly(page, true);

await expect(visibleSessions(page)).toHaveCount(1);
await expect(sessionLink(page, 'Ionic Tooling')).toBeVisible();
await expect(timeGroups(page)).toHaveCount(1);
await expect(timeGroups(page)).toContainText('9:15 am');

await showSegment(page, 'All');
await showFavoritesOnly(page, false);
await expect(visibleSessions(page)).toHaveCount(20);
});

test('search and Favorites only combine', async ({ page }) => {
for (const name of ['Ionic Tooling', 'Breakfast']) {
await sessionLink(page, name).click();
await favoriteButton(page).click();
await backButton(page, 'session-detail-page').click();
}
await showFavoritesOnly(page, true);

await (await openSearch(page)).fill('ionic');

await expect(visibleSessions(page)).toHaveCount(1);
await expect(sessionLink(page, 'Ionic Tooling')).toBeVisible();
});

test('favorite sessions are marked with a star', async ({ page }) => {
// The star is slotted into the item, outside the link in its shadow root.
const favoriteStar = (name: string) =>
schedule(page)
.locator('ion-item')
.filter({ has: page.getByRole('heading', { name, exact: true }) })
.getByRole('img', { name: 'Favorite' });
await expect(favoriteStar('Lunch')).toHaveCount(0);

await sessionLink(page, 'Lunch').click();
await favoriteButton(page).click();
await backButton(page, 'session-detail-page').click();

await expect(favoriteStar('Lunch')).toBeVisible();
await expect(favoriteStar('Breakfast')).toHaveCount(0);
});

test('the schedule shows which filters are on', async ({ page }) => {
await sessionLink(page, 'Lunch').click();
await favoriteButton(page).click();
await backButton(page, 'session-detail-page').click();
await filterButton(page).click();
await trackCheckbox(page, 'React').click();
await favoritesOnlySwitch(page).click();
await expect(favoritesOnlySwitch(page)).toBeChecked();
await filterModal(page).getByRole('button', { name: 'Done' }).click();
await expect(filterModal(page)).toBeHidden();
await expect(visibleSessions(page)).toHaveCount(1);

if (await isIos(page)) {
await schedule(page).getByRole('button', { name: 'Filtered by: Favorites, 9 of 10 Tracks' }).click();
await expect(filterModal(page)).toBeVisible();
return;
}

const favoritesChip = schedule(page).getByRole('button', { name: 'Favorites', exact: true });
await expect(favoritesChip).toHaveAttribute('aria-pressed', 'true');
await favoritesChip.click();
await expect(favoritesChip).toHaveAttribute('aria-pressed', 'false');
await expect(visibleSessions(page)).toHaveCount(18);

await schedule(page).getByRole('button', { name: '9 of 10 Tracks' }).click();
await expect(filterModal(page)).toBeVisible();
});

test('the filter excludes a track and including it brings its sessions back', async ({ page }) => {
await filterButton(page).click();
await trackCheckbox(page, 'Food').click();
Expand All @@ -139,10 +199,12 @@ test.describe('Schedule', () => {
await expect(visibleSessions(page)).toHaveCount(20);
});

test('closing the filter without Done keeps the tracks', async ({ page }) => {
test('closing the filter without Done keeps the filter', async ({ page }) => {
await filterButton(page).click();
await trackCheckbox(page, 'Food').click();
await expect(filterModal(page).getByRole('checkbox', { name: 'Food' })).not.toBeChecked();
await favoritesOnlySwitch(page).click();
await expect(favoritesOnlySwitch(page)).toBeChecked();

// Escape closes the modal the way swiping the card down or tapping the backdrop does.
await page.keyboard.press('Escape');
Expand All @@ -151,13 +213,17 @@ test.describe('Schedule', () => {
await expect(visibleSessions(page)).toHaveCount(20);
await filterButton(page).click();
await expect(filterModal(page).getByRole('checkbox', { name: 'Food' })).toBeChecked();
await expect(favoritesOnlySwitch(page)).not.toBeChecked();
});

test('Reset in the filter deselects every track', async ({ page }) => {
test('Reset in the filter deselects every track and turns off Favorites only', async ({ page }) => {
test.skip(await isIos(page), 'iOS shows Cancel instead of Reset.');
await filterButton(page).click();
await favoritesOnlySwitch(page).click();
await expect(favoritesOnlySwitch(page)).toBeChecked();
await filterModal(page).getByRole('button', { name: 'Reset' }).click();

await expect(favoritesOnlySwitch(page)).not.toBeChecked();
await expect(filterModal(page).getByRole('checkbox', { checked: true })).toHaveCount(0);
await expect(filterModal(page).getByRole('checkbox', { checked: false })).toHaveCount(10);

Expand Down Expand Up @@ -192,6 +258,8 @@ test.describe('Schedule', () => {
await filterButton(page).click();
await trackCheckbox(page, 'React').click();
await expect(filterModal(page).getByRole('checkbox', { name: 'React' })).not.toBeChecked();
await favoritesOnlySwitch(page).click();
await expect(favoritesOnlySwitch(page)).toBeChecked();
await filterModal(page).getByRole('button', { name: 'Cancel' }).click();
await expect(filterModal(page)).toBeHidden();

Expand All @@ -203,6 +271,7 @@ test.describe('Schedule', () => {
await filterButton(page).click();
await expect(filterModal(page).getByRole('checkbox', { name: 'Food' })).not.toBeChecked();
await expect(filterModal(page).getByRole('checkbox', { name: 'React' })).toBeChecked();
await expect(favoritesOnlySwitch(page)).not.toBeChecked();
});

test('Deselect All hides every session and Select All brings them back', async ({ page }) => {
Expand Down
15 changes: 7 additions & 8 deletions e2e/session-detail.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ import {
favoriteButton,
openSchedule,
removeFavoriteButton,
showSegment,
sessionLink,
showFavoritesOnly,
visiblePage,
} from './helpers';

const detail = (page: Page) => visiblePage(page, 'session-detail-page');
const schedule = (page: Page) => visiblePage(page, 'schedule-page');

const toggleFavoriteFromDetail = async (page: Page, name: string, button: typeof favoriteButton) => {
await showSegment(page, 'All');
await showFavoritesOnly(page, false);
await sessionLink(page, name).click();
await expect(detail(page).getByRole('heading', { level: 1 })).toHaveText(name);
await button(page).click();
await backButton(page, 'session-detail-page').click();
await showSegment(page, 'Favorites');
await showFavoritesOnly(page, true);
};

// Drags a session's item to the left to reveal its options.
Expand Down Expand Up @@ -127,7 +127,6 @@ test.describe('Session detail', () => {
await removeFavoriteButton(page).click();
await backButton(page, 'session-detail-page').click();

await expect(schedule(page).getByRole('tab', { name: 'Favorites' })).toHaveAttribute('aria-selected', 'true');
await expect(sessionLink(page, 'Ionic Tooling')).toBeHidden();
await expect(schedule(page).getByText('No Sessions Found')).toBeVisible();
});
Expand All @@ -149,14 +148,14 @@ test.describe('Session detail', () => {

await expect(page.getByText('Ionic Tooling was successfully added as a favorite.')).toBeVisible();

await showSegment(page, 'Favorites');
await showFavoritesOnly(page, true);
await expect(sessionLink(page, 'Ionic Tooling')).toBeVisible();
});

test('removing from Favorites with the sliding item unfavorites the session', async ({ page }) => {
await swipeOpen(page, 'Ionic Tooling');
await itemOption(page, 'Favorite').click();
await showSegment(page, 'Favorites');
await showFavoritesOnly(page, true);

await swipeOpen(page, 'Ionic Tooling');
await itemOption(page, 'Remove').click();
Expand All @@ -179,7 +178,7 @@ test.describe('Session detail', () => {
await alert.getByRole('button', { name: 'Cancel' }).click();
await expect(alert).toBeHidden();

await showSegment(page, 'Favorites');
await showFavoritesOnly(page, true);
await expect(visibleSessions(page)).toHaveCount(1);
await expect(sessionLink(page, 'Ionic Tooling')).toBeVisible();
});
Expand All @@ -195,7 +194,7 @@ test.describe('Session detail', () => {
.getByRole('button', { name: 'Remove' })
.click();

await showSegment(page, 'Favorites');
await showFavoritesOnly(page, true);
await expect(schedule(page).getByText('No Sessions Found')).toBeVisible();
});
});
9 changes: 9 additions & 0 deletions src/components/SessionList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ const favoriteOption = (container: HTMLElement, name: string) => {
};

describe('SessionList', () => {
it('marks the favorite sessions with a star', () => {
const { container } = renderList([ionicTooling.id]);

const starred = Array.from(container.querySelectorAll('ion-item-sliding')).filter((item) =>
item.querySelector('ion-icon[aria-label="Favorite"]'),
);
expect(starred.map((item) => item.querySelector('h3')?.textContent)).toEqual(['Ionic Tooling']);
});

it('favorites a session from its item', () => {
const { container } = renderList([]);

Expand Down
4 changes: 0 additions & 4 deletions src/components/SessionListFilter.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,3 @@
.ios .session-list-filter ion-list-header {
margin-top: 10px;
}

.ios .session-list-filter ion-checkbox {
color: var(--ion-color-primary);
}
28 changes: 26 additions & 2 deletions src/components/SessionListFilter.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,20 @@ beforeAll(() => {
// Shows the included tracks from the app state.
const FilteredTracks = () => <output>{useContext(AppContext).state.data.filteredTracks.join(',')}</output>;

const renderFilter = () => {
// Shows whether the app state only shows favorites.
const FavoritesOnly = () => (
<span data-testid="favorites-only">{String(useContext(AppContext).state.data.favoritesOnly)}</span>
);

const renderFilter = (favoritesOnly = false) => {
const onDismissModal = vi.fn();
renderWithState(
<>
<SessionListFilter onDismissModal={onDismissModal} />
<FilteredTracks />
<FavoritesOnly />
</>,
{ state: makeState() },
{ state: makeState({ data: { favoritesOnly } }) },
);
return { onDismissModal };
};
Expand All @@ -43,6 +49,24 @@ describe('SessionListFilter', () => {
fireEvent.click(screen.getByText('Done'));
expect(screen.getByRole('status')).toHaveTextContent('Food,Ionic,React,Tooling');
});

it('Done keeps Favorites only on when it was on', () => {
renderFilter(true);

fireEvent.click(screen.getByText('Done'));

expect(screen.getByTestId('favorites-only')).toHaveTextContent('true');
});

it('Reset deselects every track and turns off Favorites only once Done is tapped', () => {
renderFilter(true);

fireEvent.click(screen.getByText('Reset'));
fireEvent.click(screen.getByText('Done'));

expect(screen.getByRole('status')).toHaveTextContent(/^$/);
expect(screen.getByTestId('favorites-only')).toHaveTextContent('false');
});
});

describe('SessionListFilter in iOS', () => {
Expand Down
Loading
Loading