Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
82 changes: 48 additions & 34 deletions assets/js/components/email-reporting/FrequencySelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import {
} from '@/js/googlesitekit/datastore/user/constants';
import { Fragment } from 'react';
import Typography from '@/js/components/Typography';
import Tick from '@/svg/icons/tick.svg';

export default function FrequencySelector( { isUserSubscribed } ) {
const DAY_NAMES = useMemo(
Expand Down Expand Up @@ -118,6 +117,12 @@ export default function FrequencySelector( { isUserSubscribed } ) {
}
}

// Determine which column the saved frequency is in (0, 1, or 2).
const savedFrequencyIndex =
EMAIL_REPORT_FREQUENCIES.indexOf( savedFrequency );
const showCurrentSubscription =
isUserSubscribed && savedFrequencyIndex !== -1;

return (
<Fragment>
<Typography
Expand All @@ -128,6 +133,33 @@ export default function FrequencySelector( { isUserSubscribed } ) {
>
{ __( 'Frequency', 'google-site-kit' ) }
</Typography>
{ showCurrentSubscription && (
<div className="googlesitekit-frequency-selector__badge-row">
{ EMAIL_REPORT_FREQUENCIES.map(
( reportFrequency, index ) => (
<div
key={ reportFrequency }
className="googlesitekit-frequency-selector__badge-cell"
>
{ index === savedFrequencyIndex && (
<div className="googlesitekit-frequency-selector__current-subscription">
<Typography
type="body"
size="small"
as="p"
>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, use the <P> component.

{ __(
'Current subscription',
'google-site-kit'
) }
</Typography>
</div>
) }
</div>
)
) }
</div>
) }
<div
className="googlesitekit-frequency-selector"
role="radiogroup"
Expand Down Expand Up @@ -159,42 +191,24 @@ export default function FrequencySelector( { isUserSubscribed } ) {
}
>
<div className="googlesitekit-frequency-selector__label-row">
<Typography
className="googlesitekit-frequency-selector__label"
type="label"
size="large"
as="div"
>
{ label }
<div className="googlesitekit-frequency-selector__label">
<Typography type="label" size="large">
{ label }
</Typography>
</div>
</div>

<div className="googlesitekit-frequency-selector__period">
<Typography type="body" size="small">
{ period }
</Typography>
{ savedFrequency === reportFrequency &&
isUserSubscribed && (
<div className="googlesitekit-frequency-selector__saved-indicator">
<Tick
className="googlesitekit-frequency-selector__label-tick"
aria-hidden="true"
/>
</div>
) }
</div>

<Typography
className="googlesitekit-frequency-selector__period"
type="body"
size="small"
as="div"
>
{ period }
</Typography>

<Typography
className="googlesitekit-frequency-selector__description"
type="body"
size="small"
as="div"
>
{ description }
</Typography>
<div className="googlesitekit-frequency-selector__description">
<Typography type="body" size="small">
{ description }
</Typography>
</div>
</div>
);
} ) }
Expand Down
12 changes: 0 additions & 12 deletions assets/js/components/email-reporting/FrequencySelector.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,3 @@ PreviouslySavedFrequency.args = {
},
};
PreviouslySavedFrequency.scenario = {};

export const PreviouslySavedFrequencySameAsCurrent = Template.bind( {} );
PreviouslySavedFrequencySameAsCurrent.args = {
isUserSubscribed: true,
savedSettings: {
frequency: 'monthly',
},
clientSettings: {
frequency: 'monthly',
},
};
PreviouslySavedFrequencySameAsCurrent.scenario = {};
80 changes: 37 additions & 43 deletions assets/js/components/email-reporting/FrequencySelector.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,79 +108,73 @@ describe( 'FrequencySelector', () => {
expect( containerElement ).toMatchSnapshot();
} );

it( 'Previously saved frequency (saved monthly, current weekly) indicates saved on monthly only and matches snapshot', () => {
it( 'Previously saved frequency (saved monthly, current weekly) shows current subscription pill above monthly card and matches snapshot', () => {
setupRegistry( registry, {
startOfWeek: 1,
frequency: 'weekly',
savedFrequency: 'monthly',
} );

const { containerElement, getByText } = renderSelector( registry, {
isUserSubscribed: true,
} );

const indicators = containerElement.querySelectorAll(
'.googlesitekit-frequency-selector__saved-indicator'
const { container, containerElement, getByText } = renderSelector(
registry,
{
isUserSubscribed: true,
}
);
expect( indicators.length ).toBe( 1 );

const monthlyLabel = getByText( 'Monthly' );
const monthlyCard = monthlyLabel.closest(
'.googlesitekit-frequency-selector__card'
// Check that there's exactly one current subscription pill.
const pills = container.querySelectorAll(
'.googlesitekit-frequency-selector__current-subscription'
);
expect( monthlyCard ).toBeTruthy();
expect(
monthlyCard.querySelector(
'.googlesitekit-frequency-selector__saved-indicator'
)
).toBeInTheDocument();
expect( pills.length ).toBe( 1 );

const weeklyLabel = getByText( 'Weekly' );
const weeklyCard = weeklyLabel.closest(
'.googlesitekit-frequency-selector__card'
// Check that the badge row exists and contains the pill.
const badgeRow = container.querySelector(
'.googlesitekit-frequency-selector__badge-row'
);
expect( badgeRow ).toBeInTheDocument();
expect(
weeklyCard.querySelector(
'.googlesitekit-frequency-selector__saved-indicator'
badgeRow.querySelector(
'.googlesitekit-frequency-selector__current-subscription'
)
).not.toBeInTheDocument();
).toBeInTheDocument();

const quarterlyLabel = getByText( 'Quarterly' );
const quarterlyCard = quarterlyLabel.closest(
'.googlesitekit-frequency-selector__card'
);
expect(
quarterlyCard.querySelector(
'.googlesitekit-frequency-selector__saved-indicator'
)
).not.toBeInTheDocument();
// Check that the pill text is correct.
expect( getByText( 'Current subscription' ) ).toBeInTheDocument();

expect( containerElement ).toMatchSnapshot();
} );

it( 'Previously saved frequency (same as the current frequency) shows saved indicator on selected card and matches snapshot', () => {
it( 'Previously saved frequency (same as the current frequency) shows current subscription pill above selected card and matches snapshot', () => {
setupRegistry( registry, {
startOfWeek: 1,
frequency: 'monthly',
savedFrequency: 'monthly',
} );

const { containerElement, getByText } = renderSelector( registry, {
isUserSubscribed: true,
} );

const monthlyLabel = getByText( 'Monthly' );
const monthlyCard = monthlyLabel.closest(
'.googlesitekit-frequency-selector__card'
const { container, containerElement, getByText } = renderSelector(
registry,
{
isUserSubscribed: true,
}
);
expect( monthlyCard ).toBeTruthy();

// Check that there's exactly one current subscription pill in the badge row.
const badgeRow = container.querySelector(
'.googlesitekit-frequency-selector__badge-row'
);
expect( badgeRow ).toBeInTheDocument();
expect(
monthlyCard.querySelector(
'.googlesitekit-frequency-selector__saved-indicator'
badgeRow.querySelector(
'.googlesitekit-frequency-selector__current-subscription'
)
).toBeInTheDocument();

// Check that the monthly card is selected.
const monthlyLabel = getByText( 'Monthly' );
const monthlyCard = monthlyLabel.closest(
'.googlesitekit-frequency-selector__card'
);
expect(
monthlyCard.classList.contains(
'googlesitekit-frequency-selector__card--selected'
Expand Down
Loading
Loading