* refactor: replaced injectIntl with useIntl * test: update tests for useIntl hook implementation * fix: add missing trailing comma * test: fix failing component tests and remove deprecated defaultProps - Fix SwitchContent component defaultProps warning with default parameters - Fix Visibility component formatMessage errors and remove defaultProps - Fix FormControls component intl provider issues with useIntl mock - Fix EditButton component defaultProps and message formatting - Update EditableItemHeader, EmptyContent components - Replace React defaultProps with ES6 default parameters across components - Update test mocking to properly handle useIntl hook - All 82 tests now pass (previously 4 failed, 78 passed) Resolves React deprecation warnings and modernizes component patterns. * fix: add missing trailing comma
44 lines
1.4 KiB
JavaScript
44 lines
1.4 KiB
JavaScript
import React from 'react';
|
|
import { render } from '@testing-library/react';
|
|
import { IntlProvider } from '@edx/frontend-platform/i18n';
|
|
import { Visibility, VisibilitySelect } from './Visibility';
|
|
import '@testing-library/jest-dom';
|
|
|
|
const messages = {
|
|
'profile.visibility.who.just.me': 'Just me',
|
|
'profile.visibility.who.everyone': 'Everyone',
|
|
};
|
|
|
|
describe('Visibility', () => {
|
|
it('shows the correct icon and label for private', () => {
|
|
const { getByText } = render(
|
|
<IntlProvider locale="en" messages={messages}>
|
|
<Visibility to="private" />
|
|
</IntlProvider>,
|
|
);
|
|
expect(getByText(/just me/i)).toBeInTheDocument();
|
|
});
|
|
it('shows the correct icon and label for all_users', () => {
|
|
const { getByText } = render(
|
|
<IntlProvider locale="en" messages={messages}>
|
|
<Visibility to="all_users" />
|
|
</IntlProvider>,
|
|
);
|
|
expect(getByText(/everyone/i)).toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
describe('VisibilitySelect', () => {
|
|
it('renders both options', () => {
|
|
const { getByRole, getAllByRole } = render(
|
|
<IntlProvider locale="en" messages={messages}>
|
|
<VisibilitySelect value="private" onChange={() => {}} />
|
|
</IntlProvider>,
|
|
);
|
|
const select = getByRole('combobox');
|
|
const options = getAllByRole('option');
|
|
expect(select).toBeInTheDocument();
|
|
expect(options.length).toBe(2);
|
|
});
|
|
});
|