Skip to content

Commit

Permalink
Merge pull request #3221 from processing/develop-khanniie-testwarnings
Browse files Browse the repository at this point in the history
fix (some) test suite warnings
  • Loading branch information
raclim authored Aug 22, 2024
2 parents 272645f + de1b882 commit 2dc1835
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import EditorAccessibility from './EditorAccessibility';

describe('<EditorAccessibility />', () => {
it('renders empty message with no lines', () => {
render(<EditorAccessibility lintMessages={[]} />);
render(<EditorAccessibility lintMessages={[]} currentLine={0} />);

expect(
screen.getByRole('listitem', {
Expand All @@ -21,11 +21,12 @@ describe('<EditorAccessibility />', () => {
lintMessages={[
{
severity: 'info',
line: '1',
line: 1,
message: 'foo',
id: '1a2b3c'
id: 123
}
]}
currentLine={0}
/>
);

Expand Down
16 changes: 13 additions & 3 deletions client/modules/IDE/components/ErrorModal.unit.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,30 @@ jest.mock('../../../i18n');

describe('<ErrorModal />', () => {
it('renders type forceAuthentication', () => {
render(<ErrorModal type="forceAuthentication" closeModal={jest.fn()} />);
render(
<ErrorModal
type="forceAuthentication"
closeModal={jest.fn()}
service="google"
/>
);

expect(screen.getByText('Login')).toBeVisible();
expect(screen.getByText('Sign Up')).toBeVisible();
});

it('renders type staleSession', () => {
render(<ErrorModal type="staleSession" closeModal={jest.fn()} />);
render(
<ErrorModal type="staleSession" closeModal={jest.fn()} service="google" />
);

expect(screen.getByText('log in')).toBeVisible();
});

it('renders type staleProject', () => {
render(<ErrorModal type="staleProject" closeModal={jest.fn()} />);
render(
<ErrorModal type="staleProject" closeModal={jest.fn()} service="google" />
);

expect(
screen.getByText(
Expand Down
8 changes: 7 additions & 1 deletion client/modules/IDE/components/FileNode.unit.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,18 @@ describe('<FileNode />', () => {
});

it('can change to a different extension', async () => {
const mockConfirm = jest.fn(() => true);
window.confirm = mockConfirm;

const newName = 'newname.gif';
const props = renderFileNode('file');

changeName(newName);

await waitFor(() => expect(props.updateFileName).not.toHaveBeenCalled());
expect(mockConfirm).toHaveBeenCalled();
await waitFor(() =>
expect(props.updateFileName).toHaveBeenCalledWith(props.id, newName)
);
await expectFileNameToBe(props.name);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ describe('project.controller', () => {
});

it('fails if user does not have permission', async () => {
// We don't want to clog up the jest output with extra
// logs, so we turn off console warn for this one test.
jest.spyOn(console, 'warn').mockImplementation(() => {});

request.user = { _id: 'abc123', username: 'alice' };
request.params = {
username: 'dana'
Expand Down
2 changes: 1 addition & 1 deletion server/controllers/project.controller/createProject.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export async function apiCreateProject(req, res) {

const checkUserHasPermission = () => {
if (req.user.username !== req.params.username) {
console.log('no permission');
console.warn('no permission');
const error = new ProjectValidationError(
`'${req.user.username}' does not have permission to create for '${req.params.username}'`
);
Expand Down

0 comments on commit 2dc1835

Please sign in to comment.