@procraft/widget-order 2.32.1 → 2.33.0

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.
Files changed (124) hide show
  1. package/dist/CourseItem/AltItem/index.js +3 -3
  2. package/dist/CourseItem/AltItem/index.js.map +1 -1
  3. package/dist/CourseItem/AltItemText/index.js +1 -1
  4. package/dist/CourseItem/AltItemText/index.js.map +1 -1
  5. package/dist/CourseItem/FieldValues/index.js +6 -6
  6. package/dist/CourseItem/FieldValues/index.js.map +1 -1
  7. package/dist/CourseItem/FieldValuesByType/index.js +2 -2
  8. package/dist/CourseItem/FieldValuesByType/index.js.map +1 -1
  9. package/dist/CourseItem/Materials/index.js +5 -5
  10. package/dist/CourseItem/Materials/index.js.map +1 -1
  11. package/dist/CourseItem/Materials/styles.js +1 -1
  12. package/dist/CourseItem/Materials/styles.js.map +1 -1
  13. package/dist/CourseItem/OrderButton/index.js +24 -20
  14. package/dist/CourseItem/OrderButton/index.js.map +1 -1
  15. package/dist/CourseItem/OrderButton/interfaces.d.ts +1 -0
  16. package/dist/CourseItem/OrderButton/styles.js +1 -1
  17. package/dist/CourseItem/OrderButton/styles.js.map +1 -1
  18. package/dist/CourseItem/PlacesLeft/index.js +1 -1
  19. package/dist/CourseItem/PlacesLeft/index.js.map +1 -1
  20. package/dist/CourseItem/Reviews/ReviewsPopup/Filters/index.js +7 -7
  21. package/dist/CourseItem/Reviews/ReviewsPopup/Filters/index.js.map +1 -1
  22. package/dist/CourseItem/Reviews/ReviewsPopup/ProgressBar/index.js +1 -1
  23. package/dist/CourseItem/Reviews/ReviewsPopup/ProgressBar/index.js.map +1 -1
  24. package/dist/CourseItem/Reviews/ReviewsPopup/Review/index.js +1 -1
  25. package/dist/CourseItem/Reviews/ReviewsPopup/Review/index.js.map +1 -1
  26. package/dist/CourseItem/Reviews/ReviewsPopup/Stats/index.js +6 -6
  27. package/dist/CourseItem/Reviews/ReviewsPopup/Stats/index.js.map +1 -1
  28. package/dist/CourseItem/Reviews/ReviewsPopup/index.js +10 -10
  29. package/dist/CourseItem/Reviews/ReviewsPopup/index.js.map +1 -1
  30. package/dist/CourseItem/Reviews/Stars/index.js +1 -1
  31. package/dist/CourseItem/Reviews/Stars/index.js.map +1 -1
  32. package/dist/CourseItem/Reviews/index.js +5 -5
  33. package/dist/CourseItem/Reviews/index.js.map +1 -1
  34. package/dist/CourseItem/Sales/Sale/index.js +24 -13
  35. package/dist/CourseItem/Sales/Sale/index.js.map +1 -1
  36. package/dist/CourseItem/Sales/index.js +1 -1
  37. package/dist/CourseItem/Sales/index.js.map +1 -1
  38. package/dist/CourseItem/Subscriptions/index.js +3 -3
  39. package/dist/CourseItem/Subscriptions/index.js.map +1 -1
  40. package/dist/CourseItem/Subscriptions/styles.js +1 -1
  41. package/dist/CourseItem/Subscriptions/styles.js.map +1 -1
  42. package/dist/CourseItem/index.js +12 -11
  43. package/dist/CourseItem/index.js.map +1 -1
  44. package/dist/components/DateFormat/index.js +1 -1
  45. package/dist/components/DateFormat/index.js.map +1 -1
  46. package/dist/components/OldPrice/index.js +19 -2
  47. package/dist/components/OldPrice/index.js.map +1 -1
  48. package/dist/components/OldPrice/interfaces.d.ts +7 -0
  49. package/dist/components/OldPrice/styles.d.ts +8 -0
  50. package/dist/components/OldPrice/styles.js +15 -2
  51. package/dist/components/OldPrice/styles.js.map +1 -1
  52. package/dist/components/ProlongationWidget/index.js +26 -16
  53. package/dist/components/ProlongationWidget/index.js.map +1 -1
  54. package/dist/components/ProlongationWidget/styles.js +1 -1
  55. package/dist/components/ProlongationWidget/styles.js.map +1 -1
  56. package/dist/components/RadioGroup/index.js +3 -3
  57. package/dist/components/RadioGroup/index.js.map +1 -1
  58. package/dist/components/RadioGroup/styles.js +1 -1
  59. package/dist/components/RadioGroup/styles.js.map +1 -1
  60. package/dist/components/Tabs/index.js +2 -2
  61. package/dist/components/Tabs/index.js.map +1 -1
  62. package/dist/components/Tabs/styles.js +1 -1
  63. package/dist/components/Tabs/styles.js.map +1 -1
  64. package/dist/components/Typography/index.js +1 -1
  65. package/dist/components/Typography/index.js.map +1 -1
  66. package/dist/components/Typography/styles.js +2 -2
  67. package/dist/components/Typography/styles.js.map +1 -1
  68. package/dist/helpers/getCatalogItems/index.js +1 -1
  69. package/dist/helpers/getCatalogItems/index.js.map +1 -1
  70. package/dist/hooks/useCatalogItemSubscription/index.js +3 -3
  71. package/dist/hooks/useCatalogItemSubscription/index.js.map +1 -1
  72. package/dist/hooks/useOrderLink/index.d.ts +1 -1
  73. package/dist/hooks/useOrderLink/index.js +17 -5
  74. package/dist/hooks/useOrderLink/index.js.map +1 -1
  75. package/dist/hooks/useOrderLink/interfaces.d.ts +1 -0
  76. package/dist/hooks/usePrices/index.js +1 -1
  77. package/dist/hooks/usePrices/index.js.map +1 -1
  78. package/dist/index.js +4 -4
  79. package/dist/index.js.map +1 -1
  80. package/dist/interfaces/index.d.ts +15 -0
  81. package/dist/models/Course.js +4 -4
  82. package/dist/models/Course.js.map +1 -1
  83. package/dist/modules/gql/cli/generateTypes/generateTypes.js +2 -2
  84. package/dist/modules/gql/cli/generateTypes/generateTypes.js.map +1 -1
  85. package/dist/modules/gql/cli/generateTypes/run.js +1 -1
  86. package/dist/modules/gql/cli/generateTypes/run.js.map +1 -1
  87. package/dist/modules/gql/cli/generateTypes/types.js +7 -7
  88. package/dist/modules/gql/cli/generateTypes/types.js.map +1 -1
  89. package/dist/modules/gql/generated/helpers/apollo-helpers.d.ts +88 -12
  90. package/dist/modules/gql/generated/types.d.ts +77 -1
  91. package/dist/modules/gql/generated/types.js +2 -0
  92. package/dist/modules/gql/generated/types.js.map +1 -1
  93. package/dist/money/SecondaryPrices.d.ts +26 -0
  94. package/dist/money/SecondaryPrices.js +58 -0
  95. package/dist/money/SecondaryPrices.js.map +1 -0
  96. package/dist/money/convert.d.ts +37 -0
  97. package/dist/money/convert.js +114 -0
  98. package/dist/money/convert.js.map +1 -0
  99. package/dist/styles/GlobalStyle/index.js +1 -1
  100. package/dist/styles/GlobalStyle/index.js.map +1 -1
  101. package/dist/tsconfig.build.tsbuildinfo +1 -1
  102. package/dist/utils.js +5 -5
  103. package/dist/utils.js.map +1 -1
  104. package/package.json +1 -1
  105. package/src/CourseItem/OrderButton/index.tsx +12 -0
  106. package/src/CourseItem/OrderButton/interfaces.ts +1 -0
  107. package/src/CourseItem/Sales/Sale/index.tsx +35 -6
  108. package/src/CourseItem/index.tsx +3 -0
  109. package/src/components/OldPrice/index.tsx +40 -2
  110. package/src/components/OldPrice/interfaces.ts +8 -0
  111. package/src/components/OldPrice/styles.ts +15 -0
  112. package/src/components/ProlongationWidget/__tests__/ProlongationWidget.test.tsx +101 -0
  113. package/src/components/ProlongationWidget/index.tsx +29 -34
  114. package/src/hooks/useOrderLink/index.tsx +14 -1
  115. package/src/hooks/useOrderLink/interfaces.ts +1 -0
  116. package/src/index.tsx +3 -1
  117. package/src/interfaces/index.ts +17 -0
  118. package/src/modules/gql/generated/helpers/apollo-helpers.ts +95 -19
  119. package/src/modules/gql/generated/schema.json +704 -25
  120. package/src/modules/gql/generated/types.ts +88 -1
  121. package/src/money/SecondaryPrices.tsx +99 -0
  122. package/src/money/__tests__/SecondaryPrices.test.tsx +110 -0
  123. package/src/money/__tests__/convert.test.ts +181 -0
  124. package/src/money/convert.ts +127 -0
