Skip to content

Commit

Permalink
Merge pull request #2325 from ofhope/error-modal-tests
Browse files Browse the repository at this point in the history
test: add ErrorModal tests and story
  • Loading branch information
lindapaiste authored Jul 30, 2023
2 parents 59326e8 + cbe4672 commit 09bd960
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 2 deletions.
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();
});
});

0 comments on commit 09bd960

Please sign in to comment.