refactor: simplify notifications channels flag logic (#1381)
This commit is contained in:
15
codecov.yml
Normal file
15
codecov.yml
Normal file
@@ -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"
|
||||
@@ -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 || '[]'),
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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(),
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user