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

Dashboard: Telemetry Opt In Banner #4374

Merged
merged 34 commits into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
cb6cbba
wip
dmmulroy Sep 4, 2020
2eb1ee9
Merge branch 'feature/dashboard-telemetry-setting' into feature/4226-…
dmmulroy Sep 4, 2020
ce7b62f
wip
dmmulroy Sep 4, 2020
28b0e26
add initial component
dmmulroy Sep 4, 2020
280e14f
remove id
dmmulroy Sep 7, 2020
2851cc6
write useTelemetryOptIn hook, add container for component
dmmulroy Sep 7, 2020
ec18526
add/finish storybook
dmmulroy Sep 7, 2020
dad955f
write initial test
dmmulroy Sep 7, 2020
ac49350
add unit tests for telemetry banner
dmmulroy Sep 7, 2020
071f427
add test for disabled input + add user-event dep
dmmulroy Sep 7, 2020
a0d9f82
Merge branch 'main' into feature/4226-telemetry-banner
dmmulroy Sep 7, 2020
64b1714
refactor EditorSettings view to use useTelemetryOptIn
dmmulroy Sep 7, 2020
aaec029
add karma tests
dmmulroy Sep 7, 2020
fc6631d
update hook to prevent unneeded fetchCurrentUser requests
dmmulroy Sep 7, 2020
ed9144b
refactor hook logic
dmmulroy Sep 7, 2020
ad1157d
comments
dmmulroy Sep 7, 2020
1eebb8e
update karma tests
dmmulroy Sep 7, 2020
4034426
update i18n and previously closed logic
dmmulroy Sep 8, 2020
ed69ab5
remove link
dmmulroy Sep 8, 2020
9e2690c
Update assets/src/dashboard/app/views/shared/telemetryBanner.js
dmmulroy Sep 8, 2020
20a6c28
add local storage clear to fixture restore to fix karma tests
dmmulroy Sep 8, 2020
48ae173
update banner header + tests
dmmulroy Sep 8, 2020
00e57e9
grammar
dmmulroy Sep 8, 2020
a4f8c67
Add MockApiProvider and new render util
dmmulroy Sep 8, 2020
ae12dd0
update tests to use renderWithProviders
dmmulroy Sep 8, 2020
f6335c4
update tests to use renderWithProviders
dmmulroy Sep 8, 2020
ca512f8
Merge branch 'feature/4226-telemetry-banner' of github.com:google/web…
dmmulroy Sep 8, 2020
c3a927a
Fix telemetry banner background image
swissspidy Sep 10, 2020
a998586
Make some REST API tests more consistent
swissspidy Sep 10, 2020
cb1b9e6
Tracking: allow any user to update their own opt-in preferences
swissspidy Sep 10, 2020
3dd015c
Fix typo in file name
swissspidy Sep 10, 2020
ef06bf4
Enable settings page for non-admins
swissspidy Sep 10, 2020
48fe14a
Merge branch 'main' into feature/4226-telemetry-banner
dmmulroy Sep 10, 2020
8cdd9ab
Merge branch 'feature/4226-telemetry-banner' of github.com:google/web…
dmmulroy Sep 10, 2020
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
Binary file added assets/images/analytics-banner-bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 10 additions & 14 deletions assets/src/dashboard/app/views/editorSettings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
} from '../../../constants';
import { useConfig } from '../../config';
import { PageHeading } from '../shared';
import useTelemetryOptIn from '../shared/useTelemetryOptIn';
import GoogleAnalyticsSettings from './googleAnalytics';
import { Main, Wrapper } from './components';
import PublisherLogoSettings from './publisherLogo';
Expand All @@ -45,11 +46,8 @@ const ACTIVE_DIALOG_REMOVE_LOGO = 'REMOVE_LOGO';

