Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix (some) test suite warnings #3221

Merged
merged 2 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading