diff --git a/app/soapbox/features/ui/components/__tests__/subscribe-button.test.tsx b/app/soapbox/features/ui/components/__tests__/subscribe-button.test.tsx
new file mode 100644
index 0000000000..4b0efc88e1
--- /dev/null
+++ b/app/soapbox/features/ui/components/__tests__/subscribe-button.test.tsx
@@ -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('', () => {
+ let store;
+
+ describe('with "accountNotifies" disabled', () => {
+ it('renders nothing', () => {
+ account = normalizeAccount({ ...account, relationship: normalizeRelationship({ following: true }) });
+
+ render(, 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(, 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(, 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(, 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(, 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(, 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(, 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(, null, store);
+ expect(screen.getByTestId('icon-button').title).toEqual(`Subscribe to notifications from @${account.acct}`);
+ });
+ });
+ });
+ });
+
+});
diff --git a/app/soapbox/features/ui/components/subscription-button.tsx b/app/soapbox/features/ui/components/subscription-button.tsx
index a0c3e23124..bbe01f3bae 100644
--- a/app/soapbox/features/ui/components/subscription-button.tsx
+++ b/app/soapbox/features/ui/components/subscription-button.tsx
@@ -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 (