File size: 2,866 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
import { DataStatus } from '../constants';
import { domainSuggestions } from '../reducer';
import type { DomainSuggestionState, DomainSuggestion } from '../types';
describe( 'domainSuggestions', () => {
const initialTimeStamp = Date.now();
const initialState: DomainSuggestionState = {
state: DataStatus.Uninitialized,
data: undefined,
errorMessage: null,
lastUpdated: initialTimeStamp,
pendingSince: undefined,
};
it( 'goes into a state of pending when fetching results', () => {
const now = Date.now();
const state = domainSuggestions( initialState, {
type: 'FETCH_DOMAIN_SUGGESTIONS',
timeStamp: now,
} );
const expectedState: DomainSuggestionState = {
state: DataStatus.Pending,
data: undefined,
errorMessage: null,
lastUpdated: initialTimeStamp,
pendingSince: now,
};
expect( state ).toEqual( expectedState );
} );
it( 'goes into a state of errored when fetching results have failed', () => {
const now = Date.now();
const errorMessage = 'An unexpected error has occured';
const state = domainSuggestions( initialState, {
type: 'RECEIVE_DOMAIN_SUGGESTIONS_ERROR',
timeStamp: now,
errorMessage,
} );
const expectedState: DomainSuggestionState = {
state: DataStatus.Failure,
data: undefined,
errorMessage: errorMessage,
lastUpdated: now,
pendingSince: undefined,
};
expect( state ).toEqual( expectedState );
} );
it( 'goes into a state of success when fetching results have returned results', () => {
const queryObject = {
include_dotblogsubdomain: false,
include_wordpressdotcom: true,
locale: 'en',
only_wordpressdotcom: false,
quantity: 11,
query: 'test site',
vendor: 'variation4_front',
};
const suggestions: DomainSuggestion[] = [
{
domain_name: 'test.site',
relevance: 1,
supports_privacy: true,
vendor: 'donuts',
match_reasons: [ 'tld-common', 'tld-exact' ],
product_id: 78,
product_slug: 'dotsite_domain',
cost: '$25.00',
raw_price: 25,
currency_code: 'USD',
},
{
domain_name: 'hot-test-site.com',
relevance: 1,
supports_privacy: true,
vendor: 'donuts',
match_reasons: [ 'tld-common' ],
product_id: 6,
product_slug: 'domain_reg',
cost: '$18.00',
raw_price: 18,
currency_code: 'USD',
},
];
const now = Date.now();
const state = domainSuggestions( initialState, {
type: 'RECEIVE_DOMAIN_SUGGESTIONS_SUCCESS',
queryObject,
suggestions,
timeStamp: now,
} );
const expectedState: DomainSuggestionState = {
state: DataStatus.Success,
data: { [ JSON.stringify( queryObject ) ]: suggestions },
errorMessage: null,
lastUpdated: now,
pendingSince: undefined,
};
expect( state ).toEqual( expectedState );
expect( state.data[ JSON.stringify( queryObject ) ].length ).toEqual( suggestions.length );
} );
} );
|