Skip to content

Commit 0dc601b

Browse files
committed
SMP: Added delete submission functionality + misc fixes
1 parent 4cea6bf commit 0dc601b

File tree

16 files changed

+384
-222
lines changed

16 files changed

+384
-222
lines changed

__tests__/shared/actions/smp.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,25 @@ describe('smp.confirmDelete', () => {
5151
});
5252

5353
describe('smp.deleteSubmissionDone', () => {
54-
const a = actions.smp.deleteSubmissionDone('challengeId', 'submissionId');
54+
global.fetch = jest.fn(() => Promise.resolve());
55+
56+
const a = actions.smp.deleteSubmissionDone('Token V3', 'submissionId');
5557

5658
test('has expected type', () => {
5759
expect(a.type).toBe('SMP/DELETE_SUBMISSION_DONE');
5860
});
5961

62+
test('Calls the correct endpoint', () => {
63+
expect(global.fetch).toHaveBeenCalledWith(
64+
'API-URL-V3/submissions/submissionId', {
65+
headers: {
66+
Authorization: 'Bearer Token V3',
67+
'Content-Type': 'application/json',
68+
},
69+
method: 'DELETE',
70+
});
71+
});
72+
6073
test('payload be submissionId', () =>
6174
a.payload.then(res => expect(res).toEqual('submissionId')));
6275
});
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import actions from 'actions/topcoder_header';
2+
3+
const mockNode = {
4+
getBoundingClientRect: () => 'rect',
5+
};
6+
7+
test('openMenu', () => {
8+
const a = actions.topcoderHeader.openMenu('Menu', mockNode);
9+
expect(a.type).toBe('TOPCODER_HEADER/OPEN_MENU');
10+
expect(a.payload).toEqual({
11+
menu: 'Menu',
12+
trigger: 'rect',
13+
});
14+
});
15+
16+
test('openSearch', () => {
17+
const a = actions.topcoderHeader.openSearch(mockNode);
18+
expect(a.type).toBe('TOPCODER_HEADER/OPEN_SEARCH');
19+
expect(a.payload).toEqual({
20+
trigger: 'rect',
21+
});
22+
});

__tests__/shared/components/SubmissionManagement/ScreeningStatus.jsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ test('Snapshot match', () => {
1010
screeningObject={{
1111
status: 'failed',
1212
}}
13-
submissionId="12345"
13+
submissionId={12345}
1414
/>
1515
));
1616
expect(rnd.getRenderOutput()).toMatchSnapshot();
@@ -21,7 +21,7 @@ test('Snapshot match', () => {
2121
status: 'failed',
2222
warnings: [],
2323
}}
24-
submissionId="12345"
24+
submissionId={12345}
2525
/>
2626
));
2727
expect(rnd.getRenderOutput()).toMatchSnapshot();
@@ -31,7 +31,7 @@ test('Snapshot match', () => {
3131
screeningObject={{
3232
status: 'passed',
3333
}}
34-
submissionId="12345"
34+
submissionId={12345}
3535
/>
3636
));
3737
expect(rnd.getRenderOutput()).toMatchSnapshot();
@@ -42,7 +42,7 @@ test('Snapshot match', () => {
4242
status: 'passed',
4343
warnings: [],
4444
}}
45-
submissionId="12345"
45+
submissionId={12345}
4646
/>
4747
));
4848
expect(rnd.getRenderOutput()).toMatchSnapshot();
@@ -53,7 +53,7 @@ test('Snapshot match', () => {
5353
status: 'pending',
5454
warnings: [],
5555
}}
56-
submissionId="12345"
56+
submissionId={12345}
5757
/>
5858
));
5959
expect(rnd.getRenderOutput()).toMatchSnapshot();
@@ -64,7 +64,7 @@ test('Snapshot match', () => {
6464
status: 'Screening Status',
6565
warnings: [],
6666
}}
67-
submissionId="12345"
67+
submissionId={12345}
6868
/>
6969
));
7070
expect(rnd.getRenderOutput()).toMatchSnapshot();
Lines changed: 68 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,72 @@
11
import React from 'react';
2-
import Renderer from 'react-test-renderer/shallow';
2+
import Rnd from 'react-test-renderer/shallow';
33
import Submission from 'components/SubmissionManagement/Submission';
4+
import TU from 'react-dom/test-utils';
45

