refactor: normalize company size
This commit is contained in:
@@ -4,14 +4,3 @@ export const findMatchingOption = (value, options, defaultValue) => {
|
||||
);
|
||||
return match ? match.value || match : defaultValue;
|
||||
};
|
||||
|
||||
export const findCompanySizeMatch = (options, size) => {
|
||||
if (!size) return undefined;
|
||||
if (Number.isNaN(size)) return undefined;
|
||||
return (
|
||||
options.find(option => {
|
||||
const upperLimit = option.value.split('-')[1]?.split('+')[0];
|
||||
return size < (upperLimit ? Number(upperLimit) : Infinity);
|
||||
})?.value || options[0].value
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { findMatchingOption, findCompanySizeMatch } from '../OnboardingHelper';
|
||||
import { findMatchingOption } from '../OnboardingHelper';
|
||||
|
||||
describe('findMatchingOption', () => {
|
||||
const options = [{ value: 'option1' }, { value: 'option2' }];
|
||||
@@ -13,28 +13,3 @@ describe('findMatchingOption', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('findCompanySizeMatch', () => {
|
||||
const mockCompanySizeOptions = [
|
||||
{ value: '1-10' },
|
||||
{ value: '11-50' },
|
||||
{ value: '51-500' },
|
||||
{ value: '501-1000' },
|
||||
{ value: '1001+' },
|
||||
];
|
||||
|
||||
it('should return the correct company size range', () => {
|
||||
const size = 25;
|
||||
expect(findCompanySizeMatch(mockCompanySizeOptions, size)).toBe('11-50');
|
||||
});
|
||||
|
||||
it('should return the last company size range when limit exceeds', () => {
|
||||
const size = 1500;
|
||||
expect(findCompanySizeMatch(mockCompanySizeOptions, size)).toBe('1001+');
|
||||
});
|
||||
|
||||
it('should return the undefined when no match is found', () => {
|
||||
const size = undefined;
|
||||
expect(findCompanySizeMatch(mockCompanySizeOptions, size)).toBe(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -94,10 +94,7 @@ import { ONBOARDING_STEP_NAMES } from 'dashboard/constants/globals';
|
||||
import SubmitButton from 'dashboard/components/buttons/FormSubmitButton.vue';
|
||||
import { timeZoneOptions } from 'dashboard/routes/dashboard/settings/inbox/helpers/businessHour.js';
|
||||
import { getBrowserTimezone, getBrowserLocale } from 'v3/helpers/BrowserHelper';
|
||||
import {
|
||||
findMatchingOption,
|
||||
findCompanySizeMatch,
|
||||
} from 'v3/helpers/OnboardingHelper';
|
||||
import { findMatchingOption } from 'v3/helpers/OnboardingHelper';
|
||||
import alertMixin from 'shared/mixins/alertMixin';
|
||||
import configMixin from 'shared/mixins/configMixin';
|
||||
export default {
|
||||
@@ -118,8 +115,8 @@ export default {
|
||||
companySizeOptions: [
|
||||
{ value: '1-10', label: '1-10' },
|
||||
{ value: '11-50', label: '11-50' },
|
||||
{ value: '51-500', label: '51-500' },
|
||||
{ value: '501-1000', label: '501-1000' },
|
||||
{ value: '51-250', label: '51-250' },
|
||||
{ value: '251-1000', label: '251-1000' },
|
||||
{ value: '1001+', label: 'Over 1000' },
|
||||
],
|
||||
industryOptions: [
|
||||
@@ -235,10 +232,7 @@ export default {
|
||||
this.industryOptions,
|
||||
'other'
|
||||
);
|
||||
this.companySize = findCompanySizeMatch(
|
||||
this.companySizeOptions,
|
||||
companySize
|
||||
);
|
||||
this.companySize = companySize;
|
||||
this.timezone = findMatchingOption(
|
||||
timezone,
|
||||
this.timeZones.map(zone => zone.value),
|
||||
|
||||
Reference in New Issue
Block a user