homeflowjs 0.10.17 → 0.10.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__tests__/instant-valuation.test.jsx +12 -1
- package/instant-valuation/instant-valuation/instant-valuation.component.jsx +11 -2
- package/instant-valuation/result-step/result-step.component.jsx +18 -17
- package/instant-valuation/similar-properties-step/similar-properties-step.component.jsx +2 -1
- package/package.json +1 -1
@@ -3,11 +3,14 @@
|
|
3
3
|
import React from 'react';
|
4
4
|
import { Router } from 'react-router-dom';
|
5
5
|
import { createHashHistory } from 'history';
|
6
|
-
import {
|
6
|
+
import {
|
7
|
+
render, screen, fireEvent, waitFor,
|
8
|
+
} from '@testing-library/react';
|
7
9
|
import { rest } from 'msw';
|
8
10
|
import { setupServer } from 'msw/node';
|
9
11
|
|
10
12
|
import InstantValuation from 'instant-valuation/instant-valuation/instant-valuation.component';
|
13
|
+
import ResultStep from '../instant-valuation/result-step/result-step.component';
|
11
14
|
|
12
15
|
const server = setupServer(
|
13
16
|
rest.get('/address_lookup', (req, res, ctx) => (
|
@@ -65,3 +68,11 @@ describe('Instant Valuation', () => {
|
|
65
68
|
expect(message).toBeInTheDocument();
|
66
69
|
});
|
67
70
|
});
|
71
|
+
|
72
|
+
describe('Instant Valuation Results', () => {
|
73
|
+
it('renders error message if it can\'t provide an accurate valuation', () => {
|
74
|
+
render(<ResultStep valuation={{ price: null }} getValuation={jest.fn} />);
|
75
|
+
const errorMessage = screen.getByTestId('valuation-error');
|
76
|
+
expect(errorMessage).toBeInTheDocument();
|
77
|
+
});
|
78
|
+
});
|
@@ -15,6 +15,7 @@ import './instant-valuation.styles.scss';
|
|
15
15
|
|
16
16
|
const INITIAL_STATE = {
|
17
17
|
step: 1,
|
18
|
+
loading: false,
|
18
19
|
addresses: [],
|
19
20
|
message: null,
|
20
21
|
similarProperties: [],
|
@@ -91,10 +92,11 @@ class InstantValuation extends Component {
|
|
91
92
|
}
|
92
93
|
|
93
94
|
getSimilarProperties() {
|
95
|
+
this.setState({ loading: true });
|
94
96
|
const { search } = this.state;
|
95
97
|
fetch(`/properties/similar_properties?bedrooms=${search.bedrooms}&postcode=${search.postcode}&channel=sales`)
|
96
98
|
.then((response) => response.json())
|
97
|
-
.then((json) => this.setState({ similarProperties: json }));
|
99
|
+
.then((json) => this.setState({ similarProperties: json, loading: false }));
|
98
100
|
}
|
99
101
|
|
100
102
|
getRecentSales() {
|
@@ -108,6 +110,7 @@ class InstantValuation extends Component {
|
|
108
110
|
}
|
109
111
|
|
110
112
|
getValuation() {
|
113
|
+
this.setState({ loading: true });
|
111
114
|
const { search, lead } = this.state;
|
112
115
|
const { properties, ...restOfSearch } = search;
|
113
116
|
|
@@ -144,7 +147,11 @@ class InstantValuation extends Component {
|
|
144
147
|
.then((json) => {
|
145
148
|
this.getRecentSales()
|
146
149
|
.then((recentSalesJson) => {
|
147
|
-
this.setState({
|
150
|
+
this.setState({
|
151
|
+
valuation: json,
|
152
|
+
recentSales: recentSalesJson.recent_sales,
|
153
|
+
loading: false,
|
154
|
+
});
|
148
155
|
|
149
156
|
const event = new CustomEvent('formSubmission', {
|
150
157
|
detail: {
|
@@ -247,6 +254,7 @@ class InstantValuation extends Component {
|
|
247
254
|
similarProperties,
|
248
255
|
valuation,
|
249
256
|
recentSales,
|
257
|
+
loading,
|
250
258
|
} = this.state;
|
251
259
|
|
252
260
|
const StepComponent = stepComponents[step];
|
@@ -290,6 +298,7 @@ class InstantValuation extends Component {
|
|
290
298
|
recentSales={recentSales}
|
291
299
|
reset={this.reset}
|
292
300
|
setMessage={this.setMessage}
|
301
|
+
loading={loading}
|
293
302
|
/>}
|
294
303
|
</div>
|
295
304
|
</div>
|
@@ -15,6 +15,7 @@ const ResultStep = ({
|
|
15
15
|
valuation,
|
16
16
|
recentSales,
|
17
17
|
reset,
|
18
|
+
loading,
|
18
19
|
}) => {
|
19
20
|
const [selectedChannel, setSelectedChannel] = useState('sales');
|
20
21
|
|
@@ -26,6 +27,23 @@ const ResultStep = ({
|
|
26
27
|
if (valuation) Homeflow.kickEvent('valuation_successful');
|
27
28
|
}, [valuation])
|
28
29
|
|
30
|
+
if (!valuation || loading) return <Loader className="hfjs-instant-val__loader" />;
|
31
|
+
|
32
|
+
if (!valuation.price) {
|
33
|
+
return (
|
34
|
+
<div data-testid="valuation-error" id="no_results">
|
35
|
+
<p>
|
36
|
+
Unfortunately we do not have enough data to give you an accurate valuation. Your local
|
37
|
+
{' '}
|
38
|
+
{companyName}
|
39
|
+
{' '}
|
40
|
+
property expert will be in touch to arrange an accurate valuation taking
|
41
|
+
into account improvements to your property, the local market and more.
|
42
|
+
</p>
|
43
|
+
</div>
|
44
|
+
);
|
45
|
+
}
|
46
|
+
|
29
47
|
const formatPrice = (price) => (
|
30
48
|
`£${Math.round(price)}${selectedChannel === 'lettings' ? '/month' : ''}`
|
31
49
|
.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1,')
|
@@ -66,25 +84,8 @@ const ResultStep = ({
|
|
66
84
|
const companyName = Homeflow.get('company_name');
|
67
85
|
const gmapsKey = Homeflow.get('theme_preferences').google_maps_api_key;
|
68
86
|
|
69
|
-
if (!valuation) return <Loader className="hfjs-instant-val__loader" />;
|
70
|
-
|
71
87
|
const streetviewQuery = `size=900x900&location=${lead.full_address},${search.postcode}&key=${gmapsKey}`;
|
72
88
|
|
73
|
-
if (valuation.price === 0) {
|
74
|
-
return (
|
75
|
-
<div id="no_results">
|
76
|
-
<p>
|
77
|
-
Unfortunately we do not have enough data to give you an accurate valuation. Your local
|
78
|
-
{' '}
|
79
|
-
{companyName}
|
80
|
-
{' '}
|
81
|
-
property expert will be in touch to arrange an accurate valuation taking
|
82
|
-
into account improvements to your property, the local market and more.
|
83
|
-
</p>
|
84
|
-
</div>
|
85
|
-
);
|
86
|
-
}
|
87
|
-
|
88
89
|
return (
|
89
90
|
<div className="result-container">
|
90
91
|
<div className="inner-wrapper">
|
@@ -11,6 +11,7 @@ const SimilarPropertiesStep = ({
|
|
11
11
|
getSimilarProperties,
|
12
12
|
toggleSimilarProperty,
|
13
13
|
reset,
|
14
|
+
loading,
|
14
15
|
}) => {
|
15
16
|
useEffect(() => {
|
16
17
|
getSimilarProperties();
|
@@ -24,7 +25,7 @@ const SimilarPropertiesStep = ({
|
|
24
25
|
|
25
26
|
const { properties: selectedProperties } = search;
|
26
27
|
|
27
|
-
if (!similarProperties.length) return <Loader className="hfjs-instant-val__loader" />;
|
28
|
+
if (!similarProperties.length || loading) return <Loader className="hfjs-instant-val__loader" />;
|
28
29
|
|
29
30
|
return (
|
30
31
|
<form id="similar-properties-form" onSubmit={handleSubmit}>
|