5-
test('Matches shallow shapshot', () => {
6-
const renderer = new Renderer();
7-
renderer.render(<Submission />);
8-
expect(renderer.getRenderOutput()).toMatchSnapshot();
6+
const mockOnDelete = jest.fn();
7+
const mockOnShowDetails = jest.fn();
8+
9+
const rnd = new Rnd();
10+
11+
test('Snapshot match', () => {
12+
rnd.render((
13+
<Submission
14+
onDelete={mockOnDelete}
15+
onShowDetails={mockOnShowDetails}
16+
showScreeningDetails
17+
type="develop"
18+
/>
19+
));
20+
expect(rnd.getRenderOutput()).toMatchSnapshot();
21+
rnd.render((
22+
<Submission
23+
onDelete={mockOnDelete}
24+
onShowDetails={mockOnShowDetails}
25+
submissionObject={{
26+
submissionId: 12345,
27+
screening: {},
28+
}}
29+
type="design"
30+
/>
31+
));
32+
expect(rnd.getRenderOutput()).toMatchSnapshot();
33+
});
34+
35+
class Wrapper extends React.Component {
36+
componentDidMount() {}
37+
render() {
38+
return <table><tbody><Submission {...this.props} /></tbody></table>;
39+
}
40+
}
41+
42+
const page = TU.renderIntoDocument((
43+
<Wrapper
44+
onDelete={mockOnDelete}
45+
onShowDetails={mockOnShowDetails}
46+
submissionObject={{
47+
submissionId: 12345,
48+
screening: {},
49+
}}
50+
type="design"
51+
/>
52+
));
53+
54+
describe('User input', () => {
55+
beforeEach(() => jest.clearAllMocks());
56+
57+
test('onDelete', () => {
58+
const icon = TU.findAllInRenderedTree(page, item =>
59+
item && item.className && item.className.match(/delete-icon/));
60+
expect(icon.length).toBe(1);
61+
TU.Simulate.click(icon[0]);
62+
expect(mockOnDelete).toHaveBeenCalled();
63+
});
64+
65+
test('onShowDetails', () => {
66+
const icon = TU.findAllInRenderedTree(page, item =>
67+
item && item.className && item.className.match(/expand-icon/));
68+
expect(icon.length).toBe(1);
69+
TU.Simulate.click(icon[0]);
70+
expect(mockOnShowDetails).toHaveBeenCalled();
71+
});
972
});

__tests__/shared/components/SubmissionManagement/__snapshots__/Submission.jsx.snap

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`Matches shallow shapshot 1`] = `
3+
exports[`Snapshot match 1`] = `
44
<tr
55
className="src-shared-components-SubmissionManagement-Submission-___styles__submission-row___2yQOc"
66
>
@@ -9,7 +9,7 @@ exports[`Matches shallow shapshot 1`] = `
99
>
1010
<img
1111
alt="preview"
12-
className="src-shared-components-SubmissionManagement-Submission-___styles__design-img___1klwr"
12+
className="src-shared-components-SubmissionManagement-Submission-___styles__dev-img___rbFEF"
1313
src="https://studio.topcoder-dev.com?module=DownloadSubmission&sbmid=undefined&sbt=tiny"
1414
/>
1515
</td>
@@ -22,18 +22,80 @@ exports[`Matches shallow shapshot 1`] = `
2222
>
2323
Invalid date
2424
</td>
25+
<td>
26+
<div
27+
className="src-shared-components-SubmissionManagement-Submission-___styles__action-col___2M1RY"
28+
>
29+
<a
30+
href="https://studio.topcoder-dev.com?module=DownloadSubmission&sbmid=undefined&sbt=original"
31+
>
32+
<DownloadIcon />
33+
</a>
34+
<button
35+
className="src-shared-components-SubmissionManagement-Submission-___styles__delete-icon___2M67z"
36+
onClick={[Function]}
37+
>
38+
<DeleteIcon />
39+
</button>
40+
<button
41+
className="src-shared-components-SubmissionManagement-Submission-___styles__expand-icon___TDY6Y src-shared-components-SubmissionManagement-Submission-___styles__expanded___8pRX_"
42+
onClick={[Function]}
43+
>
44+
<ExpandIcon />
45+
</button>
46+
</div>
47+
</td>
48+
</tr>
49+
`;
50+
51+
exports[`Snapshot match 2`] = `
52+
<tr
53+
className="src-shared-components-SubmissionManagement-Submission-___styles__submission-row___2yQOc"
54+
>
55+
<td
56+
className="src-shared-components-SubmissionManagement-Submission-___styles__preview-col___1pWYq"
57+
>
58+
<img
59+
alt="preview"
60+
className="src-shared-components-SubmissionManagement-Submission-___styles__design-img___1klwr"
61+
src="https://studio.topcoder-dev.com?module=DownloadSubmission&sbmid=12345&sbt=tiny"
62+
/>
63+
</td>
64+
<td
65+
className="src-shared-components-SubmissionManagement-Submission-___styles__id-col___zC6Hi"
66+
>
67+
12345
68+
</td>
69+
<td />
70+
<td
71+
className="src-shared-components-SubmissionManagement-Submission-___styles__date-col___3XOxK"
72+
>
73+
Invalid date
74+
</td>
2575
<td
2676
className="src-shared-components-SubmissionManagement-Submission-___styles__status-col___1Byk3"
27-
/>
77+
>
78+
<ScreeningStatus
79+
onShowDetails={[Function]}
80+
screeningObject={Object {}}
81+
submissionId={12345}
82+
/>
83+
</td>
2884
<td>
2985
<div
3086
className="src-shared-components-SubmissionManagement-Submission-___styles__action-col___2M1RY"
3187
>
3288
<a
33-
href="https://studio.topcoder-dev.com?module=DownloadSubmission&sbmid=undefined&sbt=original"
89+
href="https://studio.topcoder-dev.com?module=DownloadSubmission&sbmid=12345&sbt=original"
3490
>
3591
<DownloadIcon />
3692
</a>
93+
<button
94+
className="src-shared-components-SubmissionManagement-Submission-___styles__delete-icon___2M67z"
95+
onClick={[Function]}
96+
>
97+
<DeleteIcon />
98+
</button>
3799
<button
38100
className="src-shared-components-SubmissionManagement-Submission-___styles__expand-icon___TDY6Y"
39101
onClick={[Function]}

0 commit comments

Comments
 (0)