Skip to content

test: add ErrorModal tests and story #2325

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

Merged
merged 6 commits into from
Jul 30, 2023
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
9 changes: 7 additions & 2 deletions client/modules/IDE/components/ErrorModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,14 @@ const ErrorModal = ({ type, service, closeModal }) => {
};

ErrorModal.propTypes = {
type: PropTypes.string.isRequired,
type: PropTypes.oneOf([
'forceAuthentication',
'staleSession',
'staleProject',
'oauthError'
]).isRequired,
closeModal: PropTypes.func.isRequired,
service: PropTypes.string
service: PropTypes.oneOf(['google', 'github'])
};

ErrorModal.defaultProps = {
Expand Down
30 changes: 30 additions & 0 deletions client/modules/IDE/components/ErrorModal.stories.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import ErrorModal from './ErrorModal';

export default {
title: 'IDE/ErrorModal',
component: ErrorModal,
argTypes: {
closeModal: { action: 'closed' }
}
};

export const ForceAuthenticationErrorModal = {
args: {
type: 'forceAuthentication'
}
};
export const StaleSessionErrorModal = {
args: {
type: 'staleSession'
}
};
export const StaleProjectErrorModal = {
args: {
type: 'staleProject'
}
};
export const OauthErrorModal = {
args: {
type: 'oauthError'
}
};
57 changes: 57 additions & 0 deletions client/modules/IDE/components/ErrorModal.unit.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React from 'react';

import { render, screen } from '../../../test-utils';

import ErrorModal from './ErrorModal';

jest.mock('../../../i18n');

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

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

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

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

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

expect(
screen.getByText(
'The project you have attempted to save has been saved from another window',
{ exact: false }
)
).toBeVisible();
});

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

expect(
screen.getByText('There was a problem linking your Google account', {
exact: false
})
).toBeVisible();
});

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

expect(
screen.getByText('There was a problem linking your GitHub account', {
exact: false
})
).toBeVisible();
});
});