homeflowjs 0.10.17 → 0.10.18

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.
@@ -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 { render, screen, fireEvent, waitFor } from '@testing-library/react';
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 }} />);
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({ valuation: json, recentSales: recentSalesJson.recent_sales });
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,7 +15,23 @@ const ResultStep = ({
15
15
  valuation,
16
16
  recentSales,
17
17
  reset,
18
+ loading,
18
19
  }) => {
20
+ if (!valuation.price) {
21
+ return (
22
+ <div data-testid="valuation-error" id="no_results">
23
+ <p>
24
+ Unfortunately we do not have enough data to give you an accurate valuation. Your local
25
+ {' '}
26
+ {companyName}
27
+ {' '}
28
+ property expert will be in touch to arrange an accurate valuation taking
29
+ into account improvements to your property, the local market and more.
30
+ </p>
31
+ </div>
32
+ );
33
+ }
34
+
19
35
  const [selectedChannel, setSelectedChannel] = useState('sales');
20
36
 
21
37
  useEffect(() => {
@@ -66,24 +82,10 @@ const ResultStep = ({
66
82
  const companyName = Homeflow.get('company_name');
67
83
  const gmapsKey = Homeflow.get('theme_preferences').google_maps_api_key;
68
84
 
69
- if (!valuation) return <Loader className="hfjs-instant-val__loader" />;
85
+ if (!valuation || loading) return <Loader className="hfjs-instant-val__loader" />;
70
86
 
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
89
 
88
90
  return (
89
91
  <div className="result-container">
@@ -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}>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homeflowjs",
3
- "version": "0.10.17",
3
+ "version": "0.10.18",
4
4
  "description": "JavaScript toolkit for Homeflow themes",
5
5
  "main": "index.js",
6
6
  "scripts": {