@@ -71,6 +71,7 @@ export enum CardFieldName {
71
71
  SOCIALFACEBOOK = 'SocialFacebook',
72
72
  MESSENGERWHATSAPP = 'MessengerWhatsApp',
73
73
  MESSENGERVIBER = 'MessengerViber',
74
+ MESSENGERMAH = 'MessengerMah',
74
75
  MESSENGERTELEGRAM = 'MessengerTelegram',
75
76
  MESSENGERSKYPE = 'MessengerSkype',
76
77
  MESSENGERIMESSAGE = 'MessengerIMessage',
@@ -113,6 +114,7 @@ export interface CatalogFieldValue {
113
114
  fieldName: Scalars['String'];
114
115
  optionName: Scalars['String'];
115
116
  optionValue?: Maybe<Scalars['String']>;
117
+ parents?: Maybe<Scalars['String']>;
116
118
  isSelected: Scalars['Boolean'];
117
119
  isDisplayRemainder?: Maybe<Scalars['Boolean']>;
118
120
  isDefault?: Maybe<Scalars['Boolean']>;
@@ -126,7 +128,6 @@ export interface CatalogFieldValue {
126
128
  /** Количество оставшихся мест */
127
129
  availableCount?: Maybe<Scalars['Int']>;
128
130
  params?: Maybe<Scalars['String']>;
129
- parents?: Maybe<Scalars['String']>;
130
131
  /** Кастомный признак типа записи */
131
132
  type: CatalogFieldValueType;
132
133
  }
@@ -136,6 +137,7 @@ export interface CatalogFieldValueInput {
136
137
  fieldName?: Maybe<Scalars['String']>;
137
138
  optionName: Scalars['String'];
138
139
  optionValue?: Maybe<Scalars['String']>;
140
+ parents?: Maybe<Scalars['String']>;
139
141
  isSelected?: Maybe<Scalars['Boolean']>;
140
142
  extraPay?: Maybe<Scalars['BigDecimal']>;
141
143
  extraPayPercentage?: Maybe<Scalars['BigDecimal']>;
@@ -269,6 +271,13 @@ export interface ClientFormSubmitExtraFieldsPayload {
269
271
  clientForms: Array<ClientForm>;
270
272
  }
271
273
 
274
+ /** Профиль клиента */
275
+ export interface ClientProfile {
276
+ __typename?: 'ClientProfile';
277
+ id: Scalars['ID'];
278
+ hasSelfSubmittedOrder: Scalars['Boolean'];
279
+ }
280
+
272
281
  /** Контакты пользователя */
273
282
  export interface ContactsProfile {
274
283
  __typename?: 'ContactsProfile';
@@ -296,9 +305,15 @@ export interface CourseItem {
296
305
  tariffId?: Maybe<Scalars['Int']>;
297
306
  /** На сколько дней продление. Нужно для prolongation. */
298
307
  prolongationDays?: Maybe<Scalars['Int']>;
308
+ financeDocumentIds: Array<Scalars['Int']>;
299
309
  courseMeta?: Maybe<CourseItemMeta>;
300
310
  }
301
311
 
312
+
313
+ export type CourseItemFinanceDocumentIdsArgs = {
314
+ tariffId?: Maybe<Scalars['Int']>;
315
+ };
316
+
302
317
  export interface CourseItemMeta {
303
318
  __typename?: 'CourseItemMeta';
304
319
  courseName: Scalars['String'];
@@ -428,6 +443,7 @@ export interface CreateLandingOrderInput {
428
443
  isMultiday?: Maybe<Scalars['Boolean']>;
429
444
  clientMutationId?: Maybe<Scalars['String']>;
430
445
  promoCode?: Maybe<Scalars['String']>;
446
+ partnerCode?: Maybe<Scalars['String']>;
431
447
  paymentSchemaUid?: Maybe<Scalars['String']>;
432
448
  paymentSchemaIndexes?: Maybe<Array<Scalars['Int']>>;
433
449
  /** Поэтапная оплата */
@@ -442,6 +458,27 @@ export interface CreateLandingTemplateInput {
442
458
  }
443
459
 
444
460
 
461
+ export interface DepositTopupConfig {
462
+ __typename?: 'DepositTopupConfig';
463
+ /** Id бонусной валюты */
464
+ bonusCurrencyId: Scalars['Int'];
465
+ /** Курс: рубли за единицу бонусной валюты (руб. = Q × rate) */
466
+ rate: Scalars['BigDecimal'];
467
+ /** Название бонусной валюты */
468
+ bonusCurrencyName: Scalars['String'];
469
+ /** Максимум единиц к покупке (если задан) */
470
+ limit?: Maybe<Scalars['Int']>;
471
+ }
472
+
473
+ /** Валюта показа. Первый элемент списка — валюта Organization с rate = 1. Правила отбора считает lms-back, клиент их не знает. */
474
+ export interface DisplayCurrency {
475
+ __typename?: 'DisplayCurrency';
476
+ /** Код валюты (RUB, USD, …) */
477
+ currency: Scalars['String'];
478
+ /** Сколько единиц валюты Organization за 1 единицу этой валюты */
479
+ rate: Scalars['BigDecimal'];
480
+ }
481
+
445
482
  export interface Email {
446
483
  __typename?: 'Email';
447
484
  email: Scalars['String'];
@@ -485,6 +522,13 @@ export interface FinanceDocument {
485
522
  fileName: Scalars['String'];
486
523
  name: Scalars['String'];
487
524
  kind: Scalars['String'];
525
+ required: Scalars['Boolean'];
526
+ deletedAt?: Maybe<Scalars['DateTime']>;
527
+ }
528
+
529
+ export interface FinanceDocumentConsentInput {
530
+ financeDocumentId: Scalars['Int'];
531
+ agreed: Scalars['Boolean'];
488
532
  }
489
533
 
490
534
  export interface FlowPublicCustom {
@@ -526,6 +570,7 @@ export interface LandingSite {
526
570
  extraScript?: Maybe<Scalars['String']>;
527
571
  verificationCode?: Maybe<Scalars['String']>;
528
572
  showFeedbackWidget?: Maybe<Scalars['Boolean']>;
573
+ searchEngineIndexingDisabled: Scalars['Boolean'];
529
574
  }
530
575
 
531
576
  export interface LandingSitePrivate {
@@ -576,6 +621,7 @@ export interface LandingViewerUserRoleFragment {
576
621
  auths: Array<UserAuth>;
577
622
  human: UserHuman;
578
623
  contacts: ContactsProfile;
624
+ client: ClientProfile;
579
625
  }
580
626
 
581
627
  export interface LandintTemplatePayload {
@@ -609,6 +655,12 @@ export interface MasterClientProfileCommon {
609
655
  supervised: Array<UserProfileCustom>;
610
656
  }
611
657
 
658
+ export interface MasterClientRole {
659
+ __typename?: 'MasterClientRole';
660
+ uid: Scalars['Int'];
661
+ userId?: Maybe<Scalars['Int']>;
662
+ }
663
+
612
664
  export interface MasterProfileCustom {
613
665
  __typename?: 'MasterProfileCustom';
614
666
  id: Scalars['ID'];
@@ -622,6 +674,11 @@ export interface MasterProfileCustom {
622
674
  orgPhoto?: Maybe<PhotoData>;
623
675
  }
624
676
 
677
+
678
+ export type MasterProfileCustomDocumentsArgs = {
679
+ withDeleted?: Maybe<Scalars['Boolean']>;
680
+ };
681
+
625
682
  export enum MeetExpectation {
626
683
  /** Выше ожиданий */
627
684
  OVEREXPECTATION = 'OverExpectation',
@@ -646,6 +703,7 @@ export enum MessengerServices {
646
703
  WHATSAPP = 'WhatsApp',
647
704
  VIBER = 'Viber',
648
705
  TELEGRAM = 'Telegram',
706
+ MAH = 'Mah',
649
707
  SKYPE = 'Skype',
650
708
  IMESSAGE = 'IMessage',
651
709
  HANGOUTS = 'Hangouts',
@@ -776,6 +834,8 @@ export interface OrderCatalogItemOrg {
776
834
  __typename?: 'OrderCatalogItemOrg';
777
835
  contacts: OrderCatalogItemOrgContacts;
778
836
  sendingTransport?: Maybe<OrderCatalogItemOrgSendingTransport>;
837
+ language?: Maybe<Scalars['String']>;
838
+ displayCurrencies: Array<DisplayCurrency>;
779
839
  }
780
840
 
781
841
  export interface OrderCatalogItemOrgContacts {
@@ -798,6 +858,7 @@ export interface OrderCatalogItemFragment {
798
858
  id: Scalars['ID'];
799
859
  uid: Scalars['Int'];
800
860
  name: Scalars['String'];
861
+ kind?: Maybe<Scalars['String']>;
801
862
  /** @deprecated Заголовки для формирования заказа */
802
863
  title: Array<Scalars['String']>;
803
864
  /** Цена */
@@ -821,6 +882,7 @@ export interface OrderCatalogItemFragment {
821
882
  /** Опции с ценами */
822
883
  fieldValues?: Maybe<Array<CatalogFieldValue>>;
823
884
  partialPayment?: Maybe<PartialPayment>;
885
+ depositTopup?: Maybe<DepositTopupConfig>;
824
886
  }
825
887
 
826
888
 
@@ -858,6 +920,9 @@ export interface OrderCustom {
858
920
  /** Оригинальная цена без каких-либо скидок */
859
921
  catalogPrice?: Maybe<Scalars['Float']>;
860
922
  saleDiscount?: Maybe<Scalars['BigDecimal']>;
923
+ /** Сумма индивидуальной (персональной) скидки клиента на оплату */
924
+ clientDiscount?: Maybe<Scalars['BigDecimal']>;
925
+ priceDetails?: Maybe<PriceDetails>;
861
926
  promoCodeDiscount?: Maybe<Scalars['BigDecimal']>;
862
927
  availableBonusDiscount?: Maybe<Scalars['BigDecimal']>;
863
928
  subscriptionPrice?: Maybe<Scalars['BigDecimal']>;
@@ -971,6 +1036,7 @@ export interface PartialPaymentComplexItem {
971
1036
  /** Этап оплаты */
972
1037
  export interface PartialPrice {
973
1038
  __typename?: 'PartialPrice';
1039
+ name?: Maybe<Scalars['String']>;
974
1040
  /** Сумма */
975
1041
  amount: Scalars['Float'];
976
1042
  /** Крайний срок оплаты */
@@ -999,6 +1065,18 @@ export interface PhotoDataInput {
999
1065
  height?: Maybe<Scalars['Int']>;
1000
1066
  }
1001
1067
 
1068
+ export interface PriceDetails {
1069
+ __typename?: 'PriceDetails';
1070
+ strokePrice?: Maybe<Scalars['BigDecimal']>;
1071
+ choicePrice?: Maybe<Scalars['BigDecimal']>;
1072
+ saleDiscount?: Maybe<Scalars['BigDecimal']>;
1073
+ promoCodeDiscount?: Maybe<Scalars['BigDecimal']>;
1074
+ customDiscount?: Maybe<Scalars['BigDecimal']>;
1075
+ hiddenPayments?: Maybe<Scalars['BigDecimal']>;
1076
+ schemaMarkup?: Maybe<Scalars['BigDecimal']>;
1077
+ name?: Maybe<Scalars['String']>;
1078
+ }
1079
+
1002
1080
  export interface PriceOrderConditionData {
1003
1081
  __typename?: 'PriceOrderConditionData';
1004
1082
  kind: PriceOrderConditionKind;
@@ -1046,6 +1124,7 @@ export interface PublicLandingViewer {
1046
1124
  registerAuthMethod?: Maybe<AuthMethod>;
1047
1125
  checkoutPositions: Array<CheckoutPosition>;
1048
1126
  sendingTransport?: Maybe<SendingTransport>;
1127
+ org?: Maybe<ViewerOrgProfile>;
1049
1128
  }
1050
1129
 
1051
1130
  export interface PublicMasterRole {
@@ -1236,6 +1315,7 @@ export interface SubmitLandingOrderInput {
1236
1315
  customer?: Maybe<BookingClientInput>;
1237
1316
  clientMutationId?: Maybe<Scalars['String']>;
1238
1317
  address?: Maybe<AddressInput>;
1318
+ documentConsents?: Maybe<Array<FinanceDocumentConsentInput>>;
1239
1319
  }
1240
1320
 
1241
1321
  export interface TelegramTransport {
@@ -1337,6 +1417,13 @@ export interface UserProfileCustom {
1337
1417
  name: Scalars['String'];
1338
1418
  shortName: Scalars['String'];
1339
1419
  avatarUrl?: Maybe<Scalars['String']>;
1420
+ client?: Maybe<MasterClientRole>;
1421
+ }
1422
+
1423
+ export interface ViewerOrgProfile {
1424
+ __typename?: 'ViewerOrgProfile';
1425
+ language?: Maybe<Scalars['String']>;
1426
+ displayCurrencies: Array<DisplayCurrency>;
1340
1427
  }
1341
1428
 
1342
1429
  export interface WhatsAppTransport {
@@ -0,0 +1,99 @@
1
+ import React from 'react'
2
+ import styled from 'styled-components'
3
+
4
+ import { PriceFormat } from '../PriceFormat'
5
+ import { getCurrencyPrefix, getCurrencySuffix } from '../utils'
6
+ import {
7
+ convertMoney,
8
+ DisplayCurrencyRate,
9
+ secondaryCurrencies,
10
+ } from './convert'
11
+
12
+ export type SecondaryPricesProps = {
13
+ amount: number
14
+ /** Основная валюта — валюта Organization, `catalogItem.master?.currency`. */
15
+ primaryCurrency: string
16
+ /**
17
+ * Весь список валют показа как он пришёл с gateway: первый элемент — валюта Organization
18
+ * с `rate = 1`. Читается защитно: новый виджет обязан пережить старый gateway.
19
+ */
20
+ displayCurrencies?: ReadonlyArray<DisplayCurrencyRate> | null
21
+ /** `block` — строкой под ценой; `inline` — в скобках в той же строке (внутри кнопки). */
22
+ mode?: 'block' | 'inline'
23
+ }
24
+
25
+ /**
26
+ * Вторичные суммы рядом с ценой (SL-13080).
27
+ *
28
+ * `currentColor` + `opacity`, а не абсолютный серый: кнопка «Купить за …» залита цветом,
29
+ * который задаёт школа (`main_bg` в эмбед-коде), и фиксированный серый на ней нечитаем
30
+ * (контракт §7).
31
+ *
32
+ * При пустом хвосте не рендерит ничего — ни одного узла: со снятой галкой бэкенд отдаёт ровно
33
+ * один элемент, и разметка обязана совпасть с той, что была до изменения (§12 п.5).
34
+ */
35
+ export const SecondaryPrices: React.FC<SecondaryPricesProps> = ({
36
+ amount,
37
+ primaryCurrency,
38
+ displayCurrencies,
39
+ mode = 'block',
40
+ }) => {
41
+ const secondary = secondaryCurrencies(displayCurrencies, primaryCurrency)
42
+ if (!secondary.length) {
43
+ return null
44
+ }
45
+
46
+ const price = (n: DisplayCurrencyRate) => (
47
+ <PriceFormat
48
+ prefix={getCurrencyPrefix(n.currency)}
49
+ suffix={getCurrencySuffix(n.currency)}
50
+ value={convertMoney(amount, n.rate)}
51
+ />
52
+ )
53
+
54
+ if (mode === 'inline') {
55
+ return (
56
+ <SecondaryInlineStyled>
57
+ {' ('}
58
+ {secondary.map((n, index) => (
59
+ <React.Fragment key={n.currency}>
60
+ {index > 0 ? ', ' : null}
61
+ {price(n)}
62
+ </React.Fragment>
63
+ ))}
64
+ {')'}
65
+ </SecondaryInlineStyled>
66
+ )
67
+ }
68
+
69
+ return (
70
+ <SecondaryBlockStyled>
71
+ {secondary.map((n) => (
72
+ <span key={n.currency}>{price(n)}</span>
73
+ ))}
74
+ </SecondaryBlockStyled>
75
+ )
76
+ }
77
+
78
+ const secondaryTypography = `
79
+ color: currentColor;
80
+ opacity: 0.65;
81
+ font-size: calc(1em - 2px);
82
+ font-weight: inherit;
83
+ white-space: nowrap;
84
+ `
85
+
86
+ const SecondaryInlineStyled = styled.span`
87
+ ${secondaryTypography}
88
+ `
89
+
90
+ const SecondaryBlockStyled = styled.span`
91
+ ${secondaryTypography}
92
+ display: block;
93
+
94
+ > span {
95
+ display: block;
96
+ }
97
+ `
98
+
99
+ export default SecondaryPrices
@@ -0,0 +1,110 @@
1
+ import React from 'react'
2
+ import { render } from '@testing-library/react'
3
+
4
+ import { SecondaryPrices } from '../SecondaryPrices'
5
+ import OldPrice from '../../components/OldPrice'
6
+ import { DisplayCurrencyRate } from '../convert'
7
+
8
+ /** Школа с валютой USD и активным рублёвым финпрофилем — сценарий контракта §12 п.1. */
9
+ const USD_WITH_RUB: DisplayCurrencyRate[] = [
10
+ { currency: 'USD', rate: 1 },
11
+ { currency: 'RUB', rate: 0.0125 },
12
+ ]
13
+
14
+ const USD_WITH_RUB_KZT: DisplayCurrencyRate[] = [
15
+ ...USD_WITH_RUB,
16
+ { currency: 'KZT', rate: 0.002 },
17
+ ]
18
+
19
+ /** Снятая галка: бэкенд отдаёт ровно один элемент. */
20
+ const ONLY_PRIMARY: DisplayCurrencyRate[] = [{ currency: 'USD', rate: 1 }]
21
+
22
+ describe('SecondaryPrices', () => {
23
+ it('block: вторичная сумма отдельным узлом', () => {
24
+ const { container } = render(
25
+ <SecondaryPrices
26
+ amount={499}
27
+ primaryCurrency="USD"
28
+ displayCurrencies={USD_WITH_RUB}
29
+ />
30
+ )
31
+ expect(container.textContent).toContain('39')
32
+ expect(container.textContent).toContain('920')
33
+ expect(container.textContent).toContain('₽')
34
+ })
35
+
36
+ it('inline: вторичные суммы в скобках через запятую', () => {
37
+ const { container } = render(
38
+ <SecondaryPrices
39
+ amount={499}
40
+ primaryCurrency="USD"
41
+ displayCurrencies={USD_WITH_RUB_KZT}
42
+ mode="inline"
43
+ />
44
+ )
45
+ const text = container.textContent ?? ''
46
+ expect(text.trim().startsWith('(')).toBe(true)
47
+ expect(text.trim().endsWith(')')).toBe(true)
48
+ expect(text).toContain(', ')
49
+ expect(text).toContain('₸')
50
+ })
51
+
52
+ it('пустой хвост — ни одного узла (критерий приёмки §12 п.5)', () => {
53
+ const { container } = render(
54
+ <SecondaryPrices
55
+ amount={499}
56
+ primaryCurrency="USD"
57
+ displayCurrencies={ONLY_PRIMARY}
58
+ />
59
+ )
60
+ expect(container.innerHTML).toBe('')
61
+ })
62
+
63
+ it('displayCurrencies отсутствует (старый gateway) — ни одного узла', () => {
64
+ const { container } = render(
65
+ <SecondaryPrices amount={499} primaryCurrency="USD" />
66
+ )
67
+ expect(container.innerHTML).toBe('')
68
+ })
69
+
70
+ it('считает конвертером, а не double-делением (вектор §8 №18)', () => {
71
+ const { container } = render(
72
+ <SecondaryPrices
73
+ amount={17}
74
+ primaryCurrency="USD"
75
+ displayCurrencies={[
76
+ { currency: 'USD', rate: 1 },
77
+ { currency: 'RUB', rate: 0.272 },
78
+ ]}
79
+ />
80
+ )
81
+ expect(container.textContent).toContain('63')
82
+ })
83
+ })
84
+
85
+ describe('OldPrice', () => {
86
+ it('без валют показа разметка прежняя — один зачёркнутый узел', () => {
87
+ const { container } = render(<OldPrice price={999} prefix="$" suffix="" />)
88
+ // Ровно один узел верхнего уровня — обёртки OldPriceGroupStyled не появилось.
89
+ expect(container.childElementCount).toBe(1)
90
+ expect(container.textContent).toBe('$999')
91
+ })
92
+
93
+ it('со вторичной валютой каждая цена зачёркнута своим узлом', () => {
94
+ const { container } = render(
95
+ <OldPrice
96
+ price={999}
97
+ prefix="$"
98
+ suffix=""
99
+ primaryCurrency="USD"
100
+ displayCurrencies={USD_WITH_RUB}
101
+ />
102
+ )
103
+ // Обёртка появилась, внутри — два зачёркнутых узла (основная и вторичная цены).
104
+ expect(container.childElementCount).toBe(1)
105
+ expect(container.firstElementChild?.childElementCount).toBe(2)
106
+ expect(container.textContent).toContain('999')
107
+ expect(container.textContent).toContain('79')
108
+ expect(container.textContent).toContain('920')
109
+ })
110
+ })
@@ -0,0 +1,181 @@
1
+ import { convertMoney, secondaryCurrencies } from '../convert'
2
+
3
+ /**
4
+ * Канонический набор — контракт SL-13080 §8, все 19 векторов, дословно.
5
+ * Тот же набор прогоняется в lms-back (Scala) и в widget-order.
6
+ * Расхождение хотя бы на одном — стоп-условие, а не повод править таблицу.
7
+ */
8
+ type Vector = { amount: number; rate: number; expected: number; why: string }
9
+
10
+ const CONTRACT_VECTORS: Vector[] = [
11
+ {
12
+ amount: 7.99,
13
+ rate: 1,
14
+ expected: 7.99,
15
+ why: 'ветка rate == 1: округления нет; Math.round дал бы 8',
16
+ },
17
+ { amount: 39920, rate: 1, expected: 39920, why: 'та же ветка на целом' },
18
+ {
19
+ amount: 7.99,
20
+ rate: 1.0,
21
+ expected: 7.99,
22
+ why: 'курс со scale 10 обязан попасть в ту же ветку',
23
+ },
24
+ { amount: 0, rate: 1, expected: 0, why: 'ноль, родная валюта' },
25
+ { amount: 0, rate: 0.0125, expected: 0, why: 'ноль, конвертация' },
26
+ {
27
+ amount: 499,
28
+ rate: 0.0125,
29
+ expected: 39920,
30
+ why: 'критерий приёмки §12 п.1',
31
+ },
32
+ {
33
+ amount: 499,
34
+ rate: 0.0125,
35
+ expected: 39920,
36
+ why: 'хвост нулей расширенной точности ничего не меняет',
37
+ },
38
+ {
39
+ amount: -499,
40
+ rate: 0.0125,
41
+ expected: -39920,
42
+ why: 'возврат, точное деление',
43
+ },
44
+ { amount: 5, rate: 2, expected: 3, why: 'ровно 2.5 → HALF_UP вверх' },
45
+ {
46
+ amount: -5,
47
+ rate: 2,
48
+ expected: -3,
49
+ why: 'ровно -2.5 → HALF_UP от нуля; Math.round(-2.5) === -2',
50
+ },
51
+ { amount: 4, rate: 8, expected: 1, why: 'ровно 0.5' },
52
+ {
53
+ amount: -4,
54
+ rate: 8,
55
+ expected: -1,
56
+ why: 'ровно -0.5; Math.round(-0.5) === -0',
57
+ },
58
+ {
59
+ amount: 100,
60
+ rate: 3,
61
+ expected: 33,
62
+ why: 'непериодическое частное 33.333…',
63
+ },
64
+ { amount: 200, rate: 3, expected: 67, why: '66.666… → вверх' },
65
+ {
66
+ amount: 499,
67
+ rate: 0.0000789266,
68
+ expected: 6322330,
69
+ why: 'курс класса USD↔UZS',
70
+ },
71
+ {
72
+ amount: 499,
73
+ rate: 0.0001,
74
+ expected: 4990000,
75
+ why: 'тот же курс, урезанный до decimal(10,4)',
76
+ },
77
+ {
78
+ amount: 1,
79
+ rate: 0.0000000001,
80
+ expected: 10000000000,
81
+ why: 'граница scale = 10',
82
+ },
83
+ {
84
+ amount: 17,
85
+ rate: 0.272,
86
+ expected: 63,
87
+ why: 'точное 62.5; в double 62.49999999999999 → наивно 62',
88
+ },
89
+ {
90
+ amount: 7,
91
+ rate: 0.56,
92
+ expected: 13,
93
+ why: 'точное 12.5; в double 12.499999999999998 → наивно 12',
94
+ },
95
+ ]
96
+
97
+ describe('convertMoney — паритет со Scala (контракт §8)', () => {
98
+ CONTRACT_VECTORS.forEach((v, index) => {
99
+ it(`№${index + 1}: convertMoney(${v.amount}, ${v.rate}) === ${
100
+ v.expected
101
+ } — ${v.why}`, () => {
102
+ expect(convertMoney(v.amount, v.rate)).toBe(v.expected)
103
+ })
104
+ })
105
+
106
+ it('вектор №3 использует курс со scale 10 в исходной записи', () => {
107
+ // 1.0000000000 в JS неотличим от 1, поэтому вектор проверяется отдельно
108
+ // через строковый разбор — как он приедет из JSON.
109
+ expect(convertMoney(7.99, Number('1.0000000000'))).toBe(7.99)
110
+ })
111
+
112
+ it('вектор №7 использует курс со scale 10 в исходной записи', () => {
113
+ expect(convertMoney(499, Number('0.0125000000'))).toBe(39920)
114
+ })
115
+ })
116
+
117
+ describe('convertMoney — защитные случаи витрины', () => {
118
+ it('нулевой курс возвращает сумму как есть', () => {
119
+ expect(convertMoney(499, 0)).toBe(499)
120
+ })
121
+
122
+ it('NaN в курсе возвращает сумму как есть', () => {
123
+ expect(convertMoney(499, NaN)).toBe(499)
124
+ })
125
+
126
+ it('отрицательный курс возвращает сумму как есть', () => {
127
+ expect(convertMoney(499, -0.5)).toBe(499)
128
+ })
129
+
130
+ it('NaN в сумме возвращает её как есть', () => {
131
+ expect(Number.isNaN(convertMoney(NaN, 0.0125))).toBe(true)
132
+ })
133
+
134
+ it('не порождает -0', () => {
135
+ expect(Object.is(convertMoney(-0.001, 2), 0)).toBe(true)
136
+ })
137
+ })
138
+
139
+ describe('secondaryCurrencies', () => {
140
+ const list = [
141
+ { currency: 'USD', rate: 1 },
142
+ { currency: 'RUB', rate: 0.0125 },
143
+ { currency: 'KZT', rate: 0.002 },
144
+ ]
145
+
146
+ it('отбрасывает первый элемент — валюту Organization', () => {
147
+ expect(secondaryCurrencies(list, 'USD').map((n) => n.currency)).toEqual([
148
+ 'RUB',
149
+ 'KZT',
150
+ ])
151
+ })
152
+
153
+ it('список из одного элемента даёт пустой хвост', () => {
154
+ expect(secondaryCurrencies([{ currency: 'RUB', rate: 1 }], 'RUB')).toEqual(
155
+ []
156
+ )
157
+ })
158
+
159
+ it('null и undefined дают пустой хвост', () => {
160
+ expect(secondaryCurrencies(null, 'RUB')).toEqual([])
161
+ expect(secondaryCurrencies(undefined, 'RUB')).toEqual([])
162
+ })
163
+
164
+ it('отсекает валюту, совпавшую с основной (расхождение OrgProfile и MasterProfileCommon)', () => {
165
+ expect(secondaryCurrencies(list, 'RUB').map((n) => n.currency)).toEqual([
166
+ 'KZT',
167
+ ])
168
+ })
169
+
170
+ it('отсекает нулевой и отрицательный курс', () => {
171
+ const broken = [
172
+ { currency: 'USD', rate: 1 },
173
+ { currency: 'RUB', rate: 0 },
174
+ { currency: 'KZT', rate: -1 },
175
+ { currency: 'UAH', rate: 0.03 },
176
+ ]
177
+ expect(secondaryCurrencies(broken, 'USD').map((n) => n.currency)).toEqual([
178
+ 'UAH',
179
+ ])
180
+ })
181
+ })