Refactor tests with mock stores
This commit is contained in:
parent
0a90c3c377
commit
300d3a0200
|
@ -1,46 +1,33 @@
|
||||||
import { fromJS } from 'immutable';
|
|
||||||
import React from 'react';
|
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 { render, screen } from '../../../../jest/test-helpers';
|
||||||
import CtaBanner from '../cta-banner';
|
import CtaBanner from '../cta-banner';
|
||||||
|
|
||||||
describe('<CtaBanner />', () => {
|
describe('<CtaBanner />', () => {
|
||||||
it('renders the banner', () => {
|
it('renders the banner', () => {
|
||||||
const store = { instance: normalizeInstance({ registrations: true }) };
|
render(<CtaBanner />, undefined, storeOpen);
|
||||||
|
|
||||||
render(<CtaBanner />, undefined, store);
|
|
||||||
expect(screen.getByTestId('cta-banner')).toHaveTextContent(/sign up/i);
|
expect(screen.getByTestId('cta-banner')).toHaveTextContent(/sign up/i);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('with a logged in user', () => {
|
describe('with a logged in user', () => {
|
||||||
it('renders empty', () => {
|
it('renders empty', () => {
|
||||||
const store = { me: true };
|
render(<CtaBanner />, undefined, storeLoggedIn);
|
||||||
|
|
||||||
render(<CtaBanner />, undefined, store);
|
|
||||||
expect(screen.queryAllByTestId('cta-banner')).toHaveLength(0);
|
expect(screen.queryAllByTestId('cta-banner')).toHaveLength(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('with registrations closed', () => {
|
describe('with registrations closed', () => {
|
||||||
it('renders empty', () => {
|
it('renders empty', () => {
|
||||||
const store = { instance: normalizeInstance({ registrations: false }) };
|
render(<CtaBanner />, undefined, storeClosed);
|
||||||
|
|
||||||
render(<CtaBanner />, undefined, store);
|
|
||||||
expect(screen.queryAllByTestId('cta-banner')).toHaveLength(0);
|
expect(screen.queryAllByTestId('cta-banner')).toHaveLength(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('with Pepe enabled', () => {
|
describe('with Pepe enabled', () => {
|
||||||
it('renders the banner', () => {
|
it('renders the banner', () => {
|
||||||
const store = {
|
render(<CtaBanner />, undefined, storePepeOpen);
|
||||||
instance: normalizeInstance({ registrations: false }),
|
|
||||||
soapbox: fromJS({ extensions: { pepe: { enabled: true } } }),
|
|
||||||
verification: { instance: fromJS({ registrations: true }) },
|
|
||||||
};
|
|
||||||
|
|
||||||
render(<CtaBanner />, undefined, store);
|
|
||||||
expect(screen.getByTestId('cta-banner')).toHaveTextContent(/sign up/i);
|
expect(screen.getByTestId('cta-banner')).toHaveTextContent(/sign up/i);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import { fromJS } from 'immutable';
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
|
import { storeOpen, storePepeOpen } from 'soapbox/jest/mock-stores';
|
||||||
import { render, screen } from 'soapbox/jest/test-helpers';
|
import { render, screen } from 'soapbox/jest/test-helpers';
|
||||||
import { normalizeInstance } from 'soapbox/normalizers';
|
|
||||||
|
|
||||||
import Navbar from '../navbar';
|
import Navbar from '../navbar';
|
||||||
|
|
||||||
|
@ -19,21 +18,14 @@ describe('<Navbar />', () => {
|
||||||
|
|
||||||
describe('with registrations enabled', () => {
|
describe('with registrations enabled', () => {
|
||||||
it('displays the signup button', () => {
|
it('displays the signup button', () => {
|
||||||
const store = { instance: normalizeInstance({ registrations: true }) };
|
render(<Navbar />, undefined, storeOpen);
|
||||||
render(<Navbar />, undefined, store);
|
|
||||||
expect(screen.getByText('Sign up')).toBeInTheDocument();
|
expect(screen.getByText('Sign up')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('with registrations closed, Pepe enabled', () => {
|
describe('with registrations closed, Pepe enabled', () => {
|
||||||
it('displays the signup button', () => {
|
it('displays the signup button', () => {
|
||||||
const store = {
|
render(<Navbar />, undefined, storePepeOpen);
|
||||||
instance: normalizeInstance({ registrations: false }),
|
|
||||||
soapbox: fromJS({ extensions: { pepe: { enabled: true } } }),
|
|
||||||
verification: { instance: fromJS({ registrations: true }) },
|
|
||||||
};
|
|
||||||
|
|
||||||
render(<Navbar />, undefined, store);
|
|
||||||
expect(screen.getByText('Sign up')).toBeInTheDocument();
|
expect(screen.getByText('Sign up')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import { fromJS } from 'immutable';
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
|
import { storeOpen, storePepeOpen } from 'soapbox/jest/mock-stores';
|
||||||
import { render, screen } from 'soapbox/jest/test-helpers';
|
import { render, screen } from 'soapbox/jest/test-helpers';
|
||||||
import { normalizeInstance } from 'soapbox/normalizers';
|
|
||||||
|
|
||||||
import LandingPageModal from '../landing-page-modal';
|
import LandingPageModal from '../landing-page-modal';
|
||||||
|
|
||||||
|
@ -19,21 +18,14 @@ describe('<LandingPageModal />', () => {
|
||||||
|
|
||||||
describe('with registrations enabled', () => {
|
describe('with registrations enabled', () => {
|
||||||
it('displays the signup button', () => {
|
it('displays the signup button', () => {
|
||||||
const store = { instance: normalizeInstance({ registrations: true }) };
|
render(<LandingPageModal onClose={jest.fn} />, undefined, storeOpen);
|
||||||
render(<LandingPageModal onClose={jest.fn} />, undefined, store);
|
|
||||||
expect(screen.getByText('Register')).toBeInTheDocument();
|
expect(screen.getByText('Register')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('with registrations closed, Pepe enabled', () => {
|
describe('with registrations closed, Pepe enabled', () => {
|
||||||
it('displays the signup button', () => {
|
it('displays the signup button', () => {
|
||||||
const store = {
|
render(<LandingPageModal onClose={jest.fn} />, undefined, storePepeOpen);
|
||||||
instance: normalizeInstance({ registrations: false }),
|
|
||||||
soapbox: fromJS({ extensions: { pepe: { enabled: true } } }),
|
|
||||||
verification: { instance: fromJS({ registrations: true }) },
|
|
||||||
};
|
|
||||||
|
|
||||||
render(<LandingPageModal onClose={jest.fn} />, undefined, store);
|
|
||||||
expect(screen.getByText('Register')).toBeInTheDocument();
|
expect(screen.getByText('Register')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import { fromJS } from 'immutable';
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
|
import { storeOpen, storePepeOpen } from 'soapbox/jest/mock-stores';
|
||||||
import { render, screen } from 'soapbox/jest/test-helpers';
|
import { render, screen } from 'soapbox/jest/test-helpers';
|
||||||
import { normalizeInstance } from 'soapbox/normalizers';
|
|
||||||
|
|
||||||
import UnauthorizedModal from '../unauthorized-modal';
|
import UnauthorizedModal from '../unauthorized-modal';
|
||||||
|
|
||||||
|
@ -19,21 +18,14 @@ describe('<UnauthorizedModal />', () => {
|
||||||
|
|
||||||
describe('with registrations enabled', () => {
|
describe('with registrations enabled', () => {
|
||||||
it('displays the signup button', () => {
|
it('displays the signup button', () => {
|
||||||
const store = { instance: normalizeInstance({ registrations: true }) };
|
render(<UnauthorizedModal onClose={jest.fn} action='FOLLOW' />, undefined, storeOpen);
|
||||||
render(<UnauthorizedModal onClose={jest.fn} action='FOLLOW' />, undefined, store);
|
|
||||||
expect(screen.getByText('Sign up')).toBeInTheDocument();
|
expect(screen.getByText('Sign up')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('with registrations closed, Pepe enabled', () => {
|
describe('with registrations closed, Pepe enabled', () => {
|
||||||
it('displays the signup button', () => {
|
it('displays the signup button', () => {
|
||||||
const store = {
|
render(<UnauthorizedModal onClose={jest.fn} action='FOLLOW' />, undefined, storePepeOpen);
|
||||||
instance: normalizeInstance({ registrations: false }),
|
|
||||||
soapbox: fromJS({ extensions: { pepe: { enabled: true } } }),
|
|
||||||
verification: { instance: fromJS({ registrations: true }) },
|
|
||||||
};
|
|
||||||
|
|
||||||
render(<UnauthorizedModal onClose={jest.fn} action='FOLLOW' />, undefined, store);
|
|
||||||
expect(screen.getByText('Sign up')).toBeInTheDocument();
|
expect(screen.getByText('Sign up')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import { fromJS } from 'immutable';
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
|
import { storeOpen, storePepeOpen } from 'soapbox/jest/mock-stores';
|
||||||
import { render, screen } from 'soapbox/jest/test-helpers';
|
import { render, screen } from 'soapbox/jest/test-helpers';
|
||||||
import { normalizeInstance } from 'soapbox/normalizers';
|
|
||||||
|
|
||||||
import SignUpPanel from '../sign-up-panel';
|
import SignUpPanel from '../sign-up-panel';
|
||||||
|
|
||||||
|
@ -14,21 +13,14 @@ describe('<SignUpPanel />', () => {
|
||||||
|
|
||||||
describe('with registrations enabled', () => {
|
describe('with registrations enabled', () => {
|
||||||
it('successfully renders', () => {
|
it('successfully renders', () => {
|
||||||
const store = { instance: normalizeInstance({ registrations: true }) };
|
render(<SignUpPanel />, undefined, storeOpen);
|
||||||
render(<SignUpPanel />, undefined, store);
|
|
||||||
expect(screen.getByTestId('sign-up-panel')).toBeInTheDocument();
|
expect(screen.getByTestId('sign-up-panel')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('with registrations closed, Pepe enabled', () => {
|
describe('with registrations closed, Pepe enabled', () => {
|
||||||
it('successfully renders', () => {
|
it('successfully renders', () => {
|
||||||
const store = {
|
render(<SignUpPanel />, undefined, storePepeOpen);
|
||||||
instance: normalizeInstance({ registrations: false }),
|
|
||||||
soapbox: fromJS({ extensions: { pepe: { enabled: true } } }),
|
|
||||||
verification: { instance: fromJS({ registrations: true }) },
|
|
||||||
};
|
|
||||||
|
|
||||||
render(<SignUpPanel />, undefined, store);
|
|
||||||
expect(screen.getByTestId('sign-up-panel')).toBeInTheDocument();
|
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 { renderHook } from 'soapbox/jest/test-helpers';
|
||||||
import { normalizeInstance } from 'soapbox/normalizers';
|
|
||||||
|
|
||||||
import { useRegistrationStatus } from '../useRegistrationStatus';
|
import { useRegistrationStatus } from '../useRegistrationStatus';
|
||||||
|
|
||||||
describe('useRegistrationStatus()', () => {
|
describe('useRegistrationStatus()', () => {
|
||||||
test('Registrations open', () => {
|
test('Registrations open', () => {
|
||||||
const store = { instance: normalizeInstance({ registrations: true }) };
|
const { result } = renderHook(useRegistrationStatus, undefined, storeOpen);
|
||||||
const { result } = renderHook(useRegistrationStatus, undefined, store);
|
|
||||||
|
|
||||||
expect(result.current).toMatchObject({
|
expect(result.current).toMatchObject({
|
||||||
isOpen: true,
|
isOpen: true,
|
||||||
|
@ -18,8 +15,7 @@ describe('useRegistrationStatus()', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Registrations closed', () => {
|
test('Registrations closed', () => {
|
||||||
const store = { instance: normalizeInstance({ registrations: false }) };
|
const { result } = renderHook(useRegistrationStatus, undefined, storeClosed);
|
||||||
const { result } = renderHook(useRegistrationStatus, undefined, store);
|
|
||||||
|
|
||||||
expect(result.current).toMatchObject({
|
expect(result.current).toMatchObject({
|
||||||
isOpen: false,
|
isOpen: false,
|
||||||
|
@ -29,13 +25,7 @@ describe('useRegistrationStatus()', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Registrations closed, Pepe enabled & open', () => {
|
test('Registrations closed, Pepe enabled & open', () => {
|
||||||
const store = {
|
const { result } = renderHook(useRegistrationStatus, undefined, storePepeOpen);
|
||||||
instance: normalizeInstance({ registrations: false }),
|
|
||||||
soapbox: fromJS({ extensions: { pepe: { enabled: true } } }),
|
|
||||||
verification: { instance: fromJS({ registrations: true }) },
|
|
||||||
};
|
|
||||||
|
|
||||||
const { result } = renderHook(useRegistrationStatus, undefined, store);
|
|
||||||
|
|
||||||
expect(result.current).toMatchObject({
|
expect(result.current).toMatchObject({
|
||||||
isOpen: true,
|
isOpen: true,
|
||||||
|
@ -45,13 +35,7 @@ describe('useRegistrationStatus()', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Registrations closed, Pepe enabled & closed', () => {
|
test('Registrations closed, Pepe enabled & closed', () => {
|
||||||
const store = {
|
const { result } = renderHook(useRegistrationStatus, undefined, storePepeClosed);
|
||||||
instance: normalizeInstance({ registrations: false }),
|
|
||||||
soapbox: fromJS({ extensions: { pepe: { enabled: true } } }),
|
|
||||||
verification: { instance: fromJS({ registrations: false }) },
|
|
||||||
};
|
|
||||||
|
|
||||||
const { result } = renderHook(useRegistrationStatus, undefined, store);
|
|
||||||
|
|
||||||
expect(result.current).toMatchObject({
|
expect(result.current).toMatchObject({
|
||||||
isOpen: false,
|
isOpen: false,
|
||||||
|
|
|
@ -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 New Issue