A lead can carry the same honorific as a person, and a form that asks gender writes it onto the lead. Co-authored-by: Cursor <cursoragent@cursor.com>
143 lines
5.6 KiB
TypeScript
143 lines
5.6 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import { describe, it } from 'node:test';
|
|
import {
|
|
applyLeadGenderName,
|
|
applyPersonGenderTitle,
|
|
isGenderQuestionLabel,
|
|
parsePersonGenderAnswer,
|
|
splitPersonHonorific,
|
|
} from '@mento/shared';
|
|
|
|
describe('عنوان جنسیت در نام شخص', () => {
|
|
it('ی عربی جناب آقای را مرد میخواند و عنوان معیار را میگذارد', () => {
|
|
const named = applyPersonGenderTitle({
|
|
firstName: 'جناب آقاي آرش انتظاري',
|
|
lastName: '',
|
|
});
|
|
assert.equal(named.gender, 'male');
|
|
assert.equal(named.showGenderInName, true);
|
|
assert.equal(`${named.firstName} ${named.lastName}`, 'جناب آقای آرش انتظاری');
|
|
});
|
|
|
|
it('سرکار خانم را زن میخواند، با فاصله و بیفاصله', () => {
|
|
const spaced = applyPersonGenderTitle({
|
|
firstName: 'سرکار خانم آبيدا',
|
|
lastName: 'افرندنژاد تهران',
|
|
});
|
|
assert.equal(spaced.gender, 'female');
|
|
assert.equal(spaced.showGenderInName, true);
|
|
assert.equal(`${spaced.firstName} ${spaced.lastName}`, 'سرکار خانم آبیدا افرندنژاد تهران');
|
|
|
|
const tight = applyPersonGenderTitle({
|
|
firstName: 'سرکارخانم مریم رضایی',
|
|
lastName: '',
|
|
});
|
|
assert.equal(tight.gender, 'female');
|
|
assert.equal(`${tight.firstName} ${tight.lastName}`, 'سرکار خانم مریم رضایی');
|
|
});
|
|
|
|
it('بدون عنوان، هیچکدام میماند و چیزی اضافه نمیکند', () => {
|
|
const shop = applyPersonGenderTitle({ firstName: 'فروشگاه', lastName: 'الماس' });
|
|
assert.equal(shop.gender, 'none');
|
|
assert.equal(shop.showGenderInName, false);
|
|
assert.equal(shop.firstName, 'فروشگاه');
|
|
assert.equal(shop.lastName, 'الماس');
|
|
});
|
|
|
|
it('تیک خاموش جنسیت را نگه میدارد ولی عنوان را برمیدارد', () => {
|
|
const hidden = applyPersonGenderTitle({
|
|
firstName: 'جناب آقای آرش',
|
|
lastName: 'انتظاری',
|
|
gender: 'male',
|
|
showGenderInName: false,
|
|
});
|
|
assert.equal(hidden.gender, 'male');
|
|
assert.equal(hidden.showGenderInName, false);
|
|
assert.equal(`${hidden.firstName} ${hidden.lastName}`, 'آرش انتظاری');
|
|
});
|
|
|
|
it('هیچکدام عنوان را برمیدارد حتی اگر تیک روشن باشد', () => {
|
|
const cleared = applyPersonGenderTitle({
|
|
firstName: 'جناب آقای آرش',
|
|
lastName: 'انتظاری',
|
|
gender: 'none',
|
|
showGenderInName: true,
|
|
});
|
|
assert.equal(cleared.gender, 'none');
|
|
assert.equal(cleared.showGenderInName, false);
|
|
assert.equal(`${cleared.firstName} ${cleared.lastName}`, 'آرش انتظاری');
|
|
});
|
|
|
|
it('عنوان را فقط یک بار میگذارد', () => {
|
|
const once = applyPersonGenderTitle({
|
|
firstName: 'آرش',
|
|
lastName: 'انتظاری',
|
|
gender: 'male',
|
|
showGenderInName: true,
|
|
});
|
|
assert.equal(`${once.firstName} ${once.lastName}`, 'جناب آقای آرش انتظاری');
|
|
|
|
const again = applyPersonGenderTitle({
|
|
firstName: once.firstName,
|
|
lastName: once.lastName,
|
|
gender: 'male',
|
|
showGenderInName: true,
|
|
});
|
|
assert.equal(`${again.firstName} ${again.lastName}`, 'جناب آقای آرش انتظاری');
|
|
});
|
|
|
|
it('ویرایش بخشی از نام، آقای را دوباره به ته نام نمیچسباند', () => {
|
|
const existing = applyPersonGenderTitle({
|
|
firstName: 'آرش',
|
|
lastName: 'انتظاری',
|
|
gender: 'male',
|
|
showGenderInName: true,
|
|
});
|
|
const bare = splitPersonHonorific(existing.firstName, existing.lastName);
|
|
const next = applyPersonGenderTitle({
|
|
firstName: 'محمد',
|
|
lastName: bare.lastName,
|
|
gender: 'male',
|
|
showGenderInName: true,
|
|
});
|
|
assert.equal(bare.firstName, 'آرش');
|
|
assert.equal(bare.lastName, 'انتظاری');
|
|
assert.equal(`${next.firstName} ${next.lastName}`, 'جناب آقای محمد انتظاری');
|
|
});
|
|
});
|
|
|
|
describe('جنسیت لید و پاسخ فرم', () => {
|
|
it('عنوان را روی نام مخاطب میگذارد و عنوان لید را دست نمیزند', () => {
|
|
const named = applyLeadGenderName({
|
|
title: 'فروشگاه الماس',
|
|
contactName: 'مریم رضایی',
|
|
gender: 'female',
|
|
showGenderInName: true,
|
|
});
|
|
assert.equal(named.title, 'فروشگاه الماس');
|
|
assert.equal(named.contactName, 'سرکار خانم مریم رضایی');
|
|
assert.equal(named.gender, 'female');
|
|
assert.equal(named.showGenderInName, true);
|
|
});
|
|
|
|
it('اگر نام مخاطب خالی باشد عنوان لید پیشوند میگیرد', () => {
|
|
const named = applyLeadGenderName({
|
|
title: 'آرش انتظاری',
|
|
contactName: ' ',
|
|
gender: 'male',
|
|
showGenderInName: true,
|
|
});
|
|
assert.equal(named.title, 'جناب آقای آرش انتظاری');
|
|
assert.equal(named.contactName, null);
|
|
});
|
|
|
|
it('پاسخ فرم مرد و زن و هیچکدام را میخواند و برچسب جنسیت را میشناسد', () => {
|
|
assert.equal(parsePersonGenderAnswer('مرد'), 'male');
|
|
assert.equal(parsePersonGenderAnswer('خانم'), 'female');
|
|
assert.equal(parsePersonGenderAnswer('هیچکدام'), 'none');
|
|
assert.equal(parsePersonGenderAnswer('نمیدانم'), null);
|
|
assert.equal(isGenderQuestionLabel('جنسیت شما'), true);
|
|
assert.equal(isGenderQuestionLabel('نام'), false);
|
|
});
|
|
});
|