diff --git a/e2e/helpers.ts b/e2e/helpers.ts
index fbd82818..66eeae05 100644
--- a/e2e/helpers.ts
+++ b/e2e/helpers.ts
@@ -81,14 +81,18 @@ export const navigateFromMenu = async (page: Page, name: string): Promise
};
/**
- * 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 => {
- 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 => {
+ 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.
diff --git a/e2e/schedule.spec.ts b/e2e/schedule.spec.ts
index aaa80046..1f45e843 100644
--- a/e2e/schedule.spec.ts
+++ b/e2e/schedule.spec.ts
@@ -9,8 +9,8 @@ import {
openSchedule,
openSearch,
searchButton,
- showSegment,
sessionLink,
+ showFavoritesOnly,
visiblePage,
} from './helpers';
@@ -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 }) => {
@@ -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();
@@ -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');
@@ -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);
@@ -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();
@@ -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 }) => {
diff --git a/e2e/session-detail.spec.ts b/e2e/session-detail.spec.ts
index e8293c2f..2bc9aa81 100644
--- a/e2e/session-detail.spec.ts
+++ b/e2e/session-detail.spec.ts
@@ -6,8 +6,8 @@ import {
favoriteButton,
openSchedule,
removeFavoriteButton,
- showSegment,
sessionLink,
+ showFavoritesOnly,
visiblePage,
} from './helpers';
@@ -15,12 +15,12 @@ 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.
@@ -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();
});
@@ -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();
@@ -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();
});
@@ -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();
});
});
diff --git a/src/components/SessionList.test.tsx b/src/components/SessionList.test.tsx
index 92df7f53..4429f335 100644
--- a/src/components/SessionList.test.tsx
+++ b/src/components/SessionList.test.tsx
@@ -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([]);
diff --git a/src/components/SessionListFilter.css b/src/components/SessionListFilter.css
index 4516c7ac..ed9c5159 100644
--- a/src/components/SessionListFilter.css
+++ b/src/components/SessionListFilter.css
@@ -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);
-}
diff --git a/src/components/SessionListFilter.test.tsx b/src/components/SessionListFilter.test.tsx
index 1336f66d..bc56fce0 100644
--- a/src/components/SessionListFilter.test.tsx
+++ b/src/components/SessionListFilter.test.tsx
@@ -17,14 +17,20 @@ beforeAll(() => {
// Shows the included tracks from the app state.
const FilteredTracks = () => ;
-const renderFilter = () => {
+// Shows whether the app state only shows favorites.
+const FavoritesOnly = () => (
+ {String(useContext(AppContext).state.data.favoritesOnly)}
+);
+
+const renderFilter = (favoritesOnly = false) => {
const onDismissModal = vi.fn();
renderWithState(
<>
+
>,
- { state: makeState() },
+ { state: makeState({ data: { favoritesOnly } }) },
);
return { onDismissModal };
};
@@ -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', () => {
diff --git a/src/components/SessionListFilter.tsx b/src/components/SessionListFilter.tsx
index b773f79d..2c752113 100644
--- a/src/components/SessionListFilter.tsx
+++ b/src/components/SessionListFilter.tsx
@@ -12,6 +12,7 @@ import {
IonCheckbox,
IonFooter,
IonIcon,
+ IonToggle,
} from '@ionic/react';
import {
logoReact,
@@ -24,13 +25,14 @@ import {
colorPalette,
construct,
compass,
+ star,
} from 'ionicons/icons';
import React, { useState } from 'react';
import './SessionListFilter.css';
import { connect } from '../data/connect';
-import { updateFilteredTracks } from '../data/sessions/sessions.actions';
+import { setFavoritesOnly, updateFilteredTracks } from '../data/sessions/sessions.actions';
interface OwnProps {
onDismissModal: () => void;
@@ -39,10 +41,12 @@ interface OwnProps {
interface StateProps {
allTracks: string[];
filteredTracks: string[];
+ favoritesOnly: boolean;
}
interface DispatchProps {
updateFilteredTracks: typeof updateFilteredTracks;
+ setFavoritesOnly: typeof setFavoritesOnly;
}
type SessionListFilterProps = OwnProps & StateProps & DispatchProps;
@@ -50,12 +54,15 @@ type SessionListFilterProps = OwnProps & StateProps & DispatchProps;
const SessionListFilter: React.FC = ({
allTracks,
filteredTracks,
+ favoritesOnly,
onDismissModal,
updateFilteredTracks,
+ setFavoritesOnly,
}) => {
const ios = getMode() === 'ios';
- // The track changes stay here until Done, so Cancel, swiping the iOS card down, or tapping the backdrop discards them.
+ // The changes stay here until Done, so Cancel, swiping the iOS card down, or tapping the backdrop discards them.
const [draftTracks, setDraftTracks] = useState(filteredTracks);
+ const [draftFavoritesOnly, setDraftFavoritesOnly] = useState(favoritesOnly);
const toggleTrackFilter = (track: string) => {
setDraftTracks((tracks) => (tracks.includes(track) ? tracks.filter((x) => x !== track) : [...tracks, track]));
@@ -63,9 +70,15 @@ const SessionListFilter: React.FC = ({
const handleDone = () => {
updateFilteredTracks(draftTracks);
+ setFavoritesOnly(draftFavoritesOnly);
onDismissModal();
};
+ const handleReset = () => {
+ setDraftFavoritesOnly(false);
+ setDraftTracks([]);
+ };
+
const handleDeselectAll = () => {
setDraftTracks([]);
};
@@ -93,7 +106,7 @@ const SessionListFilter: React.FC = ({
{ios && Cancel}
- {!ios && Reset}
+ {!ios && Reset}
Filter Sessions
@@ -107,6 +120,15 @@ const SessionListFilter: React.FC = ({
+
+
+ {ios && }
+ setDraftFavoritesOnly(e.detail.checked)}>
+ Favorites only
+
+
+
+
Tracks
@@ -144,9 +166,11 @@ export default connect({
mapStateToProps: (state) => ({
allTracks: state.data.allTracks,
filteredTracks: state.data.filteredTracks,
+ favoritesOnly: state.data.favoritesOnly,
}),
mapDispatchToProps: {
updateFilteredTracks,
+ setFavoritesOnly,
},
component: SessionListFilter,
});
diff --git a/src/components/SessionListItem.tsx b/src/components/SessionListItem.tsx
index f38c86d5..c19344e3 100644
--- a/src/components/SessionListItem.tsx
+++ b/src/components/SessionListItem.tsx
@@ -1,5 +1,6 @@
import type { AlertButton } from '@ionic/react';
-import { IonItemSliding, IonItem, IonLabel, IonItemOptions, IonItemOption, useIonToast } from '@ionic/react';
+import { IonIcon, IonItemSliding, IonItem, IonLabel, IonItemOptions, IonItemOption, useIonToast } from '@ionic/react';
+import { star } from 'ionicons/icons';
import React, { useRef } from 'react';
import type { Session } from '../models/Schedule';
@@ -80,6 +81,9 @@ const SessionListItem: React.FC = ({
{session.location}
+ {isFavorite && (
+
+ )}
{listType === 'favorites' ? (
diff --git a/src/data/sessions/conf.state.ts b/src/data/sessions/conf.state.ts
index 24bd4ef9..a8cd18f6 100644
--- a/src/data/sessions/conf.state.ts
+++ b/src/data/sessions/conf.state.ts
@@ -9,6 +9,7 @@ export interface ConfState {
favorites: number[];
locations: Location[];
filteredTracks: string[];
+ favoritesOnly: boolean;
searchText?: string;
mapCenterId?: number;
loading?: boolean;
diff --git a/src/data/sessions/sessions.actions.ts b/src/data/sessions/sessions.actions.ts
index 03cde7f8..cd0a4d5b 100644
--- a/src/data/sessions/sessions.actions.ts
+++ b/src/data/sessions/sessions.actions.ts
@@ -42,6 +42,12 @@ export const updateFilteredTracks = (filteredTracks: string[]) =>
filteredTracks,
}) as const;
+export const setFavoritesOnly = (favoritesOnly: boolean) =>
+ ({
+ type: 'set-favorites-only',
+ favoritesOnly,
+ }) as const;
+
export const setSearchText = (searchText?: string) =>
({
type: 'set-search-text',
@@ -60,5 +66,6 @@ export type SessionsActions =
| ActionType
| ActionType
| ActionType
+ | ActionType
| ActionType
| ActionType;
diff --git a/src/data/sessions/sessions.reducer.ts b/src/data/sessions/sessions.reducer.ts
index e2627fec..a324bc03 100644
--- a/src/data/sessions/sessions.reducer.ts
+++ b/src/data/sessions/sessions.reducer.ts
@@ -24,6 +24,9 @@ export const sessionsReducer = (state: ConfState, action: SessionsActions): Conf
case 'update-filtered-tracks': {
return { ...state, filteredTracks: action.filteredTracks };
}
+ case 'set-favorites-only': {
+ return { ...state, favoritesOnly: action.favoritesOnly };
+ }
case 'set-search-text': {
return { ...state, searchText: action.searchText };
}
diff --git a/src/data/state.test.ts b/src/data/state.test.ts
index a5e44971..fbb8e643 100644
--- a/src/data/state.test.ts
+++ b/src/data/state.test.ts
@@ -9,6 +9,7 @@ import {
setData as setConfData,
setLoading as setConfLoading,
setMenuEnabled,
+ setFavoritesOnly,
setSearchText,
updateFilteredTracks,
} from './sessions/sessions.actions';
@@ -61,6 +62,14 @@ describe('sessions reducer', () => {
expect(state.data.searchText).toBe('ionic');
});
+ it('turns Favorites only on and off', () => {
+ let state = reducers(makeState(), setFavoritesOnly(true));
+ expect(state.data.favoritesOnly).toBe(true);
+
+ state = reducers(state, setFavoritesOnly(false));
+ expect(state.data.favoritesOnly).toBe(false);
+ });
+
it('merges loaded conference data and tracks loading', () => {
let state = reducers(initialState, setConfLoading(true));
expect(state.data.loading).toBe(true);
diff --git a/src/data/state.ts b/src/data/state.ts
index 87d14d61..43720999 100644
--- a/src/data/state.ts
+++ b/src/data/state.ts
@@ -12,6 +12,7 @@ export const initialState: AppState = {
locations: [],
allTracks: [],
filteredTracks: [],
+ favoritesOnly: false,
mapCenterId: 0,
loading: false,
menuEnabled: true,
diff --git a/src/pages/SchedulePage.scss b/src/pages/SchedulePage.scss
index aa897500..c894616b 100644
--- a/src/pages/SchedulePage.scss
+++ b/src/pages/SchedulePage.scss
@@ -15,6 +15,60 @@
--background-activated: var(--ion-color-step-250, #d9d9d9);
}
+ .filtered-by {
+ display: block;
+ width: 100%;
+ padding: 4px 16px 8px;
+ border: 0;
+ background: none;
+ color: var(--ion-color-step-600, #666);
+ font-family: inherit;
+ font-size: 13px;
+ text-align: center;
+ cursor: pointer;
+ }
+
+ .filtered-by-value {
+ color: var(--ion-color-primary);
+ }
+
+ .filter-chips {
+ display: flex;
+ gap: 8px;
+ padding: 16px 16px 8px;
+ }
+
+ .filter-chip {
+ display: inline-flex;
+ position: relative;
+ align-items: center;
+ gap: 4px;
+ height: 32px;
+ padding: 0 12px;
+ overflow: hidden;
+ border: 0;
+ border-radius: 16px;
+ background: rgba(var(--ion-text-color-rgb, 0, 0, 0), 0.12);
+ color: rgba(var(--ion-text-color-rgb, 0, 0, 0), 0.87);
+ font-family: inherit;
+ font-size: 14px;
+ cursor: pointer;
+ }
+
+ .filter-chip ion-icon {
+ font-size: 18px;
+ }
+
+ .filter-chip-selected {
+ padding-inline-start: 8px;
+ background: rgba(var(--ion-color-primary-rgb), 0.12);
+ color: var(--ion-color-primary);
+ }
+
+ .favorite-indicator {
+ font-size: 16px;
+ }
+
ion-item-sliding.track-ionic ion-label {
border-left: 2px solid var(--ion-color-primary);
padding-left: 10px;
diff --git a/src/pages/SchedulePage.test.tsx b/src/pages/SchedulePage.test.tsx
index fdd032de..08ea7019 100644
--- a/src/pages/SchedulePage.test.tsx
+++ b/src/pages/SchedulePage.test.tsx
@@ -1,6 +1,6 @@
import { setupIonicReact } from '@ionic/react';
-import { screen, within } from '@testing-library/react';
-import { beforeAll, describe, expect, it } from 'vitest';
+import { fireEvent, screen, within } from '@testing-library/react';
+import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import { ionicTooling, makeState, reactSession } from '../testing/fixtures';
import { renderWithState } from '../testing/render';
@@ -12,7 +12,7 @@ beforeAll(() => {
setupIonicReact({ mode: 'md' });
});
-// The page renders the All and Favorites lists, and hides the one that isn't selected.
+// The page renders the All and Favorites lists, and hides the one that Favorites only doesn't show.
const lists = (container: HTMLElement) => {
const [all, favorites] = Array.from(container.querySelectorAll('ion-content ion-list'));
return { all: all as HTMLElement, favorites: favorites as HTMLElement };
@@ -66,6 +66,106 @@ describe('SchedulePage', () => {
expect(lists(container).favorites.style.display).toBe('none');
});
+ it('shows only the favorites list when Favorites only is on', () => {
+ const { container } = renderWithState(, {
+ state: makeState({ data: { favorites: [ionicTooling.id], favoritesOnly: true } }),
+ });
+
+ expect(sessionNames(lists(container).favorites)).toEqual(['Ionic Tooling']);
+ expect(lists(container).favorites.style.display).toBe('');
+ expect(lists(container).all.style.display).toBe('none');
+ });
+
+ describe('filter chips', () => {
+ const chips = (container: HTMLElement) => Array.from(container.querySelectorAll('.filter-chip'));
+ const selected = (container: HTMLElement) =>
+ chips(container).map((chip) => chip.classList.contains('filter-chip-selected'));
+
+ it('shows unselected Favorites and Tracks chips when nothing is filtered', () => {
+ const { container } = renderWithState(, { state: makeState() });
+
+ expect(chips(container).map((chip) => chip.textContent)).toEqual(['Favorites', 'Tracks']);
+ expect(selected(container)).toEqual([false, false]);
+ expect(screen.getByRole('button', { name: 'Favorites' })).toHaveAttribute('aria-pressed', 'false');
+ });
+
+ it('selects the chips and counts the shown tracks when filtered', () => {
+ const { container } = renderWithState(, {
+ state: makeState({ data: { favoritesOnly: true, filteredTracks: ['Ionic', 'React'] } }),
+ });
+
+ expect(chips(container).map((chip) => chip.textContent)).toEqual(['Favorites', '2 of 4 Tracks']);
+ expect(chips(container)[1]).toHaveAttribute('aria-haspopup', 'dialog');
+ expect(selected(container)).toEqual([true, true]);
+ expect(screen.getByRole('button', { name: 'Favorites' })).toHaveAttribute('aria-pressed', 'true');
+ });
+
+ it('names the track when only one track is shown', () => {
+ const { container } = renderWithState(, {
+ state: makeState({ data: { filteredTracks: ['React'] } }),
+ });
+
+ expect(chips(container)[1].textContent).toBe('React');
+ });
+
+ it('turns Favorites only on and off from the Favorites chip', () => {
+ const { container } = renderWithState(, {
+ state: makeState({ data: { favorites: [ionicTooling.id] } }),
+ });
+ const favoritesChip = screen.getByRole('button', { name: 'Favorites' });
+
+ fireEvent.click(favoritesChip);
+ expect(favoritesChip).toHaveAttribute('aria-pressed', 'true');
+ expect(lists(container).all.style.display).toBe('none');
+
+ fireEvent.click(favoritesChip);
+ expect(favoritesChip).toHaveAttribute('aria-pressed', 'false');
+ expect(lists(container).all.style.display).toBe('');
+ });
+
+ it('does not show the Filtered by line', () => {
+ const { container } = renderWithState(, {
+ state: makeState({ data: { favoritesOnly: true } }),
+ });
+
+ expect(container.querySelector('.filtered-by')).toBeNull();
+ });
+ });
+
+ describe('Filtered by line on iOS', () => {
+ beforeAll(() => {
+ setupIonicReact({ mode: 'ios' });
+ });
+
+ afterAll(() => {
+ setupIonicReact({ mode: 'md' });
+ });
+
+ it('shows no Filtered by line or chips when nothing is filtered', () => {
+ const { container } = renderWithState(, { state: makeState() });
+
+ expect(container.querySelector('.filtered-by')).toBeNull();
+ expect(container.querySelector('.filter-chip')).toBeNull();
+ });
+
+ it('lists the active filters', () => {
+ const { container } = renderWithState(, {
+ state: makeState({ data: { favoritesOnly: true, filteredTracks: ['Ionic', 'React'] } }),
+ });
+
+ expect(container.querySelector('.filtered-by')?.textContent).toBe('Filtered by: Favorites, 2 of 4 Tracks');
+ expect(container.querySelector('.filtered-by')).toHaveAttribute('aria-haspopup', 'dialog');
+ });
+
+ it('lists only the track filter when favorites are not filtered', () => {
+ const { container } = renderWithState(, {
+ state: makeState({ data: { filteredTracks: ['React'] } }),
+ });
+
+ expect(container.querySelector('.filtered-by')?.textContent).toBe('Filtered by: React');
+ });
+ });
+
it('shows an empty state when no session matches', () => {
renderWithState(, { state: makeState({ data: { filteredTracks: [] } }) });
diff --git a/src/pages/SchedulePage.tsx b/src/pages/SchedulePage.tsx
index 543141d3..f6cceb6d 100644
--- a/src/pages/SchedulePage.tsx
+++ b/src/pages/SchedulePage.tsx
@@ -5,8 +5,6 @@ import {
IonButtons,
IonTitle,
IonMenuButton,
- IonSegment,
- IonSegmentButton,
IonButton,
IonIcon,
IonSearchbar,
@@ -15,9 +13,10 @@ import {
IonToast,
IonModal,
IonHeader,
+ IonRippleEffect,
getConfig,
} from '@ionic/react';
-import { options, search } from 'ionicons/icons';
+import { caretDown, checkmark, options, search } from 'ionicons/icons';
import React, { useState, useRef } from 'react';
import SessionList from '../components/SessionList';
@@ -25,7 +24,7 @@ import SessionListFilter from '../components/SessionListFilter';
import ShareSocialFab from '../components/ShareSocialFab';
import { connect } from '../data/connect';
import * as selectors from '../data/selectors';
-import { setSearchText } from '../data/sessions/sessions.actions';
+import { setFavoritesOnly, setSearchText } from '../data/sessions/sessions.actions';
import type { Schedule } from '../models/Schedule';
import './SchedulePage.scss';
@@ -34,17 +33,29 @@ interface OwnProps {}
interface StateProps {
schedule: Schedule;
favoritesSchedule: Schedule;
+ favoritesOnly: boolean;
+ allTracks: string[];
+ filteredTracks: string[];
mode: 'ios' | 'md';
}
interface DispatchProps {
setSearchText: typeof setSearchText;
+ setFavoritesOnly: typeof setFavoritesOnly;
}
type SchedulePageProps = OwnProps & StateProps & DispatchProps;
-const SchedulePage: React.FC = ({ favoritesSchedule, schedule, setSearchText, mode }) => {
- const [segment, setSegment] = useState<'all' | 'favorites'>('all');
+const SchedulePage: React.FC = ({
+ favoritesSchedule,
+ favoritesOnly,
+ allTracks,
+ filteredTracks,
+ schedule,
+ setSearchText,
+ setFavoritesOnly,
+ mode,
+}) => {
const [showSearchbar, setShowSearchbar] = useState(false);
const [showFilterModal, setShowFilterModal] = useState(false);
const ionRefresherRef = useRef(null);
@@ -54,6 +65,11 @@ const SchedulePage: React.FC = ({ favoritesSchedule, schedule
const ios = mode === 'ios';
+ const tracksFiltered = filteredTracks.length < allTracks.length;
+ const trackSummary =
+ filteredTracks.length === 1 ? filteredTracks[0] : `${filteredTracks.length} of ${allTracks.length} Tracks`;
+ const filterSummary = [favoritesOnly && 'Favorites', tracksFiltered && trackSummary].filter(Boolean).join(', ');
+
const doRefresh = () => {
setTimeout(() => {
ionRefresherRef.current!.complete();
@@ -70,13 +86,7 @@ const SchedulePage: React.FC = ({ favoritesSchedule, schedule
)}
- {ios && (
- setSegment(e.detail.value as any)}>
- All
- Favorites
-
- )}
- {!ios && !showSearchbar && Schedule}
+ {!showSearchbar && Schedule}
{showSearchbar && (
= ({ favoritesSchedule, schedule
)}
-
- {!ios && (
-
- setSegment(e.detail.value as any)}>
- All
- Favorites
-
-
- )}
@@ -138,8 +139,37 @@ const SchedulePage: React.FC = ({ favoritesSchedule, schedule
onDidDismiss={() => setShowCompleteToast(false)}
/>
-
-
+ {ios && filterSummary && (
+
+ )}
+ {!ios && (
+
+
+
+
+ )}
+
+
+
({
mapStateToProps: (state) => ({
schedule: selectors.getSearchedSchedule(state),
favoritesSchedule: selectors.getGroupedFavorites(state),
+ favoritesOnly: state.data.favoritesOnly,
+ allTracks: state.data.allTracks,
+ filteredTracks: state.data.filteredTracks,
mode: getConfig()!.get('mode'),
}),
mapDispatchToProps: {
setSearchText,
+ setFavoritesOnly,
},
component: React.memo(SchedulePage),
});