diff --git a/src/renderer/components/NotificationRow.tsx b/src/renderer/components/NotificationRow.tsx index 3bd305433..ab64a0564 100644 --- a/src/renderer/components/NotificationRow.tsx +++ b/src/renderer/components/NotificationRow.tsx @@ -10,10 +10,8 @@ import { AppContext } from '../context/App'; import { Opacity, Size } from '../types'; import type { Notification } from '../typesGitHub'; import { cn } from '../utils/cn'; -import { - formatForDisplay, - isMarkAsDoneFeatureSupported, -} from '../utils/helpers'; +import { isMarkAsDoneFeatureSupported } from '../utils/features'; +import { formatForDisplay } from '../utils/helpers'; import { getNotificationTypeIcon, getNotificationTypeIconColor, diff --git a/src/renderer/components/RepositoryNotifications.tsx b/src/renderer/components/RepositoryNotifications.tsx index f48d64377..715f6e9a4 100644 --- a/src/renderer/components/RepositoryNotifications.tsx +++ b/src/renderer/components/RepositoryNotifications.tsx @@ -4,10 +4,8 @@ import { AppContext } from '../context/App'; import { Opacity, Size } from '../types'; import type { Notification } from '../typesGitHub'; import { cn } from '../utils/cn'; -import { - getChevronDetails, - isMarkAsDoneFeatureSupported, -} from '../utils/helpers'; +import { isMarkAsDoneFeatureSupported } from '../utils/features'; +import { getChevronDetails } from '../utils/helpers'; import { openRepository } from '../utils/links'; import { HoverGroup } from './HoverGroup'; import { NotificationRow } from './NotificationRow'; diff --git a/src/renderer/hooks/useNotifications.ts b/src/renderer/hooks/useNotifications.ts index 5b377f311..e3fe51191 100644 --- a/src/renderer/hooks/useNotifications.ts +++ b/src/renderer/hooks/useNotifications.ts @@ -13,7 +13,7 @@ import { markNotificationThreadAsDone, markNotificationThreadAsRead, } from '../utils/api/client'; -import { isMarkAsDoneFeatureSupported } from '../utils/helpers'; +import { isMarkAsDoneFeatureSupported } from '../utils/features'; import { getAllNotifications, setTrayIconColor, diff --git a/src/renderer/utils/api/client.ts b/src/renderer/utils/api/client.ts index 47e66da57..3615fc3a4 100644 --- a/src/renderer/utils/api/client.ts +++ b/src/renderer/utils/api/client.ts @@ -22,7 +22,7 @@ import type { Release, UserDetails, } from '../../typesGitHub'; -import { isAnsweredDiscussionFeatureSupported } from '../helpers'; +import { isAnsweredDiscussionFeatureSupported } from '../features'; import { QUERY_SEARCH_DISCUSSIONS } from './graphql/discussions'; import { formatAsGitHubSearchSyntax } from './graphql/utils'; import { apiRequestAuth } from './request'; diff --git a/src/renderer/utils/features.test.ts b/src/renderer/utils/features.test.ts new file mode 100644 index 000000000..35b4cb980 --- /dev/null +++ b/src/renderer/utils/features.test.ts @@ -0,0 +1,97 @@ +import { + mockGitHubCloudAccount, + mockGitHubEnterpriseServerAccount, +} from '../__mocks__/state-mocks'; + +import { + isAnsweredDiscussionFeatureSupported, + isMarkAsDoneFeatureSupported, +} from './features'; + +describe('renderer/utils/features.ts', () => { + describe('isMarkAsDoneFeatureSupported', () => { + it('should return true for GitHub Cloud', () => { + expect(isMarkAsDoneFeatureSupported(mockGitHubCloudAccount)).toBe(true); + }); + + it('should return false for GitHub Enterprise Server < v3.13', () => { + const account = { + ...mockGitHubEnterpriseServerAccount, + version: '3.12.0', + }; + + expect(isMarkAsDoneFeatureSupported(account)).toBe(false); + }); + + it('should return true for GitHub Enterprise Server >= v3.13', () => { + const account = { + ...mockGitHubEnterpriseServerAccount, + version: '3.13.3', + }; + + expect(isMarkAsDoneFeatureSupported(account)).toBe(true); + }); + + it('should return false for GitHub Enterprise Server when partial version available', () => { + const account = { + ...mockGitHubEnterpriseServerAccount, + version: '3', + }; + + expect(isMarkAsDoneFeatureSupported(account)).toBe(false); + }); + + it('should return false for GitHub Enterprise Server when no version available', () => { + const account = { + ...mockGitHubEnterpriseServerAccount, + version: null, + }; + + expect(isMarkAsDoneFeatureSupported(account)).toBe(false); + }); + }); + + describe('isAnsweredDiscussionFeatureSupported', () => { + it('should return true for GitHub Cloud', () => { + expect(isAnsweredDiscussionFeatureSupported(mockGitHubCloudAccount)).toBe( + true, + ); + }); + + it('should return false for GitHub Enterprise Server < v3.12', () => { + const account = { + ...mockGitHubEnterpriseServerAccount, + version: '3.11.0', + }; + + expect(isAnsweredDiscussionFeatureSupported(account)).toBe(false); + }); + + it('should return true for GitHub Enterprise Server >= v3.12', () => { + const account = { + ...mockGitHubEnterpriseServerAccount, + version: '3.12.3', + }; + + expect(isAnsweredDiscussionFeatureSupported(account)).toBe(true); + }); + + it('should return false for GitHub Enterprise Server when partial version available', () => { + const account = { + ...mockGitHubEnterpriseServerAccount, + version: '3', + }; + + expect(isAnsweredDiscussionFeatureSupported(account)).toBe(false); + }); + + it('should return false for GitHub Enterprise Server when no version available', () => { + const account = { + ...mockGitHubEnterpriseServerAccount, + version: null, + }; + + expect(isMarkAsDoneFeatureSupported(account)).toBe(false); + }); + }); +}); diff --git a/src/renderer/utils/features.ts b/src/renderer/utils/features.ts new file mode 100644 index 000000000..9e2a83e06 --- /dev/null +++ b/src/renderer/utils/features.ts @@ -0,0 +1,41 @@ +import type { Account } from '../types'; +import { isEnterpriseServerHost } from './helpers'; + +/** + * Check if the "Mark as done" feature is supported for the given account. + * + * GitHub Cloud or GitHub Enterprise Server 3.13 or newer is required to support this feature. + */ + +export function isMarkAsDoneFeatureSupported(account: Account): boolean { + if (isEnterpriseServerHost(account.hostname)) { + if (account.version) { + const version = account?.version.split('.').map(Number); + return version[0] >= 3 && version[1] >= 13; + } + + return false; + } + + return true; +} +/** + * Check if the "answered" discussions are supported for the given account. + * + * GitHub Cloud or GitHub Enterprise Server 3.12 or newer is required to support this feature. + */ + +export function isAnsweredDiscussionFeatureSupported( + account: Account, +): boolean { + if (isEnterpriseServerHost(account.hostname)) { + if (account.version) { + const version = account?.version.split('.').map(Number); + return version[0] >= 3 && version[1] >= 12; + } + + return false; + } + + return true; +} diff --git a/src/renderer/utils/helpers.test.ts b/src/renderer/utils/helpers.test.ts index 56f3beef6..42547328c 100644 --- a/src/renderer/utils/helpers.test.ts +++ b/src/renderer/utils/helpers.test.ts @@ -1,9 +1,5 @@ import type { AxiosPromise, AxiosResponse } from 'axios'; -import { - mockGitHubCloudAccount, - mockGitHubEnterpriseServerAccount, - mockPersonalAccessTokenAccount, -} from '../__mocks__/state-mocks'; +import { mockPersonalAccessTokenAccount } from '../__mocks__/state-mocks'; import { ChevronDownIcon, @@ -19,6 +15,7 @@ import { mockSingleNotification, } from './api/__mocks__/response-mocks'; import * as apiRequests from './api/request'; + import { formatForDisplay, formatNotificationUpdatedAt, @@ -27,9 +24,7 @@ import { getChevronDetails, getFilterCount, getPlatformFromHostname, - isAnsweredDiscussionFeatureSupported, isEnterpriseServerHost, - isMarkAsDoneFeatureSupported, } from './helpers'; describe('renderer/utils/helpers.ts', () => { @@ -69,92 +64,6 @@ describe('renderer/utils/helpers.ts', () => { }); }); - describe('isMarkAsDoneFeatureSupported', () => { - it('should return true for GitHub Cloud', () => { - expect(isMarkAsDoneFeatureSupported(mockGitHubCloudAccount)).toBe(true); - }); - - it('should return false for GitHub Enterprise Server < v3.13', () => { - const account = { - ...mockGitHubEnterpriseServerAccount, - version: '3.12.0', - }; - - expect(isMarkAsDoneFeatureSupported(account)).toBe(false); - }); - - it('should return true for GitHub Enterprise Server >= v3.13', () => { - const account = { - ...mockGitHubEnterpriseServerAccount, - version: '3.13.3', - }; - - expect(isMarkAsDoneFeatureSupported(account)).toBe(true); - }); - - it('should return false for GitHub Enterprise Server when partial version available', () => { - const account = { - ...mockGitHubEnterpriseServerAccount, - version: '3', - }; - - expect(isMarkAsDoneFeatureSupported(account)).toBe(false); - }); - - it('should return false for GitHub Enterprise Server when no version available', () => { - const account = { - ...mockGitHubEnterpriseServerAccount, - version: null, - }; - - expect(isMarkAsDoneFeatureSupported(account)).toBe(false); - }); - }); - - describe('isAnsweredDiscussionFeatureSupported', () => { - it('should return true for GitHub Cloud', () => { - expect(isAnsweredDiscussionFeatureSupported(mockGitHubCloudAccount)).toBe( - true, - ); - }); - - it('should return false for GitHub Enterprise Server < v3.12', () => { - const account = { - ...mockGitHubEnterpriseServerAccount, - version: '3.11.0', - }; - - expect(isAnsweredDiscussionFeatureSupported(account)).toBe(false); - }); - - it('should return true for GitHub Enterprise Server >= v3.12', () => { - const account = { - ...mockGitHubEnterpriseServerAccount, - version: '3.12.3', - }; - - expect(isAnsweredDiscussionFeatureSupported(account)).toBe(true); - }); - - it('should return false for GitHub Enterprise Server when partial version available', () => { - const account = { - ...mockGitHubEnterpriseServerAccount, - version: '3', - }; - - expect(isAnsweredDiscussionFeatureSupported(account)).toBe(false); - }); - - it('should return false for GitHub Enterprise Server when no version available', () => { - const account = { - ...mockGitHubEnterpriseServerAccount, - version: null, - }; - - expect(isMarkAsDoneFeatureSupported(account)).toBe(false); - }); - }); - describe('generateNotificationReferrerId', () => { it('should generate the notification_referrer_id', () => { const referrerId = generateNotificationReferrerId(mockSingleNotification); diff --git a/src/renderer/utils/helpers.ts b/src/renderer/utils/helpers.ts index 889e04617..b2e1a4823 100644 --- a/src/renderer/utils/helpers.ts +++ b/src/renderer/utils/helpers.ts @@ -6,7 +6,7 @@ import { import { formatDistanceToNowStrict, parseISO } from 'date-fns'; import log from 'electron-log'; import { defaultSettings } from '../context/App'; -import type { Account, Chevron, Hostname, Link, SettingsState } from '../types'; +import type { Chevron, Hostname, Link, SettingsState } from '../types'; import type { Notification } from '../typesGitHub'; import { getHtmlUrl, getLatestDiscussion } from './api/client'; import type { PlatformType } from './auth/types'; @@ -27,44 +27,6 @@ export function isEnterpriseServerHost(hostname: Hostname): boolean { return !hostname.endsWith(Constants.DEFAULT_AUTH_OPTIONS.hostname); } -/** - * Check if the "Mark as done" feature is supported for the given account. - * - * GitHub Cloud or GitHub Enterprise Server 3.13 or newer is required to support this feature. - */ -export function isMarkAsDoneFeatureSupported(account: Account): boolean { - if (isEnterpriseServerHost(account.hostname)) { - if (account.version) { - const version = account?.version.split('.').map(Number); - return version[0] >= 3 && version[1] >= 13; - } - - return false; - } - - return true; -} - -/** - * Check if the "answered" discussions are supported for the given account. - * - * GitHub Cloud or GitHub Enterprise Server 3.12 or newer is required to support this feature. - */ -export function isAnsweredDiscussionFeatureSupported( - account: Account, -): boolean { - if (isEnterpriseServerHost(account.hostname)) { - if (account.version) { - const version = account?.version.split('.').map(Number); - return version[0] >= 3 && version[1] >= 12; - } - - return false; - } - - return true; -} - export function generateNotificationReferrerId( notification: Notification, ): string {