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

feat: add settings panel #417

Merged
merged 3 commits into from
Mar 18, 2021
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
18 changes: 17 additions & 1 deletion __tests__/BookmarksPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import { LoggedUser } from '../lib/user';
import BookmarksPage from '../pages/bookmarks';
import { NextRouter, useRouter } from 'next/router';
import { mocked } from 'ts-jest/utils';
import SettingsContext, {
SettingsContextData,
} from '../contexts/SettingsContext';

const showLogin = jest.fn();
const routerReplace = jest.fn();
Expand All @@ -38,6 +41,7 @@ const createFeedMock = (
variables: unknown = {
first: 7,
loggedIn: true,
unreadOnly: false,
},
): MockedGraphQLResponse<FeedData> => ({
request: {
Expand All @@ -59,6 +63,16 @@ const renderComponent = (

mocks.forEach(mockGraphQL);
nock('http://localhost:3000').get('/v1/a').reply(200, [ad]);
const settingsContext: SettingsContextData = {
spaciness: 'eco',
showOnlyUnreadPosts: false,
openNewTab: true,
toggleLightMode: jest.fn(),
lightMode: false,
setSpaciness: jest.fn(),
toggleOpenNewTab: jest.fn(),
toggleShowOnlyUnreadPosts: jest.fn(),
};
return render(
<QueryClientProvider client={client}>
<AuthContext.Provider
Expand All @@ -71,7 +85,9 @@ const renderComponent = (
tokenRefreshed: true,
}}
>
<BookmarksPage />
<SettingsContext.Provider value={settingsContext}>
<BookmarksPage />
</SettingsContext.Provider>
</AuthContext.Provider>
</QueryClientProvider>,
);
Expand Down
22 changes: 21 additions & 1 deletion __tests__/Feed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ import { getRankQueryKey } from '../hooks/useReadingRank';
import { OperationOptions } from 'subscriptions-transport-ws';
import { SubscriptionCallbacks } from '../hooks/useSubscription';
import { COMMENT_ON_POST_MUTATION } from '../graphql/comments';
import SettingsContext, {
SettingsContextData,
} from '../contexts/SettingsContext';

const showLogin = jest.fn();
let nextCallback: (value: PostsEngaged) => unknown = null;
Expand Down Expand Up @@ -59,6 +62,7 @@ const createFeedMock = (
variables: unknown = {
first: 7,
loggedIn: true,
unreadOnly: false,
},
): MockedGraphQLResponse<FeedData> => ({
request: {
Expand All @@ -82,6 +86,16 @@ const renderComponent = (

mocks.forEach(mockGraphQL);
nock('http://localhost:3000').get('/v1/a').reply(200, [ad]);
const settingsContext: SettingsContextData = {
spaciness: 'eco',
showOnlyUnreadPosts: false,
openNewTab: true,
toggleLightMode: jest.fn(),
lightMode: false,
setSpaciness: jest.fn(),
toggleOpenNewTab: jest.fn(),
toggleShowOnlyUnreadPosts: jest.fn(),
};
return render(
<QueryClientProvider client={queryClient}>
<AuthContext.Provider
Expand All @@ -94,7 +108,9 @@ const renderComponent = (
tokenRefreshed: true,
}}
>
<Feed query={ANONYMOUS_FEED_QUERY} />
<SettingsContext.Provider value={settingsContext}>
<Feed query={ANONYMOUS_FEED_QUERY} />
</SettingsContext.Provider>
</AuthContext.Provider>
</QueryClientProvider>,
);
Expand Down Expand Up @@ -168,6 +184,7 @@ it('should open login modal on anonymous upvote', async () => {
createFeedMock(defaultFeedPage, ANONYMOUS_FEED_QUERY, {
first: 7,
loggedIn: false,
unreadOnly: false,
}),
],
null,
Expand Down Expand Up @@ -223,6 +240,7 @@ it('should open login modal on anonymous bookmark', async () => {
createFeedMock(defaultFeedPage, ANONYMOUS_FEED_QUERY, {
first: 7,
loggedIn: false,
unreadOnly: false,
}),
],
null,
Expand Down Expand Up @@ -312,6 +330,7 @@ it('should increase reading rank progress for anonymous users', async () => {
createFeedMock(defaultFeedPage, ANONYMOUS_FEED_QUERY, {
first: 7,
loggedIn: false,
unreadOnly: false,
}),
],
null,
Expand Down Expand Up @@ -341,6 +360,7 @@ it('should not increase reading rank progress for anonymous users after the firs
createFeedMock(defaultFeedPage, ANONYMOUS_FEED_QUERY, {
first: 7,
loggedIn: false,
unreadOnly: false,
}),
],
null,
Expand Down
36 changes: 27 additions & 9 deletions __tests__/MostUpvotedPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import { QueryClient, QueryClientProvider } from 'react-query';
import { LoggedUser } from '../lib/user';
import Upvoted from '../pages/upvoted';
import OnboardingContext from '../contexts/OnboardingContext';
import SettingsContext, {
SettingsContextData,
} from '../contexts/SettingsContext';

const showLogin = jest.fn();

Expand All @@ -26,6 +29,7 @@ const createFeedMock = (
variables: unknown = {
first: 7,
loggedIn: true,
unreadOnly: false,
},
): MockedGraphQLResponse<FeedData> => ({
request: {
Expand All @@ -47,6 +51,16 @@ const renderComponent = (

mocks.forEach(mockGraphQL);
nock('http://localhost:3000').get('/v1/a').reply(200, [ad]);
const settingsContext: SettingsContextData = {
spaciness: 'eco',
showOnlyUnreadPosts: false,
openNewTab: true,
toggleLightMode: jest.fn(),
lightMode: false,
setSpaciness: jest.fn(),
toggleOpenNewTab: jest.fn(),
toggleShowOnlyUnreadPosts: jest.fn(),
};
return render(
<QueryClientProvider client={client}>
<AuthContext.Provider
Expand All @@ -59,15 +73,17 @@ const renderComponent = (
tokenRefreshed: true,
}}
>
<OnboardingContext.Provider
value={{
showWelcome: false,
onboardingReady: true,
setShowWelcome: jest.fn(),
}}
>
{Upvoted.getLayout(<Upvoted />, {}, Upvoted.layoutProps)}
</OnboardingContext.Provider>
<SettingsContext.Provider value={settingsContext}>
<OnboardingContext.Provider
value={{
showWelcome: false,
onboardingReady: true,
setShowWelcome: jest.fn(),
}}
>
{Upvoted.getLayout(<Upvoted />, {}, Upvoted.layoutProps)}
</OnboardingContext.Provider>
</SettingsContext.Provider>
</AuthContext.Provider>
</QueryClientProvider>,
);
Expand All @@ -78,6 +94,7 @@ it('should request most upvoted feed when logged-in', async () => {
createFeedMock(defaultFeedPage, MOST_UPVOTED_FEED_QUERY, {
first: 7,
loggedIn: true,
unreadOnly: false,
}),
]);
await waitFor(async () => {
Expand All @@ -92,6 +109,7 @@ it('should request most upvoted feed when not', async () => {
createFeedMock(defaultFeedPage, MOST_UPVOTED_FEED_QUERY, {
first: 7,
loggedIn: false,
unreadOnly: false,
}),
],
null,
Expand Down
38 changes: 29 additions & 9 deletions __tests__/PopularPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import { QueryClient, QueryClientProvider } from 'react-query';
import { LoggedUser } from '../lib/user';
import Popular from '../pages/popular';
import OnboardingContext from '../contexts/OnboardingContext';
import SettingsContext, {
SettingsContextData,
} from '../contexts/SettingsContext';

const showLogin = jest.fn();

Expand All @@ -26,6 +29,7 @@ const createFeedMock = (
variables: unknown = {
first: 7,
loggedIn: true,
unreadOnly: false,
},
): MockedGraphQLResponse<FeedData> => ({
request: {
Expand All @@ -48,6 +52,16 @@ const renderComponent = (

mocks.forEach(mockGraphQL);
nock('http://localhost:3000').get('/v1/a').reply(200, [ad]);
const settingsContext: SettingsContextData = {
spaciness: 'eco',
showOnlyUnreadPosts: false,
openNewTab: true,
toggleLightMode: jest.fn(),
lightMode: false,
setSpaciness: jest.fn(),
toggleOpenNewTab: jest.fn(),
toggleShowOnlyUnreadPosts: jest.fn(),
};
return render(
<QueryClientProvider client={client}>
<AuthContext.Provider
Expand All @@ -60,15 +74,17 @@ const renderComponent = (
tokenRefreshed: true,
}}
>
<OnboardingContext.Provider
value={{
showWelcome,
onboardingReady: true,
setShowWelcome: jest.fn(),
}}
>
{Popular.getLayout(<Popular />, {}, Popular.layoutProps)}
</OnboardingContext.Provider>
<SettingsContext.Provider value={settingsContext}>
<OnboardingContext.Provider
value={{
showWelcome,
onboardingReady: true,
setShowWelcome: jest.fn(),
}}
>
{Popular.getLayout(<Popular />, {}, Popular.layoutProps)}
</OnboardingContext.Provider>
</SettingsContext.Provider>
</AuthContext.Provider>
</QueryClientProvider>,
);
Expand All @@ -79,6 +95,7 @@ it('should request user feed', async () => {
createFeedMock(defaultFeedPage, FEED_QUERY, {
first: 7,
loggedIn: true,
unreadOnly: false,
}),
]);
await waitFor(async () => {
Expand All @@ -93,6 +110,7 @@ it('should request anonymous feed', async () => {
createFeedMock(defaultFeedPage, ANONYMOUS_FEED_QUERY, {
first: 7,
loggedIn: false,
unreadOnly: false,
}),
],
null,
Expand All @@ -109,6 +127,7 @@ it('should show welcome message during the onboarding', async () => {
createFeedMock(defaultFeedPage, ANONYMOUS_FEED_QUERY, {
first: 7,
loggedIn: false,
unreadOnly: false,
}),
],
null,
Expand All @@ -123,6 +142,7 @@ it('should not show welcome message after the onboarding', async () => {
createFeedMock(defaultFeedPage, ANONYMOUS_FEED_QUERY, {
first: 7,
loggedIn: false,
unreadOnly: false,
}),
],
null,
Expand Down
36 changes: 27 additions & 9 deletions __tests__/RecentPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import { QueryClient, QueryClientProvider } from 'react-query';
import { LoggedUser } from '../lib/user';
import Recent from '../pages/recent';
import OnboardingContext from '../contexts/OnboardingContext';
import SettingsContext, {
SettingsContextData,
} from '../contexts/SettingsContext';

const showLogin = jest.fn();

Expand All @@ -26,6 +29,7 @@ const createFeedMock = (
variables: unknown = {
first: 7,
loggedIn: true,
unreadOnly: false,
},
): MockedGraphQLResponse<FeedData> => ({
request: {
Expand All @@ -47,6 +51,16 @@ const renderComponent = (

mocks.forEach(mockGraphQL);
nock('http://localhost:3000').get('/v1/a').reply(200, [ad]);
const settingsContext: SettingsContextData = {
spaciness: 'eco',
showOnlyUnreadPosts: false,
openNewTab: true,
toggleLightMode: jest.fn(),
lightMode: false,
setSpaciness: jest.fn(),
toggleOpenNewTab: jest.fn(),
toggleShowOnlyUnreadPosts: jest.fn(),
};
return render(
<QueryClientProvider client={client}>
<AuthContext.Provider
Expand All @@ -59,15 +73,17 @@ const renderComponent = (
tokenRefreshed: true,
}}
>
<OnboardingContext.Provider
value={{
showWelcome: false,
onboardingReady: true,
setShowWelcome: jest.fn(),
}}
>
{Recent.getLayout(<Recent />, {}, Recent.layoutProps)}
</OnboardingContext.Provider>
<SettingsContext.Provider value={settingsContext}>
<OnboardingContext.Provider
value={{
showWelcome: false,
onboardingReady: true,
setShowWelcome: jest.fn(),
}}
>
{Recent.getLayout(<Recent />, {}, Recent.layoutProps)}
</OnboardingContext.Provider>
</SettingsContext.Provider>
</AuthContext.Provider>
</QueryClientProvider>,
);
Expand All @@ -79,6 +95,7 @@ it('should request user feed', async () => {
first: 7,
loggedIn: true,
ranking: 'TIME',
unreadOnly: false,
}),
]);
await waitFor(async () => {
Expand All @@ -94,6 +111,7 @@ it('should request anonymous feed', async () => {
first: 7,
loggedIn: false,
ranking: 'TIME',
unreadOnly: false,
}),
],
null,
Expand Down
Loading