Skip to content

Commit 4b54951

Browse files
authored
Merge pull request #104 from oslabs-beta/AS/CbReactTesting
As/cb react testing
2 parents 906f95e + 39730ee commit 4b54951

File tree

6 files changed

+100
-40
lines changed

6 files changed

+100
-40
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import React from 'React';
2+
import { Provider } from 'react-redux';
3+
import { render, screen } from '@testing-library/react';
4+
import configureStore from 'redux-mock-store';
5+
import '@testing-library/jest-dom';
6+
import { Clipboard } from '../../client/components/Clipboard';
7+
import { BrowserRouter } from 'react-router-dom';
8+
9+
const initialState = {
10+
clipboard:{
11+
server: '',
12+
},
13+
userInfo: {
14+
projectsInfo: [],
15+
}
16+
};
17+
18+
const mockStore = configureStore();
19+
20+
const board = () => {
21+
render(
22+
<Provider store={mockStore(initialState)}>
23+
<BrowserRouter>
24+
<Clipboard />
25+
</BrowserRouter>
26+
</Provider>
27+
);
28+
};
29+
30+
describe('Unit testing Clipboard component', () => {
31+
beforeEach(() => {
32+
board();
33+
});
34+
35+
test(`Renders a Clipboard with the classname of ${'code-container'}`, () => {
36+
expect(screen.getByTestId('code-container')).toBeInTheDocument();
37+
});
38+
test(`Renders the delete button with the classname of ${'delete'}` , () => {
39+
expect(screen.getByRole('button', { name:'Clear Clipboard' })).toBeInTheDocument();
40+
});
41+
test(`Renders the copy button with a class name of ${'clipboard-button-container'}`, () => {
42+
expect(screen.getByTestId('bttn-copy')).toBeInTheDocument();
43+
});
44+
test(`Renders the server url textbox with a label of ${'Server URL'}`, () => {
45+
expect(screen.getByRole('textbox', { name:'Server URL' })).toBeInTheDocument();
46+
});
47+
});

client/components/Clipboard.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,15 @@ export const Clipboard = () => {
7171
return (
7272
<div className="page-body">
7373
<Box
74-
sx={{
74+
sx={{
7575
display: 'flex',
7676
flexDirection: 'column',
7777
alignItems: 'center',
7878
gap: '30px',
7979
width: .8,
8080
}}
81+
className='code-container'
82+
data-testid='code-container'
8183
>
8284
<Typography variant="h3" align="center" gutterBottom sx={{ color: '#6E00BB', mb: 0, mt: 5 }}>{projectName}</Typography>
8385
<TextField
@@ -112,6 +114,7 @@ export const Clipboard = () => {
112114
<Button
113115
onClick={handleClear}
114116
sx={{ flexDirection: 'column' }}
117+
className='delete'
115118
>
116119
<DeleteForeverIcon />
117120
{buttonText}

dist/dist/bundle.js

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/dist/bundle.js.LICENSE.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/*! js-cookie v3.0.1 | MIT */
22

3+
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
4+
35
/**
46
* @license React
57
* react-dom.production.min.js

package-lock.json

Lines changed: 41 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@
9191
"file-loader": "^6.2.0",
9292
"highlight.js": "^11.6.0",
9393
"js-cookie": "^3.0.1",
94-
"node-fetch": "2.6.7",
9594
"passport": "^0.5.0",
9695
"passport-github2": "^0.1.12",
9796
"pg": "^8.8.0",

0 commit comments

Comments
 (0)