Skip to content

Commit 09bd960

Browse files
authored
Merge pull request #2325 from ofhope/error-modal-tests
test: add ErrorModal tests and story
2 parents 59326e8 + cbe4672 commit 09bd960

File tree

3 files changed

+94
-2
lines changed

3 files changed

+94
-2
lines changed

client/modules/IDE/components/ErrorModal.jsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,14 @@ const ErrorModal = ({ type, service, closeModal }) => {
6969
};
7070

7171
ErrorModal.propTypes = {
72-
type: PropTypes.string.isRequired,
72+
type: PropTypes.oneOf([
73+
'forceAuthentication',
74+
'staleSession',
75+
'staleProject',
76+
'oauthError'
77+
]).isRequired,
7378
closeModal: PropTypes.func.isRequired,
74-
service: PropTypes.string
79+
service: PropTypes.oneOf(['google', 'github'])
7580
};
7681

7782
ErrorModal.defaultProps = {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import ErrorModal from './ErrorModal';
2+
3+
export default {
4+
title: 'IDE/ErrorModal',
5+
component: ErrorModal,
6+
argTypes: {
7+
closeModal: { action: 'closed' }
8+
}
9+
};
10+
11+
export const ForceAuthenticationErrorModal = {
12+
args: {
13+
type: 'forceAuthentication'
14+
}
15+
};
16+
export const StaleSessionErrorModal = {
17+
args: {
18+
type: 'staleSession'
19+
}
20+
};
21+
export const StaleProjectErrorModal = {
22+
args: {
23+
type: 'staleProject'
24+
}
25+
};
26+
export const OauthErrorModal = {
27+
args: {
28+
type: 'oauthError'
29+
}
30+
};
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import React from 'react';
2+
3+
import { render, screen } from '../../../test-utils';
4+
5+
import ErrorModal from './ErrorModal';
6+
7+
jest.mock('../../../i18n');
8+
9+
describe('<ErrorModal />', () => {
10+
it('renders type forceAuthentication', () => {
11+
render(<ErrorModal type="forceAuthentication" closeModal={jest.fn()} />);
12+
13+
expect(screen.getByText('Login')).toBeVisible();
14+
expect(screen.getByText('Sign Up')).toBeVisible();
15+
});
16+
17+
it('renders type staleSession', () => {
18+
render(<ErrorModal type="staleSession" closeModal={jest.fn()} />);
19+
20+
expect(screen.getByText('log in')).toBeVisible();
21+
});
22+
23+
it('renders type staleProject', () => {
24+
render(<ErrorModal type="staleProject" closeModal={jest.fn()} />);
25+
26+
expect(
27+
screen.getByText(
28+
'The project you have attempted to save has been saved from another window',
29+
{ exact: false }
30+
)
31+
).toBeVisible();
32+
});
33+
34+
it('renders type oauthError with service google', () => {
35+
render(
36+
<ErrorModal type="oauthError" service="google" closeModal={jest.fn()} />
37+
);
38+
39+
expect(
40+
screen.getByText('There was a problem linking your Google account', {
41+
exact: false
42+
})
43+
).toBeVisible();
44+
});
45+
46+
it('renders type oauthError with service github', () => {
47+
render(
48+
<ErrorModal type="oauthError" service="github" closeModal={jest.fn()} />
49+
);
50+
51+
expect(
52+
screen.getByText('There was a problem linking your GitHub account', {
53+
exact: false
54+
})
55+
).toBeVisible();
56+
});
57+
});

0 commit comments

Comments
 (0)