Refactor tests with mock stores
This commit is contained in:
parent
0a90c3c377
commit
300d3a0200
7 changed files with 62 additions and 83 deletions
|
@ -1,46 +1,33 @@
|
|||
import { fromJS } from 'immutable';
|
||||
import React from 'react';
|
||||
|
||||
import { normalizeInstance } from 'soapbox/normalizers';
|
||||
import { storeClosed, storeLoggedIn, storeOpen, storePepeOpen } from 'soapbox/jest/mock-stores';
|
||||
|
||||
import { render, screen } from '../../../../jest/test-helpers';
|
||||
import CtaBanner from '../cta-banner';
|
||||
|
||||
describe('<CtaBanner />', () => {
|
||||
it('renders the banner', () => {
|
||||
const store = { instance: normalizeInstance({ registrations: true }) };
|
||||
|
||||
render(<CtaBanner />, undefined, store);
|
||||
render(<CtaBanner />, undefined, storeOpen);
|
||||
expect(screen.getByTestId('cta-banner')).toHaveTextContent(/sign up/i);
|
||||
});
|
||||
|
||||
describe('with a logged in user', () => {
|
||||
it('renders empty', () => {
|
||||
const store = { me: true };
|
||||
|
||||
render(<CtaBanner />, undefined, store);
|
||||
render(<CtaBanner />, undefined, storeLoggedIn);
|
||||
expect(screen.queryAllByTestId('cta-banner')).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with registrations closed', () => {
|
||||
it('renders empty', () => {
|
||||
const store = { instance: normalizeInstance({ registrations: false }) };
|
||||
|
||||
render(<CtaBanner />, undefined, store);
|
||||
render(<CtaBanner />, undefined, storeClosed);
|
||||
expect(screen.queryAllByTestId('cta-banner')).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with Pepe enabled', () => {
|
||||
it('renders the banner', () => {
|
||||
const store = {
|
||||
instance: normalizeInstance({ registrations: false }),
|
||||
soapbox: fromJS({ extensions: { pepe: { enabled: true } } }),
|
||||
verification: { instance: fromJS({ registrations: true }) },
|
||||
};
|
||||
|
||||
render(<CtaBanner />, undefined, store);
|
||||
render(<CtaBanner />, undefined, storePepeOpen);
|
||||
expect(screen.getByTestId('cta-banner')).toHaveTextContent(/sign up/i);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import { fromJS } from 'immutable';
|
||||
import React from 'react';
|
||||
|
||||
import { storeOpen, storePepeOpen } from 'soapbox/jest/mock-stores';
|
||||
import { render, screen } from 'soapbox/jest/test-helpers';
|
||||
import { normalizeInstance } from 'soapbox/normalizers';
|
||||
|
||||
import Navbar from '../navbar';
|
||||
|
||||
|
@ -19,21 +18,14 @@ describe('<Navbar />', () => {
|
|||
|
||||
describe('with registrations enabled', () => {
|
||||
it('displays the signup button', () => {
|
||||
const store = { instance: normalizeInstance({ registrations: true }) };
|
||||
render(<Navbar />, undefined, store);
|
||||
render(<Navbar />, undefined, storeOpen);
|
||||
expect(screen.getByText('Sign up')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('with registrations closed, Pepe enabled', () => {
|
||||
it('displays the signup button', () => {
|
||||
const store = {
|
||||
instance: normalizeInstance({ registrations: false }),
|
||||
soapbox: fromJS({ extensions: { pepe: { enabled: true } } }),
|
||||
verification: { instance: fromJS({ registrations: true }) },
|
||||
};
|
||||
|
||||
render(<Navbar />, undefined, store);
|
||||
render(<Navbar />, undefined, storePepeOpen);
|
||||
expect(screen.getByText('Sign up')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import { fromJS } from 'immutable';
|
||||
import React from 'react';
|
||||
|
||||
import { storeOpen, storePepeOpen } from 'soapbox/jest/mock-stores';
|
||||
import { render, screen } from 'soapbox/jest/test-helpers';
|
||||
import { normalizeInstance } from 'soapbox/normalizers';
|
||||
|
||||
import LandingPageModal from '../landing-page-modal';
|
||||
|
||||
|
@ -19,21 +18,14 @@ describe('<LandingPageModal />', () => {
|
|||
|
||||
describe('with registrations enabled', () => {
|
||||
it('displays the signup button', () => {
|
||||
const store = { instance: normalizeInstance({ registrations: true }) };
|
||||
render(<LandingPageModal onClose={jest.fn} />, undefined, store);
|
||||
render(<LandingPageModal onClose={jest.fn} />, undefined, storeOpen);
|
||||
expect(screen.getByText('Register')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('with registrations closed, Pepe enabled', () => {
|
||||
it('displays the signup button', () => {
|
||||
const store = {
|
||||
instance: normalizeInstance({ registrations: false }),
|
||||
soapbox: fromJS({ extensions: { pepe: { enabled: true } } }),
|
||||
verification: { instance: fromJS({ registrations: true }) },
|
||||
};
|
||||
|
||||
render(<LandingPageModal onClose={jest.fn} />, undefined, store);
|
||||
render(<LandingPageModal onClose={jest.fn} />, undefined, storePepeOpen);
|
||||
expect(screen.getByText('Register')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import { fromJS } from 'immutable';
|
||||
import React from 'react';
|
||||
|
||||
import { storeOpen, storePepeOpen } from 'soapbox/jest/mock-stores';
|
||||
import { render, screen } from 'soapbox/jest/test-helpers';
|
||||
import { normalizeInstance } from 'soapbox/normalizers';
|
||||
|
||||
import UnauthorizedModal from '../unauthorized-modal';
|
||||
|
||||
|
@ -19,21 +18,14 @@ describe('<UnauthorizedModal />', () => {
|
|||
|
||||
describe('with registrations enabled', () => {
|
||||
it('displays the signup button', () => {
|
||||
const store = { instance: normalizeInstance({ registrations: true }) };
|
||||
render(<UnauthorizedModal onClose={jest.fn} action='FOLLOW' />, undefined, store);
|
||||
render(<UnauthorizedModal onClose={jest.fn} action='FOLLOW' />, undefined, storeOpen);
|
||||
expect(screen.getByText('Sign up')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('with registrations closed, Pepe enabled', () => {
|
||||
it('displays the signup button', () => {
|
||||
const store = {
|
||||
instance: normalizeInstance({ registrations: false }),
|
||||
soapbox: fromJS({ extensions: { pepe: { enabled: true } } }),
|
||||
verification: { instance: fromJS({ registrations: true }) },
|
||||
};
|
||||
|
||||
render(<UnauthorizedModal onClose={jest.fn} action='FOLLOW' />, undefined, store);
|
||||
render(<UnauthorizedModal onClose={jest.fn} action='FOLLOW' />, undefined, storePepeOpen);
|
||||
expect(screen.getByText('Sign up')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import { fromJS } from 'immutable';
|
||||
import React from 'react';
|
||||
|
||||
import { storeOpen, storePepeOpen } from 'soapbox/jest/mock-stores';
|
||||
import { render, screen } from 'soapbox/jest/test-helpers';
|
||||
import { normalizeInstance } from 'soapbox/normalizers';
|
||||
|
||||
import SignUpPanel from '../sign-up-panel';
|
||||
|
||||
|
@ -14,21 +13,14 @@ describe('<SignUpPanel />', () => {
|
|||
|
||||
describe('with registrations enabled', () => {
|
||||
it('successfully renders', () => {
|
||||
const store = { instance: normalizeInstance({ registrations: true }) };
|
||||
render(<SignUpPanel />, undefined, store);
|
||||
render(<SignUpPanel />, undefined, storeOpen);
|
||||
expect(screen.getByTestId('sign-up-panel')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('with registrations closed, Pepe enabled', () => {
|
||||
it('successfully renders', () => {
|
||||
const store = {
|
||||
instance: normalizeInstance({ registrations: false }),
|
||||
soapbox: fromJS({ extensions: { pepe: { enabled: true } } }),
|
||||
verification: { instance: fromJS({ registrations: true }) },
|
||||
};
|
||||
|
||||
render(<SignUpPanel />, undefined, store);
|
||||
render(<SignUpPanel />, undefined, storePepeOpen);
|
||||
expect(screen.getByTestId('sign-up-panel')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
import { fromJS } from 'immutable';
|
||||
|
||||
import { storeClosed, storeOpen, storePepeClosed, storePepeOpen } from 'soapbox/jest/mock-stores';
|
||||
import { renderHook } from 'soapbox/jest/test-helpers';
|
||||
import { normalizeInstance } from 'soapbox/normalizers';
|
||||
|
||||
import { useRegistrationStatus } from '../useRegistrationStatus';
|
||||
|
||||
describe('useRegistrationStatus()', () => {
|
||||
test('Registrations open', () => {
|
||||
const store = { instance: normalizeInstance({ registrations: true }) };
|
||||
const { result } = renderHook(useRegistrationStatus, undefined, store);
|
||||
const { result } = renderHook(useRegistrationStatus, undefined, storeOpen);
|
||||
|
||||
expect(result.current).toMatchObject({
|
||||
isOpen: true,
|
||||
|
@ -18,8 +15,7 @@ describe('useRegistrationStatus()', () => {
|
|||
});
|
||||
|
||||
test('Registrations closed', () => {
|
||||
const store = { instance: normalizeInstance({ registrations: false }) };
|
||||
const { result } = renderHook(useRegistrationStatus, undefined, store);
|
||||
const { result } = renderHook(useRegistrationStatus, undefined, storeClosed);
|
||||
|
||||
expect(result.current).toMatchObject({
|
||||
isOpen: false,
|
||||
|
@ -29,13 +25,7 @@ describe('useRegistrationStatus()', () => {
|
|||
});
|
||||
|
||||
test('Registrations closed, Pepe enabled & open', () => {
|
||||
const store = {
|
||||
instance: normalizeInstance({ registrations: false }),
|
||||
soapbox: fromJS({ extensions: { pepe: { enabled: true } } }),
|
||||
verification: { instance: fromJS({ registrations: true }) },
|
||||
};
|
||||
|
||||
const { result } = renderHook(useRegistrationStatus, undefined, store);
|
||||
const { result } = renderHook(useRegistrationStatus, undefined, storePepeOpen);
|
||||
|
||||
expect(result.current).toMatchObject({
|
||||
isOpen: true,
|
||||
|
@ -45,13 +35,7 @@ describe('useRegistrationStatus()', () => {
|
|||
});
|
||||
|
||||
test('Registrations closed, Pepe enabled & closed', () => {
|
||||
const store = {
|
||||
instance: normalizeInstance({ registrations: false }),
|
||||
soapbox: fromJS({ extensions: { pepe: { enabled: true } } }),
|
||||
verification: { instance: fromJS({ registrations: false }) },
|
||||
};
|
||||
|
||||
const { result } = renderHook(useRegistrationStatus, undefined, store);
|
||||
const { result } = renderHook(useRegistrationStatus, undefined, storePepeClosed);
|
||||
|
||||
expect(result.current).toMatchObject({
|
||||
isOpen: false,
|
||||
|
|
40
app/soapbox/jest/mock-stores.tsx
Normal file
40
app/soapbox/jest/mock-stores.tsx
Normal file
|
@ -0,0 +1,40 @@
|
|||
import { Map as ImmutableMap, fromJS } from 'immutable';
|
||||
|
||||
import alexJson from 'soapbox/__fixtures__/pleroma-account.json';
|
||||
import { normalizeAccount, normalizeInstance } from 'soapbox/normalizers';
|
||||
|
||||
/** Store with registrations open. */
|
||||
const storeOpen = { instance: normalizeInstance({ registrations: true }) };
|
||||
|
||||
/** Store with registrations closed. */
|
||||
const storeClosed = { instance: normalizeInstance({ registrations: false }) };
|
||||
|
||||
/** Store with registrations closed, and Pepe enabled & open. */
|
||||
const storePepeOpen = {
|
||||
instance: normalizeInstance({ registrations: false }),
|
||||
soapbox: fromJS({ extensions: { pepe: { enabled: true } } }),
|
||||
verification: { instance: fromJS({ registrations: true }) },
|
||||
};
|
||||
|
||||
/** Store with registrations closed, and Pepe enabled & closed. */
|
||||
const storePepeClosed = {
|
||||
instance: normalizeInstance({ registrations: false }),
|
||||
soapbox: fromJS({ extensions: { pepe: { enabled: true } } }),
|
||||
verification: { instance: fromJS({ registrations: false }) },
|
||||
};
|
||||
|
||||
/** Store with a logged-in user. */
|
||||
const storeLoggedIn = {
|
||||
me: alexJson.id,
|
||||
accounts: ImmutableMap({
|
||||
[alexJson.id]: normalizeAccount(alexJson),
|
||||
}),
|
||||
};
|
||||
|
||||
export {
|
||||
storeOpen,
|
||||
storeClosed,
|
||||
storePepeOpen,
|
||||
storePepeClosed,
|
||||
storeLoggedIn,
|
||||
};
|
Loading…
Reference in a new issue