BAEL-4842 - Use React and Spring Boot to Build a Simple CRUD App
Updating PR to reduce complexity of react components Fixing react test
This commit is contained in:
parent
14bf673677
commit
45dcdf2a0d
|
@ -3,6 +3,6 @@ import App from './App';
|
||||||
|
|
||||||
test('renders learn react link', () => {
|
test('renders learn react link', () => {
|
||||||
render(<App />);
|
render(<App />);
|
||||||
const linkElement = screen.getByText(/learn react/i);
|
const linkElement = screen.getByText(/Clients/i);
|
||||||
expect(linkElement).toBeInTheDocument();
|
expect(linkElement).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
|
@ -35,20 +35,20 @@ class ClientEdit extends Component {
|
||||||
this.setState({item});
|
this.setState({item});
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleSubmit(event) {
|
async handleSubmit(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const {item} = this.state;
|
const {item} = this.state;
|
||||||
|
|
||||||
await fetch('/clients' + (item.id ? '/' + item.id : ''), {
|
await fetch('/clients' + (item.id ? '/' + item.id : ''), {
|
||||||
method: (item.id) ? 'PUT' : 'POST',
|
method: (item.id) ? 'PUT' : 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
body: JSON.stringify(item),
|
body: JSON.stringify(item),
|
||||||
});
|
});
|
||||||
this.props.history.push('/clients');
|
this.props.history.push('/clients');
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {item} = this.state;
|
const {item} = this.state;
|
||||||
|
|
|
@ -7,16 +7,14 @@ class ClientList extends Component {
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {clients: [], isLoading: true};
|
this.state = {clients: []};
|
||||||
this.remove = this.remove.bind(this);
|
this.remove = this.remove.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.setState({isLoading: true});
|
|
||||||
|
|
||||||
fetch('/clients')
|
fetch('/clients')
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => this.setState({clients: data, isLoading: false}));
|
.then(data => this.setState({clients: data}));
|
||||||
}
|
}
|
||||||
|
|
||||||
async remove(id) {
|
async remove(id) {
|
||||||
|
@ -33,11 +31,7 @@ class ClientList extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {clients, isLoading} = this.state;
|
const {clients} = this.state;
|
||||||
|
|
||||||
if (isLoading) {
|
|
||||||
return <p>Loading...</p>;
|
|
||||||
}
|
|
||||||
|
|
||||||
const clientList = clients.map(client => {
|
const clientList = clients.map(client => {
|
||||||
return <tr key={client.id}>
|
return <tr key={client.id}>
|
||||||
|
|
|
@ -25,16 +25,19 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
<version>2.4.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||||
|
<version>2.4.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.h2database</groupId>
|
<groupId>com.h2database</groupId>
|
||||||
<artifactId>h2</artifactId>
|
<artifactId>h2</artifactId>
|
||||||
|
<version>1.4.200</version>
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
@ -47,6 +50,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<version>2.4.3</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
@ -55,6 +59,7 @@
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-resources-plugin</artifactId>
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
|
<version>3.1.0</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>copy-resources</id>
|
<id>copy-resources</id>
|
||||||
|
|
Loading…
Reference in New Issue