Skip to content

Add Settings page with options #41

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

Merged
merged 17 commits into from
May 23, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
stories: add stories for the Settings page
  • Loading branch information
jamaljsr committed May 20, 2020
commit 6fbdf72050fbc72b6252de0931e90d9a7fd0871f
21 changes: 21 additions & 0 deletions app/src/__stories__/SettingsPage.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';
import { Layout } from 'components/layout';
import SettingsPage from 'components/settings/SettingsPage';

export default {
title: 'Pages/Settings',
component: SettingsPage,
parameters: { contained: true },
};

export const Default = () => {
return <SettingsPage />;
};

export const InsideLayout = () => {
return (
<Layout>
<SettingsPage />
</Layout>
);
};
15 changes: 13 additions & 2 deletions app/src/__stories__/StoryWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { CSSProperties, useMemo } from 'react';
import { observer } from 'mobx-react-lite';
import MockAppStorage from 'util/tests/mockAppStorage';
import { BalanceMode, Unit } from 'util/constants';
import { sampleApiResponses } from 'util/tests/sampleData';
import { createStore, StoreProvider } from 'store';
import { PersistentSettings } from 'store/stores/settingsStore';
import { Background } from 'components/common/base';
import { ThemeProvider } from 'components/theme';

Expand All @@ -17,9 +18,19 @@ const grpc = {
},
};

// fake the AppStorage dependency so that settings aren't shared across stories
class StoryAppStorage {
set = () => undefined;
get = (): PersistentSettings => ({
sidebarVisible: true,
unit: Unit.sats,
balanceMode: BalanceMode.receive,
});
}

// Create a store that pulls data from the mock GRPC and doesn't use
// the real localStorage to save settings
const createStoryStore = () => createStore(grpc, new MockAppStorage());
const createStoryStore = () => createStore(grpc, new StoryAppStorage());

/**
* This component is used to wrap every story. It provides the app theme
Expand Down
11 changes: 8 additions & 3 deletions app/src/__tests__/store/settingsStore.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import AppStorage from 'util/appStorage';
import { BalanceMode, Unit } from 'util/constants';
import { mockStorageGet } from 'util/tests/mockAppStorage';
import { createStore, SettingsStore } from 'store';
import { PersistentSettings } from 'store/stores/settingsStore';

const appStorageMock = AppStorage as jest.Mock<AppStorage<PersistentSettings>>;

describe('SettingsStore', () => {
let store: SettingsStore;
Expand All @@ -10,7 +13,8 @@ describe('SettingsStore', () => {
});

it('should load settings', async () => {
mockStorageGet.mockImplementation(() => ({
const getMock = appStorageMock.mock.instances[0].get as jest.Mock;
getMock.mockImplementation(() => ({
sidebarVisible: false,
unit: Unit.bits,
balanceMode: BalanceMode.routing,
Expand All @@ -24,7 +28,8 @@ describe('SettingsStore', () => {
});

it('should do nothing if nothing is saved in storage', () => {
mockStorageGet.mockReturnValue(undefined as any);
const getMock = appStorageMock.mock.instances[0].get as jest.Mock;
getMock.mockReturnValue(undefined as any);

store.load();

Expand Down
5 changes: 2 additions & 3 deletions app/src/setupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ import '@testing-library/jest-dom/extend-expect';
import './i18n';
// adds support for lottie-web animations in unit test env
import 'jest-canvas-mock';
// don't use the real localStorage in unit tests
import MockAppStorage from 'util/tests/mockAppStorage';

jest.mock('util/appStorage', () => MockAppStorage);
// don't use the real localStorage in unit tests
jest.mock('util/appStorage');

beforeEach(() => {
jest.clearAllMocks();
Expand Down
18 changes: 0 additions & 18 deletions app/src/util/tests/mockAppStorage.ts

This file was deleted.