mirror of
https://github.com/strapi/strapi.git
synced 2025-09-27 01:09:49 +00:00
Merge pull request #15825 from strapi/chore/ee-seats-test
Add component tests for admin seat infos
This commit is contained in:
commit
d456156ac1
@ -8,7 +8,7 @@ const CreateAction = ({ onClick }) => {
|
|||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button data-testid="create-user-button" onClick={onClick} startIcon={<Envelop />} size="S">
|
<Button onClick={onClick} startIcon={<Envelop />} size="S">
|
||||||
{formatMessage({
|
{formatMessage({
|
||||||
id: 'Settings.permissions.users.create',
|
id: 'Settings.permissions.users.create',
|
||||||
defaultMessage: 'Invite new user',
|
defaultMessage: 'Invite new user',
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { render, fireEvent } from '@testing-library/react';
|
||||||
|
import { IntlProvider } from 'react-intl';
|
||||||
|
import { ThemeProvider, lightTheme } from '@strapi/design-system';
|
||||||
|
|
||||||
|
import CreateAction from '..';
|
||||||
|
|
||||||
|
const onClickSpy = jest.fn();
|
||||||
|
|
||||||
|
const ComponentFixture = (props) => (
|
||||||
|
<ThemeProvider theme={lightTheme}>
|
||||||
|
<IntlProvider locale="en" messages={{}}>
|
||||||
|
<CreateAction onClick={onClickSpy} {...props} />
|
||||||
|
</IntlProvider>
|
||||||
|
</ThemeProvider>
|
||||||
|
);
|
||||||
|
|
||||||
|
function setup(props) {
|
||||||
|
return render(<ComponentFixture {...props} />);
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('<CreateAction />', () => {
|
||||||
|
test('Does render', () => {
|
||||||
|
const { queryByText } = setup();
|
||||||
|
|
||||||
|
expect(queryByText('Invite new user')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Calls onClick callback', () => {
|
||||||
|
const { getByRole } = setup();
|
||||||
|
|
||||||
|
fireEvent.click(getByRole('button'));
|
||||||
|
|
||||||
|
expect(onClickSpy).toBeCalledTimes(1);
|
||||||
|
});
|
||||||
|
});
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,124 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { render } from '@testing-library/react';
|
||||||
|
import { IntlProvider } from 'react-intl';
|
||||||
|
import { ThemeProvider, lightTheme } from '@strapi/design-system';
|
||||||
|
import { useLicenseLimits } from '../../../../../../../hooks';
|
||||||
|
|
||||||
|
import AdminSeatInfo from '..';
|
||||||
|
|
||||||
|
const LICENSE_MOCK = {
|
||||||
|
license: {
|
||||||
|
data: {
|
||||||
|
enforcementUserCount: 10,
|
||||||
|
licenseLimitStatus: '',
|
||||||
|
permittedSeats: 100,
|
||||||
|
isHostedOnStrapiCloud: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const withMarkup = (query) => (text) =>
|
||||||
|
query((content, node) => {
|
||||||
|
const hasText = (node) => node.textContent === text;
|
||||||
|
const childrenDontHaveText = Array.from(node.children).every((child) => !hasText(child));
|
||||||
|
|
||||||
|
return hasText(node) && childrenDontHaveText;
|
||||||
|
});
|
||||||
|
|
||||||
|
jest.mock('../../../../../../../hooks', () => ({
|
||||||
|
...jest.requireActual('../../../../../../../hooks'),
|
||||||
|
useLicenseLimits: jest.fn(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
const ComponentFixture = (props) => (
|
||||||
|
<ThemeProvider theme={lightTheme}>
|
||||||
|
<IntlProvider locale="en" messages={{}}>
|
||||||
|
<AdminSeatInfo {...props} />
|
||||||
|
</IntlProvider>
|
||||||
|
</ThemeProvider>
|
||||||
|
);
|
||||||
|
|
||||||
|
function setup(props) {
|
||||||
|
return render(<ComponentFixture {...props} />);
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('<AdminSeatInfo />', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
|
||||||
|
useLicenseLimits.mockReturnValue(LICENSE_MOCK);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Do not render anything, when permittedSeats is falsy', () => {
|
||||||
|
useLicenseLimits.mockReturnValue({
|
||||||
|
...LICENSE_MOCK,
|
||||||
|
license: {
|
||||||
|
...LICENSE_MOCK.license,
|
||||||
|
data: {
|
||||||
|
...LICENSE_MOCK.license.data,
|
||||||
|
permittedSeats: null,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const { queryByText } = setup();
|
||||||
|
|
||||||
|
expect(queryByText('Admin seats')).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Render seat info', () => {
|
||||||
|
const { getByText } = setup();
|
||||||
|
const getByTextWithMarkup = withMarkup(getByText);
|
||||||
|
|
||||||
|
expect(getByText('Admin seats')).toBeInTheDocument();
|
||||||
|
expect(getByTextWithMarkup('10/100')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Render billing link (not on strapi cloud)', () => {
|
||||||
|
const { getByText } = setup();
|
||||||
|
|
||||||
|
expect(getByText('Contact sales')).toBeInTheDocument();
|
||||||
|
expect(getByText('Contact sales').closest('a')).toHaveAttribute(
|
||||||
|
'href',
|
||||||
|
'https://share.hsforms.com/1WhxtbTkJSUmfqqEuv4pwuA43qp4'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Render billing link (on strapi cloud)', () => {
|
||||||
|
useLicenseLimits.mockReturnValue({
|
||||||
|
...LICENSE_MOCK,
|
||||||
|
license: {
|
||||||
|
...LICENSE_MOCK.license,
|
||||||
|
data: {
|
||||||
|
...LICENSE_MOCK.license.data,
|
||||||
|
isHostedOnStrapiCloud: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const { getByText } = setup();
|
||||||
|
|
||||||
|
expect(getByText('Add seats')).toBeInTheDocument();
|
||||||
|
expect(getByText('Add seats').closest('a')).toHaveAttribute(
|
||||||
|
'href',
|
||||||
|
'https://cloud.strapi.io/profile/billing'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Render OVER_LIMIT icon', () => {
|
||||||
|
useLicenseLimits.mockReturnValue({
|
||||||
|
...LICENSE_MOCK,
|
||||||
|
license: {
|
||||||
|
...LICENSE_MOCK.license,
|
||||||
|
data: {
|
||||||
|
...LICENSE_MOCK.license.data,
|
||||||
|
licenseLimitStatus: 'OVER_LIMIT',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const { getByText } = setup();
|
||||||
|
|
||||||
|
expect(getByText('At limit: add seats to invite more users')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user