Skip to content

Commit

Permalink
test(ui): Disallow translations in tests (#82841)
Browse files Browse the repository at this point in the history
  • Loading branch information
scttcper authored Jan 3, 2025
1 parent 3800216 commit fa25473
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 56 deletions.
44 changes: 33 additions & 11 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ const restrictedImportPaths = [
},
];

const restrictedImportPatterns = [
{
group: ['sentry/components/devtoolbar/*'],
message: 'Do not depend on toolbar internals',
},
{
group: ['*.spec*'],
message:
'Do not import from test files. This causes tests to be executed multiple times.',
},
];

// Used by both: `languageOptions` & `parserOptions`
const ecmaVersion = 6; // TODO(ryan953): change to 'latest'

Expand Down Expand Up @@ -418,17 +430,7 @@ export default typescript.config([
'no-restricted-imports': [
'error',
{
patterns: [
{
group: ['sentry/components/devtoolbar/*'],
message: 'Do not depend on toolbar internals',
},
{
group: ['*.spec*'],
message:
'Do not import from test files. This causes tests to be executed multiple times.',
},
],
patterns: restrictedImportPatterns,
paths: restrictedImportPaths,
},
],
Expand Down Expand Up @@ -824,6 +826,26 @@ export default typescript.config([
'testing-library/no-unnecessary-act': 'off',
},
},
{
name: 'files/sentry-test',
files: ['**/*.spec.{ts,js,tsx,jsx}', 'tests/js/**/*.{ts,js,tsx,jsx}'],
rules: {
'no-restricted-imports': [
'error',
{
patterns: restrictedImportPatterns,
paths: [
// @ts-ignore
...restrictedImportPaths,
{
name: 'sentry/locale',
message: 'Translations are not needed in tests.',
},
],
},
],
},
},
{
// We specify rules explicitly for the sdk-loader here so we do not have
// eslint ignore comments included in the source file, which is consumed
Expand Down
3 changes: 1 addition & 2 deletions static/app/components/charts/optionSelector.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {initializeOrg} from 'sentry-test/initializeOrg';
import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';

import OptionSelector from 'sentry/components/charts/optionSelector';
import {t} from 'sentry/locale';

describe('Charts > OptionSelector (Multiple)', function () {
const features = ['discover-basic'];
Expand All @@ -32,7 +31,7 @@ describe('Charts > OptionSelector (Multiple)', function () {
<OptionSelector
multiple
isOpen
title={t('Y-Axis')}
title={'Y-Axis'}
selected={currentSelected}
options={yAxisOptions}
onChange={newSelected => {
Expand Down
1 change: 1 addition & 0 deletions static/app/locale.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {render, screen} from 'sentry-test/reactTestingLibrary';
import {textWithMarkupMatcher} from 'sentry-test/utils';

// eslint-disable-next-line no-restricted-imports
import {tct} from 'sentry/locale';

describe('locale.gettextComponentTemplate', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
ModalBody,
ModalFooter,
} from 'sentry/components/globalModal/components';
import {t} from 'sentry/locale';
import MessagingIntegrationModal from 'sentry/views/alerts/rules/issue/messagingIntegrationModal';
import {MessagingIntegrationAnalyticsView} from 'sentry/views/alerts/rules/issue/setupMessagingIntegrationButton';

Expand All @@ -27,8 +26,8 @@ describe('MessagingIntegrationModal', function () {
closeModal={closeModal}
Header={makeClosableHeader(() => {})}
Body={ModalBody}
headerContent={t('Connect with a messaging tool')}
bodyContent={t('Receive alerts and digests right where you work.')}
headerContent={'Connect with a messaging tool'}
bodyContent={'Receive alerts and digests right where you work.'}
providers={providers}
CloseButton={makeCloseButton(() => {})}
Footer={ModalFooter}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {ProjectFixture} from 'sentry-fixture/project';

import {render, screen, waitFor, within} from 'sentry-test/reactTestingLibrary';

import {t} from 'sentry/locale';
import {useLocation} from 'sentry/utils/useLocation';
import usePageFilters from 'sentry/utils/usePageFilters';
import useCrossPlatformProject from 'sentry/views/insights/mobile/common/queries/useCrossPlatformProject';
Expand Down Expand Up @@ -199,14 +198,14 @@ describe('Screens Landing Page', function () {
organization.features = [];
render(<ScreensLandingPage />, {organization});
expect(
await screen.findByText(t("You don't have access to this feature"))
await screen.findByText("You don't have access to this feature")
).toBeInTheDocument();
});

it('shows content if permission is there', async function () {
organization.features = [MODULE_FEATURE];
render(<ScreensLandingPage />, {organization});
expect(await screen.findAllByText(t('Mobile Screens'))).toHaveLength(2);
expect(await screen.findAllByText('Mobile Screens')).toHaveLength(2);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
waitForElementToBeRemoved,
} from 'sentry-test/reactTestingLibrary';

import {t} from 'sentry/locale';
import {EntryType} from 'sentry/types/event';
import {SolutionsHubDrawer} from 'sentry/views/issueDetails/streamline/sidebar/solutionsHubDrawer';

Expand Down Expand Up @@ -142,9 +141,7 @@ describe('SolutionsHubDrawer', () => {
const startButton = screen.getByRole('button', {name: 'Start Autofix'});
await userEvent.click(startButton);

expect(
await screen.findByRole('button', {name: t('Start Over')})
).toBeInTheDocument();
expect(await screen.findByRole('button', {name: 'Start Over'})).toBeInTheDocument();
});

it('displays autofix steps and Start Over button when autofixData is available', async () => {
Expand All @@ -158,9 +155,7 @@ describe('SolutionsHubDrawer', () => {
{organization}
);

expect(
await screen.findByRole('button', {name: t('Start Over')})
).toBeInTheDocument();
expect(await screen.findByRole('button', {name: 'Start Over'})).toBeInTheDocument();
});

it('resets autofix on clicking the start over button', async () => {
Expand All @@ -174,7 +169,7 @@ describe('SolutionsHubDrawer', () => {
{organization}
);

const startOverButton = await screen.findByRole('button', {name: t('Start Over')});
const startOverButton = await screen.findByRole('button', {name: 'Start Over'});
expect(startOverButton).toBeInTheDocument();
await userEvent.click(startOverButton);

Expand Down
18 changes: 3 additions & 15 deletions static/app/views/projectInstall/createProject.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
} from 'sentry-test/reactTestingLibrary';

import {addErrorMessage, addSuccessMessage} from 'sentry/actionCreators/indicator';
import {tct} from 'sentry/locale';
import OrganizationStore from 'sentry/stores/organizationStore';
import TeamStore from 'sentry/stores/teamStore';
import type {Organization} from 'sentry/types/organization';
Expand Down Expand Up @@ -220,11 +219,7 @@ describe('CreateProject', function () {
expect(frameWorkModalMockRequests.projectCreationMockRequest).toHaveBeenCalledTimes(
1
);
expect(addSuccessMessage).toHaveBeenCalledWith(
tct('Created project [project]', {
project: 'testProj',
})
);
expect(addSuccessMessage).toHaveBeenCalledWith('Created project testProj');
});

it('should display error message on proj creation failure', async function () {
Expand Down Expand Up @@ -261,11 +256,7 @@ describe('CreateProject', function () {
expect(frameWorkModalMockRequests.projectCreationMockRequest).toHaveBeenCalledTimes(
1
);
expect(addErrorMessage).toHaveBeenCalledWith(
tct('Failed to create project [project]', {
project: 'apple-ios',
})
);
expect(addErrorMessage).toHaveBeenCalledWith('Failed to create project apple-ios');
});

it('should display success message when using member endpoint', async function () {
Expand Down Expand Up @@ -293,10 +284,7 @@ describe('CreateProject', function () {
frameWorkModalMockRequests.experimentalprojectCreationMockRequest
).toHaveBeenCalledTimes(1);
expect(addSuccessMessage).toHaveBeenCalledWith(
tct('Created [project] under new team [team]', {
project: 'testProj',
team: '#testTeam',
})
'Created testProj under new team #testTeam'
);
});

Expand Down
21 changes: 7 additions & 14 deletions static/app/views/projectInstall/createProject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,14 @@ function CreateProject() {
ProjectsStore.onCreateSuccess(projectData, organization.slug);

if (team) {
addSuccessMessage(
tct('Created project [project]', {
project: `${projectData.slug}`,
})
);
addSuccessMessage(t('Created project %s', `${projectData.slug}`));
} else {
addSuccessMessage(
tct('Created [project] under new team [team]', {
project: `${projectData.slug}`,
team: `#${projectData.team_slug}`,
})
t(
'Created %s under new team %s',
`${projectData.slug}`,
`#${projectData.team_slug}`
)
);
}

Expand All @@ -189,11 +186,7 @@ function CreateProject() {
} catch (err) {
setInFlight(false);
setErrors(err.responseJSON);
addErrorMessage(
tct('Failed to create project [project]', {
project: `${projectName}`,
})
);
addErrorMessage(t('Failed to create project %s', `${projectName}`));

// Only log this if the error is something other than:
// * The user not having access to create a project, or,
Expand Down
1 change: 1 addition & 0 deletions tests/js/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {ConfigFixture} from 'sentry-fixture/config';
import {resetMockDate} from 'sentry-test/utils';

import type {Client} from 'sentry/__mocks__/api';
// eslint-disable-next-line no-restricted-imports
import {DEFAULT_LOCALE_DATA, setLocale} from 'sentry/locale';
import ConfigStore from 'sentry/stores/configStore';
import {DANGEROUS_SET_TEST_HISTORY} from 'sentry/utils/browserHistory';
Expand Down

0 comments on commit fa25473

Please sign in to comment.