Skip to content

Commit d08c6e1

Browse files
committed
strategy test
1 parent f4c19c6 commit d08c6e1

File tree

8 files changed

+3575
-790
lines changed

8 files changed

+3575
-790
lines changed

package-lock.json

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

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@
88
"@testing-library/user-event": "^13.5.0",
99
"react": "^18.2.0",
1010
"react-dom": "^18.2.0",
11-
"react-scripts": "5.0.1",
1211
"web-vitals": "^2.1.4"
1312
},
13+
"devDependencies": {
14+
"autoprefixer": "^10.4.7",
15+
"postcss": "^8.4.14",
16+
"react-scripts": "5.0.1",
17+
"tailwindcss": "^3.1.4"
18+
},
1419
"scripts": {
1520
"start": "react-scripts start",
1621
"build": "react-scripts build",

src/App.js

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
1-
import logo from './logo.svg';
1+
22
import './App.css';
3+
import React, {Component} from 'react';
4+
import { Strategy, changeRed } from '../src/components/Strategy/Strategy.js'
5+
6+
7+
38

4-
function App() {
5-
return (
6-
<div className="App">
7-
<header className="App-header">
8-
<img src={logo} className="App-logo" alt="logo" />
9-
<p>
10-
Edit <code>src/App.js</code> and save to reload.
11-
</p>
12-
<a
13-
className="App-link"
14-
href="https://reactjs.org"
15-
target="_blank"
16-
rel="noopener noreferrer"
17-
>
18-
Learn React
19-
</a>
20-
</header>
21-
</div>
22-
);
9+
class App extends Component {
10+
11+
constructor(props) {
12+
super(props);
13+
this.changeRed = new changeRed();
14+
this.Strategy = new Strategy().setStrategy = this.changeRed;
15+
}
16+
17+
render() {
18+
return (
19+
<>
20+
<div className="h-72 w-72 bg-blue-500" id="bar" onClick={this.Strategy.perform}></div>
21+
</>
22+
)
23+
}
2324
}
2425

26+
2527
export default App;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React, {Component} from 'react';
2+
3+
class Strategy {
4+
constructor() {
5+
this._strategy = null;
6+
}
7+
8+
/**
9+
* @param {changeRed} strategy
10+
*/
11+
set setStrategy(strategy) {
12+
this._strategy = strategy;
13+
}
14+
15+
get getStrategy() {
16+
return this._strategy;
17+
}
18+
19+
perform() {
20+
this._strategy.perform();
21+
}
22+
}
23+
24+
// SG 07/06/2022 19:11 strategy pattern test
25+
class changeRed {
26+
perform() {
27+
document.getElementById("bar").style.backgroundColor = "red";
28+
}
29+
}
30+
31+
export { Strategy, changeRed }

src/index.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
@tailwind base;
2+
@tailwind components;
3+
@tailwind utilities;
4+
5+
6+
17
body {
28
margin: 0;
39
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',

src/index.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,4 @@ root.render(
1111
</React.StrictMode>
1212
);
1313

14-
// If you want to start measuring performance in your app, pass a function
15-
// to log results (for example: reportWebVitals(console.log))
16-
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
1714
reportWebVitals();

src/setupTests.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
// jest-dom adds custom jest matchers for asserting on DOM nodes.
2-
// allows you to do things like:
3-
// expect(element).toHaveTextContent(/react/i)
4-
// learn more: https://github.com/testing-library/jest-dom
51
import '@testing-library/jest-dom';

tailwind.config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
content: [
3+
"./src/**/*.{js,jsx,ts,tsx}",
4+
],
5+
theme: {
6+
extend: {},
7+
},
8+
plugins: [],
9+
}

0 commit comments

Comments
 (0)