function EditorSettings() {
const {
currentUser,
fetchCurrentUser,
fetchSettings,
updateSettings,
toggleWebStoriesTrackingOptIn,
googleAnalyticsId,
fetchMediaById,
uploadMedia,
Expand All @@ -63,7 +61,6 @@ function EditorSettings() {
actions: {
settingsApi: { fetchSettings, updateSettings },
mediaApi: { fetchMediaById, uploadMedia },
usersApi: { fetchCurrentUser, toggleWebStoriesTrackingOptIn },
},
state: {
settings: {
Expand All @@ -72,7 +69,6 @@ function EditorSettings() {
publisherLogoIds,
},
media: { isLoading: isMediaLoading, mediaById, newlyCreatedMediaIds },
currentUser,
},
}) => ({
fetchSettings,
Expand All @@ -85,9 +81,6 @@ function EditorSettings() {
mediaById,
newlyCreatedMediaIds,
publisherLogoIds,
fetchCurrentUser,
toggleWebStoriesTrackingOptIn,
currentUser,
})
);

Expand All @@ -97,6 +90,12 @@ function EditorSettings() {
maxUploadFormatted,
} = useConfig();

const {
disabled,
toggleWebStoriesTrackingOptIn,
optedIn,
} = useTelemetryOptIn();

dmmulroy marked this conversation as resolved.
Show resolved Hide resolved
const [activeDialog, setActiveDialog] = useState(null);
const [activeLogo, setActiveLogo] = useState('');
const [mediaError, setMediaError] = useState('');
Expand All @@ -112,8 +111,7 @@ function EditorSettings() {

useEffect(() => {
fetchSettings();
fetchCurrentUser();
}, [fetchCurrentUser, fetchSettings]);
}, [fetchSettings]);

useEffect(() => {
if (newlyCreatedMediaIds.length > 0) {
Expand Down Expand Up @@ -278,11 +276,9 @@ function EditorSettings() {
uploadError={mediaError}
/>
<TelemetrySettings
disabled={currentUser.isUpdating}
disabled={disabled}
onCheckboxSelected={toggleWebStoriesTrackingOptIn}
selected={Boolean(
currentUser.data.meta?.web_stories_tracking_optin
)}
selected={optedIn}
/>
</Main>
</Layout.Scrollable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
VIEW_STYLE,
TEMPLATES_GALLERY_SORT_OPTIONS,
} from '../../../../../constants';
import { renderWithThemeAndFlagsProvider } from '../../../../../testUtils';
import { renderWithProviders } from '../../../../../testUtils';
import LayoutProvider from '../../../../../components/layout/provider';
import Header from '../';

Expand Down Expand Up @@ -69,7 +69,7 @@ const fakeTemplates = [

describe('Explore Templates <Header />', function () {
it('should have results label that says "Viewing all templates" on initial page view', function () {
const { getByText } = renderWithThemeAndFlagsProvider(
const { getByText } = renderWithProviders(
<LayoutProvider>
<Header
filter={{ value: TEMPLATES_GALLERY_STATUS.ALL }}
Expand All @@ -86,14 +86,14 @@ describe('Explore Templates <Header />', function () {
}}
/>
</LayoutProvider>,
{ enableInProgressTemplateActions: false }
{ features: { enableInProgressTemplateActions: false } }
);

expect(getByText('Viewing all templates')).toBeInTheDocument();
});

it('should render with the correct count label and search keyword.', function () {
const { getByPlaceholderText, getByText } = renderWithThemeAndFlagsProvider(
const { getByPlaceholderText, getByText } = renderWithProviders(
<LayoutProvider>
<Header
filter={{ value: TEMPLATES_GALLERY_STATUS.ALL }}
Expand All @@ -110,15 +110,15 @@ describe('Explore Templates <Header />', function () {
}}
/>
</LayoutProvider>,
{ enableInProgressTemplateActions: true }
{ features: { enableInProgressTemplateActions: true } }
);
expect(getByPlaceholderText('Search Templates').value).toBe('Harry Potter');
expect(getByText('8 results')).toBeInTheDocument();
});

it('should call the set keyword function when new text is searched', function () {
const setKeywordFn = jest.fn();
const { getByPlaceholderText } = renderWithThemeAndFlagsProvider(
const { getByPlaceholderText } = renderWithProviders(
<LayoutProvider>
<Header
filter={{ value: TEMPLATES_GALLERY_STATUS.ALL }}
Expand All @@ -135,7 +135,7 @@ describe('Explore Templates <Header />', function () {
}}
/>
</LayoutProvider>,
{ enableInProgressTemplateActions: true }
{ features: { enableInProgressTemplateActions: true } }
);
fireEvent.change(getByPlaceholderText('Search Templates'), {
target: { value: 'Hermione Granger' },
Expand All @@ -145,7 +145,7 @@ describe('Explore Templates <Header />', function () {

it('should call the set sort function when a new sort is selected', function () {
const setSortFn = jest.fn();
const { getAllByText, getByText } = renderWithThemeAndFlagsProvider(
const { getAllByText, getByText } = renderWithProviders(
<LayoutProvider>
<Header
filter={{ value: TEMPLATES_GALLERY_STATUS.ALL }}
Expand All @@ -162,16 +162,16 @@ describe('Explore Templates <Header />', function () {
}}
/>
</LayoutProvider>,
{ enableInProgressTemplateActions: true }
{ features: { enableInProgressTemplateActions: true } }
);
fireEvent.click(getAllByText('Popular')[0].parentElement);
fireEvent.click(getByText('Recent'));

expect(setSortFn).toHaveBeenCalledWith('recent');
});

it('should not render with search when enableInProgressTemplateActions is false', function () {
const { queryAllByRole } = renderWithThemeAndFlagsProvider(
it('should not render with search when features:{enableInProgressTemplateActions is false}', function () {
const { queryAllByRole } = renderWithProviders(
<LayoutProvider>
<Header
filter={{ value: TEMPLATES_GALLERY_STATUS.ALL }}
Expand All @@ -188,7 +188,7 @@ describe('Explore Templates <Header />', function () {
}}
/>
</LayoutProvider>,
{ enableInProgressTemplateActions: false }
{ features: { enableInProgressTemplateActions: false } }
);
expect(queryAllByRole('textbox')).toHaveLength(0);
});
Expand Down
14 changes: 7 additions & 7 deletions assets/src/dashboard/app/views/myStories/header/test/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
STORY_STATUSES,
} from '../../../../../constants';
import LayoutProvider from '../../../../../components/layout/provider';
import { renderWithTheme } from '../../../../../testUtils';
import { renderWithProviders } from '../../../../../testUtils';
import Header from '../';

const fakeStories = [
Expand Down Expand Up @@ -64,7 +64,7 @@ const fakeStories = [

describe('My Stories <Header />', function () {
it('should have results label that says "Viewing all stories" on initial page view', function () {
const { getByText } = renderWithTheme(
const { getByText } = renderWithProviders(
<LayoutProvider>
<Header
filter={STORY_STATUSES[0]}
Expand All @@ -88,7 +88,7 @@ describe('My Stories <Header />', function () {
});

it('should render with the correct count label and search keyword.', function () {
const { getByPlaceholderText, getByText } = renderWithTheme(
const { getByPlaceholderText, getByText } = renderWithProviders(
<LayoutProvider>
<Header
filter={STORY_STATUSES[0]}
Expand All @@ -113,7 +113,7 @@ describe('My Stories <Header />', function () {
});

it('should have results label that says "Viewing drafts" when filter is set to drafts', function () {
const { getByText } = renderWithTheme(
const { getByText } = renderWithProviders(
<LayoutProvider>
<Header
filter={{ status: 'DRAFT', value: STORY_STATUS.DRAFT }}
Expand All @@ -137,7 +137,7 @@ describe('My Stories <Header />', function () {
});

it('should have 3 toggle buttons, one for each status that say how many items belong to that status', function () {
const { getByText } = renderWithTheme(
const { getByText } = renderWithProviders(
<LayoutProvider>
<Header
filter={STORY_STATUSES[0]}
Expand All @@ -164,7 +164,7 @@ describe('My Stories <Header />', function () {

it('should call the set keyword function when new text is searched', async function () {
const setKeywordFn = jest.fn();
const { getByPlaceholderText } = renderWithTheme(
const { getByPlaceholderText } = renderWithProviders(
<LayoutProvider>
<Header
filter={STORY_STATUSES[0]}
Expand Down Expand Up @@ -194,7 +194,7 @@ describe('My Stories <Header />', function () {

it('should call the set sort function when a new sort is selected', function () {
const setSortFn = jest.fn();
const { getAllByText, getByText } = renderWithTheme(
const { getAllByText, getByText } = renderWithProviders(
<LayoutProvider>
<Header
filter={STORY_STATUSES[0]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/
import { fireEvent } from '@testing-library/react';
import { SavedTemplatesContent, SavedTemplatesHeader } from '../index';
import { renderWithThemeAndFlagsProvider } from '../../../../testUtils';
import { renderWithProviders } from '../../../../testUtils';
import {
STORY_SORT_OPTIONS,
VIEW_STYLE,
Expand Down Expand Up @@ -68,7 +68,7 @@ describe('<SavedTemplates />', function () {
});

it('should render with the correct count label and search keyword.', function () {
const { getByPlaceholderText, getByText } = renderWithThemeAndFlagsProvider(
const { getByPlaceholderText, getByText } = renderWithProviders(
<LayoutProvider>
<SavedTemplatesHeader
filter={{ value: SAVED_TEMPLATES_STATUSES.ALL }}
Expand All @@ -81,15 +81,15 @@ describe('<SavedTemplates />', function () {
}}
/>
</LayoutProvider>,
{ enableInProgressStoryActions: false }
{ features: { enableInProgressStoryActions: false } }
);
expect(getByPlaceholderText('Search Templates').value).toBe('Harry Potter');
expect(getByText('3 results')).toBeInTheDocument();
});

it('should call the set keyword function when new text is searched', function () {
const setKeywordFn = jest.fn();
const { getByPlaceholderText } = renderWithThemeAndFlagsProvider(
const { getByPlaceholderText } = renderWithProviders(
<LayoutProvider>
<SavedTemplatesHeader
filter={{ value: SAVED_TEMPLATES_STATUSES.ALL }}
Expand All @@ -102,7 +102,7 @@ describe('<SavedTemplates />', function () {
}}
/>
</LayoutProvider>,
{ enableInProgressStoryActions: false }
{ features: { enableInProgressStoryActions: false } }
);
fireEvent.change(getByPlaceholderText('Search Templates'), {
target: { value: 'Hermione Granger' },
Expand All @@ -112,7 +112,7 @@ describe('<SavedTemplates />', function () {

it('should call the set sort function when a new sort is selected', function () {
const setSortFn = jest.fn();
const { getAllByText, getByText } = renderWithThemeAndFlagsProvider(
const { getAllByText, getByText } = renderWithProviders(
<LayoutProvider>
<SavedTemplatesHeader
filter={{ value: SAVED_TEMPLATES_STATUSES.ALL }}
Expand All @@ -125,7 +125,7 @@ describe('<SavedTemplates />', function () {
}}
/>
</LayoutProvider>,
{ enableInProgressStoryActions: false }
{ features: { enableInProgressStoryActions: false } }
);
fireEvent.click(getAllByText('Created by')[0].parentElement);
fireEvent.click(getByText('Last modified'));
Expand All @@ -134,7 +134,7 @@ describe('<SavedTemplates />', function () {
});

it('should render the content grid with the correct story count.', function () {
const { getAllByText } = renderWithThemeAndFlagsProvider(
const { getAllByText } = renderWithProviders(
<LayoutProvider>
<SavedTemplatesContent
stories={fakeStories}
Expand All @@ -147,7 +147,7 @@ describe('<SavedTemplates />', function () {
}}
/>
</LayoutProvider>,
{ enableInProgressStoryActions: false }
{ features: { enableInProgressStoryActions: false } }
);

expect(getAllByText('Use template')).toHaveLength(fakeStories.length);
Expand Down
Loading