diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..646353f --- /dev/null +++ b/codecov.yml @@ -0,0 +1,15 @@ +coverage: + status: + project: + default: + enabled: yes + target: auto + threshold: 0% + patch: + default: + enabled: yes + target: auto + threshold: 0% +ignore: + - "src/i18n" + - "src/index.jsx" diff --git a/src/index.jsx b/src/index.jsx index d15b9da..2d508c5 100755 --- a/src/index.jsx +++ b/src/index.jsx @@ -65,8 +65,8 @@ initialize({ config: () => { mergeConfig({ SUPPORT_URL: process.env.SUPPORT_URL, - SHOW_PUSH_CHANNEL: process.env.SHOW_PUSH_CHANNEL === 'true', - SHOW_EMAIL_CHANNEL: process.env.SHOW_EMAIL_CHANNEL || 'false', + SHOW_PUSH_CHANNEL: process.env.SHOW_PUSH_CHANNEL || false, + SHOW_EMAIL_CHANNEL: process.env.SHOW_EMAIL_CHANNEL || false, ENABLE_COPPA_COMPLIANCE: (process.env.ENABLE_COPPA_COMPLIANCE || false), ENABLE_ACCOUNT_DELETION: (process.env.ENABLE_ACCOUNT_DELETION !== 'false'), COUNTRIES_WITH_DELETE_ACCOUNT_DISABLED: JSON.parse(process.env.COUNTRIES_WITH_DELETE_ACCOUNT_DISABLED || '[]'), diff --git a/src/notification-preferences/NotificationPreferences.test.jsx b/src/notification-preferences/NotificationPreferences.test.jsx index dcf364d..f1c5d34 100644 --- a/src/notification-preferences/NotificationPreferences.test.jsx +++ b/src/notification-preferences/NotificationPreferences.test.jsx @@ -3,7 +3,7 @@ import { Provider } from 'react-redux'; import configureStore from 'redux-mock-store'; import { BrowserRouter as Router } from 'react-router-dom'; -import { setConfig } from '@edx/frontend-platform'; +import { setConfig, mergeConfig } from '@edx/frontend-platform'; import * as auth from '@edx/frontend-platform/auth'; import { IntlProvider } from '@edx/frontend-platform/i18n'; import { fireEvent, render, screen } from '@testing-library/react'; @@ -110,9 +110,10 @@ describe('Notification Preferences', () => { let store; beforeEach(() => { - setConfig({ + mergeConfig({ SHOW_EMAIL_CHANNEL: '', - }); + SHOW_PUSH_CHANNEL: '', + }, 'App loadConfig override handler'); store = setupStore({ ...defaultPreferences, @@ -173,6 +174,59 @@ describe('Notification Preferences', () => { expect(screen.getAllByTestId('email-cadence-button')[0]).toBeDisabled(); expect(screen.getByTestId('toggle-newGrade-web')).not.toBeDisabled(); }); + + it('does not render push channel when SHOW_PUSH_CHANNEL is false', async () => { + setConfig({ + SHOW_PUSH_CHANNEL: '', + }); + store = setupStore({ + ...defaultPreferences, + status: SUCCESS_STATUS, + selectedCourse: '', + }); + await render(notificationPreferences(store)); + + expect(screen.queryByTestId('toggle-core-push')).not.toBeInTheDocument(); + }); + + it('renders push channel when SHOW_PUSH_CHANNEL is true', async () => { + setConfig({ + SHOW_PUSH_CHANNEL: 'true', + }); + store = setupStore({ + ...defaultPreferences, + status: SUCCESS_STATUS, + selectedCourse: '', + }); + await render(notificationPreferences(store)); + expect(screen.queryByTestId('toggle-core-push')).toBeInTheDocument(); + }); + + it('does not render email channel when SHOW_EMAIL_CHANNEL is false', async () => { + setConfig({ + SHOW_EMAIL_CHANNEL: '', + }); + store = setupStore({ + ...defaultPreferences, + status: SUCCESS_STATUS, + selectedCourse: '', + }); + await render(notificationPreferences(store)); + expect(screen.queryByTestId('toggle-core-email')).not.toBeInTheDocument(); + }); + + it('renders email channel when SHOW_EMAIL_CHANNEL is true', async () => { + setConfig({ + SHOW_EMAIL_CHANNEL: 'true', + }); + store = setupStore({ + ...defaultPreferences, + status: SUCCESS_STATUS, + selectedCourse: '', + }); + await render(notificationPreferences(store)); + expect(screen.queryByTestId('toggle-core-email')).toBeInTheDocument(); + }); }); describe('Notification Preferences API v2 Logic', () => { diff --git a/src/notification-preferences/data/utils.js b/src/notification-preferences/data/utils.js index 70c6371..ca5f871 100644 --- a/src/notification-preferences/data/utils.js +++ b/src/notification-preferences/data/utils.js @@ -3,7 +3,7 @@ import { getConfig } from '@edx/frontend-platform'; export const notificationChannels = () => ({ WEB: 'web', ...(getConfig().SHOW_PUSH_CHANNEL && { PUSH: 'push' }), - ...(getConfig().SHOW_EMAIL_CHANNEL === 'true' && { EMAIL: 'email' }), + ...(getConfig().SHOW_EMAIL_CHANNEL && { EMAIL: 'email' }), }); export const shouldHideAppPreferences = (preferences, appId) => { diff --git a/src/setupTest.js b/src/setupTest.js index e2e601f..2f38607 100755 --- a/src/setupTest.js +++ b/src/setupTest.js @@ -1,6 +1,8 @@ import 'core-js/stable'; import 'regenerator-runtime/runtime'; import '@testing-library/jest-dom'; +import { initialize, mergeConfig } from '@edx/frontend-platform'; +import { MockAuthService } from '@edx/frontend-platform/auth'; import MockedPluginSlot from './tests/MockedPluginSlot'; @@ -9,3 +11,39 @@ jest.mock('@openedx/frontend-plugin-framework', () => ({ Plugin: () => 'Plugin', PluginSlot: MockedPluginSlot, })); + +mergeConfig({ + SUPPORT_URL: process.env.SUPPORT_URL || 'https://support.example.com', + SHOW_PUSH_CHANNEL: process.env.SHOW_PUSH_CHANNEL || false, + SHOW_EMAIL_CHANNEL: process.env.SHOW_EMAIL_CHANNEL || false, + ENABLE_COPPA_COMPLIANCE: (process.env.ENABLE_COPPA_COMPLIANCE || false), + ENABLE_ACCOUNT_DELETION: (process.env.ENABLE_ACCOUNT_DELETION !== 'false'), + COUNTRIES_WITH_DELETE_ACCOUNT_DISABLED: JSON.parse(process.env.COUNTRIES_WITH_DELETE_ACCOUNT_DISABLED || '[]'), + ENABLE_DOB_UPDATE: (process.env.ENABLE_DOB_UPDATE || false), + MARKETING_EMAILS_OPT_IN: (process.env.MARKETING_EMAILS_OPT_IN || false), + PASSWORD_RESET_SUPPORT_LINK: process.env.PASSWORD_RESET_SUPPORT_LINK || 'https://support.example.com/password-reset', + LEARNER_FEEDBACK_URL: process.env.LEARNER_FEEDBACK_URL || 'https://support.example.com/feedback', +}, 'App loadConfig override handler'); + +initialize({ + handlers: { + config: () => { + mergeConfig({ + authenticatedUser: { + userId: 'abc123', + username: 'Mock User', + roles: [], + administrator: false, + }, + }); + }, + }, + messages: [], + authService: MockAuthService, +}); + +global.ResizeObserver = jest.fn().mockImplementation(() => ({ + observe: jest.fn(), + unobserve: jest.fn(), + disconnect: jest.fn(), +}));