Add tests
This commit is contained in:
parent
0e1302587a
commit
5fa875ef64
2 changed files with 182 additions and 4 deletions
|
@ -0,0 +1,178 @@
|
|||
import { Map as ImmutableMap } from 'immutable';
|
||||
import React from 'react';
|
||||
|
||||
import { render, screen } from '../../../../jest/test-helpers';
|
||||
import { normalizeAccount, normalizeInstance, normalizeRelationship } from '../../../../normalizers';
|
||||
import SubscribeButton from '../subscription-button';
|
||||
|
||||
let account = {
|
||||
id: '1',
|
||||
acct: 'justin-username',
|
||||
display_name: 'Justin L',
|
||||
avatar: 'test.jpg',
|
||||
};
|
||||
|
||||
describe('<SubscribeButton />', () => {
|
||||
let store;
|
||||
|
||||
describe('with "accountNotifies" disabled', () => {
|
||||
it('renders nothing', () => {
|
||||
account = normalizeAccount({ ...account, relationship: normalizeRelationship({ following: true }) });
|
||||
|
||||
render(<SubscribeButton account={account} />, null, store);
|
||||
expect(screen.queryAllByTestId('icon-button')).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with "accountNotifies" enabled', () => {
|
||||
beforeEach(() => {
|
||||
store = {
|
||||
...store,
|
||||
instance: normalizeInstance({
|
||||
version: '3.4.1 (compatible; TruthSocial 1.0.0)',
|
||||
software: 'TRUTHSOCIAL',
|
||||
pleroma: ImmutableMap({}),
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
describe('when the relationship is requested', () => {
|
||||
beforeEach(() => {
|
||||
account = normalizeAccount({ ...account, relationship: normalizeRelationship({ requested: true }) });
|
||||
|
||||
store = {
|
||||
...store,
|
||||
accounts: ImmutableMap({
|
||||
'1': account,
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
it('renders the button', () => {
|
||||
render(<SubscribeButton account={account} />, null, store);
|
||||
expect(screen.getByTestId('icon-button')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
describe('when the user "isSubscribed"', () => {
|
||||
beforeEach(() => {
|
||||
account = normalizeAccount({
|
||||
...account,
|
||||
relationship: normalizeRelationship({ requested: true, notifying: true }),
|
||||
});
|
||||
|
||||
store = {
|
||||
...store,
|
||||
accounts: ImmutableMap({
|
||||
'1': account,
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
it('renders the unsubscribe button', () => {
|
||||
render(<SubscribeButton account={account} />, null, store);
|
||||
expect(screen.getByTestId('icon-button').title).toEqual(`Unsubscribe to notifications from @${account.acct}`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the user is not "isSubscribed"', () => {
|
||||
beforeEach(() => {
|
||||
account = normalizeAccount({
|
||||
...account,
|
||||
relationship: normalizeRelationship({ requested: true, notifying: false }),
|
||||
});
|
||||
|
||||
store = {
|
||||
...store,
|
||||
accounts: ImmutableMap({
|
||||
'1': account,
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
it('renders the unsubscribe button', () => {
|
||||
render(<SubscribeButton account={account} />, null, store);
|
||||
expect(screen.getByTestId('icon-button').title).toEqual(`Subscribe to notifications from @${account.acct}`);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the user is not following the account', () => {
|
||||
beforeEach(() => {
|
||||
account = normalizeAccount({ ...account, relationship: normalizeRelationship({ following: false }) });
|
||||
|
||||
store = {
|
||||
...store,
|
||||
accounts: ImmutableMap({
|
||||
'1': account,
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
it('renders nothing', () => {
|
||||
render(<SubscribeButton account={account} />, null, store);
|
||||
expect(screen.queryAllByTestId('icon-button')).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the user is following the account', () => {
|
||||
beforeEach(() => {
|
||||
account = normalizeAccount({ ...account, relationship: normalizeRelationship({ following: true }) });
|
||||
|
||||
store = {
|
||||
...store,
|
||||
accounts: ImmutableMap({
|
||||
'1': account,
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
it('renders the button', () => {
|
||||
render(<SubscribeButton account={account} />, null, store);
|
||||
expect(screen.getByTestId('icon-button')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
describe('when the user "isSubscribed"', () => {
|
||||
beforeEach(() => {
|
||||
account = normalizeAccount({
|
||||
...account,
|
||||
relationship: normalizeRelationship({ requested: true, notifying: true }),
|
||||
});
|
||||
|
||||
store = {
|
||||
...store,
|
||||
accounts: ImmutableMap({
|
||||
'1': account,
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
it('renders the unsubscribe button', () => {
|
||||
render(<SubscribeButton account={account} />, null, store);
|
||||
expect(screen.getByTestId('icon-button').title).toEqual(`Unsubscribe to notifications from @${account.acct}`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the user is not "isSubscribed"', () => {
|
||||
beforeEach(() => {
|
||||
account = normalizeAccount({
|
||||
...account,
|
||||
relationship: normalizeRelationship({ requested: true, notifying: false }),
|
||||
});
|
||||
|
||||
store = {
|
||||
...store,
|
||||
accounts: ImmutableMap({
|
||||
'1': account,
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
it('renders the unsubscribe button', () => {
|
||||
render(<SubscribeButton account={account} />, null, store);
|
||||
expect(screen.getByTestId('icon-button').title).toEqual(`Subscribe to notifications from @${account.acct}`);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
|
@ -30,8 +30,8 @@ const SubscriptionButton = ({ account }: ISubscriptionButton) => {
|
|||
const features = useFeatures();
|
||||
const intl = useIntl();
|
||||
|
||||
const following = account.relationship?.following;
|
||||
const requested = account.relationship?.requested;
|
||||
const isFollowing = account.relationship?.following;
|
||||
const isRequested = account.relationship?.requested;
|
||||
const isSubscribed = features.accountNotifies ?
|
||||
account.relationship?.notifying :
|
||||
account.relationship?.subscribing;
|
||||
|
@ -83,11 +83,11 @@ const SubscriptionButton = ({ account }: ISubscriptionButton) => {
|
|||
}
|
||||
};
|
||||
|
||||
if (!features.accountSubscriptions) {
|
||||
if (!features.accountSubscriptions && !features.accountNotifies) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (requested || following) {
|
||||
if (isRequested || isFollowing) {
|
||||
return (
|
||||
<IconButton
|
||||
src={isSubscribed ? require('@tabler/icons/icons/bell-ringing.svg') : require('@tabler/icons/icons/bell.svg')}
|
||||
|
|
Loading…
Reference in a new issue