Skip to content

Commit

Permalink
chore: fix some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimirpotekhin committed Aug 14, 2023
1 parent 6dfa288 commit 25ee064
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 29 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ jobs:
# Replace with npm run cy:run -- --spec "**/!(kit|recipes)/*.cy.ts" --config baseUrl="${{ env.UNIVERSAL_SERVER }}"
# After this issue fix: https://github.com/cypress-io/cypress/issues/22407
run:
npm run cy:run -- --spec "**/(angular|ssr|others)/**/*.cy.ts" --config baseUrl="${{ env.UNIVERSAL_SERVER }}"

npm run cy:run -- --spec "**/(angular|ssr|addons|others)/**/*.cy.ts" --config baseUrl="${{
env.UNIVERSAL_SERVER }}"
concurrency:
group: e2e-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
1 change: 1 addition & 0 deletions projects/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export {
} from './lib/constants';
export {Maskito} from './lib/mask';
export {
MaskExpression,
MaskitoElementPredicate,
MaskitoElementPredicateAsync,
MaskitoMask,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {DemoPath} from '@demo/constants';

import {BROWSER_SUPPORTS_REAL_EVENTS} from '../../support/constants';
import {BROWSER_SUPPORTS_REAL_EVENTS} from '../../../support/constants';

describe('Phone', () => {
describe('Basic', () => {
Expand Down Expand Up @@ -169,6 +169,89 @@ describe('Phone', () => {
},
);
});

describe('Non-removable country prefix', () => {
it('cannot be removed via selectAll + Backspace', () => {
cy.get('@input')
.type('9123456789')
.type('{selectall}{backspace}')
.should('have.value', '+7 ')
.should('have.prop', 'selectionStart', '+7 '.length)
.should('have.prop', 'selectionEnd', '+7 '.length);
});

it('cannot be removed via selectAll + Delete', () => {
cy.get('@input')
.type('9123456789')
.type('{selectall}{del}')
.should('have.value', '+7 ')
.should('have.prop', 'selectionStart', '+7 '.length)
.should('have.prop', 'selectionEnd', '+7 '.length);
});

it('cannot be removed via Backspace', () => {
cy.get('@input')
.type('9123456789')
.type('{backspace}'.repeat('+7 912 345-89'.length))
.should('have.value', '+7 ')
.should('have.prop', 'selectionStart', '+7 '.length)
.should('have.prop', 'selectionEnd', '+7 '.length);
});

it('cannot be removed via Delete', () => {
cy.get('@input')
.type('9123456789')
.type('{moveToStart}')
.type('{del}'.repeat('+7 912 345-89'.length))
.should('have.value', '+7 ')
.should('have.prop', 'selectionStart', '+7 '.length)
.should('have.prop', 'selectionEnd', '+7 '.length);
});

it('appears on focus if input is empty', () => {
cy.get('@input')
.blur()
.should('have.value', '')
.focus()
.should('have.value', '+7 ')
.should('have.prop', 'selectionStart', '+7 '.length)
.should('have.prop', 'selectionEnd', '+7 '.length);
});

it('disappears on blur if there are no more digits except it', () => {
cy.get('@input')
.focus()
.should('have.value', '+7 ')
.blur()
.should('have.value', '');
});

describe('with caret guard', () => {
it('forbids to put caret before country prefix', () => {
cy.get('@input')
.should('have.value', '+7 ')
.should('have.prop', 'selectionStart', '+7 '.length)
.should('have.prop', 'selectionEnd', '+7 '.length)
.type('{moveToStart}')
.should('have.value', '+7 ')
.should('have.prop', 'selectionStart', '+7 '.length)
.should('have.prop', 'selectionEnd', '+7 '.length)
.type('{leftArrow}'.repeat(5))
.should('have.value', '+7 ')
.should('have.prop', 'selectionStart', '+7 '.length)
.should('have.prop', 'selectionEnd', '+7 '.length);
});

it('can be selected via selectAll', () => {
cy.get('@input')
.type('9123456789')
.type('{selectall}')
.should('have.value', '+7 912 345-67-89')
.should('have.prop', 'selectionStart', 0)
.should('have.prop', 'selectionEnd', '+7 912 345-67-89'.length);
});
});
});
});

describe('Some countries', () => {
Expand Down
2 changes: 1 addition & 1 deletion projects/demo/src/app/constants/demo-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const enum DemoPath {
Date = 'kit/date',
DateRange = 'kit/date-range',
DateTime = 'kit/date-time',
PhonePackage = 'phone/phone',
PhonePackage = 'addons/phone',
Card = 'recipes/card',
Phone = 'recipes/phone',
Textarea = 'recipes/textarea',
Expand Down
6 changes: 3 additions & 3 deletions projects/demo/src/pages/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ export const DEMO_PAGES: TuiDocPages = [
keywords: `date, day, month, year, mask, time, date-time, hour, minute, second, kit, generator`,
},
{
section: 'Phone',
title: 'Phone',
section: 'Addons',
title: '@maskito/phone',
route: DemoPath.PhonePackage,
keywords: `phone, libphonenumber, generator`,
keywords: `phone, libphonenumber, international, generator`,
},
{
section: 'Recipes',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
autocomplete="tel"
inputmode="tel"
[maskito]="maskitoOptions"
(focus)="onFocus()"
(blur)="onBlur()"
/>
</tui-input>

Expand Down
10 changes: 5 additions & 5 deletions projects/phone/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# @maskito/phone

[![npm version](https://img.shields.io/npm/v/@maskito/phone.svg)](https://npmjs.com/package/@maskito/kit)
[![npm bundle size](https://img.shields.io/bundlephobia/minzip/@maskito/phone)](https://bundlephobia.com/result?p=@maskito/kit)
[![npm version](https://img.shields.io/npm/v/@maskito/phone.svg)](https://npmjs.com/package/@maskito/phone)
[![npm bundle size](https://img.shields.io/bundlephobia/minzip/@maskito/phone)](https://bundlephobia.com/result?p=@maskito/phone)

<p align="center">
<img src="https://raw.githubusercontent.com/Tinkoff/maskito/main/projects/demo/src/assets/icons/maskito.svg" alt="Maskito logo" height="120px">
<img src="https://raw.githubusercontent.com/taiga-family/maskito/main/projects/demo/src/assets/icons/maskito.svg" alt="Maskito logo" height="120px">
</p>

<p align="center">
<a href="https://tinkoff.github.io/maskito">Documentation</a> •
<a href="https://github.com/Tinkoff/maskito/issues/new/choose">Submit an Issue</a> •
<a href="https://maskito.dev">Documentation</a> •
<a href="https://github.com/taiga-family/maskito/issues/new/choose">Submit an Issue</a> •
<a href="https://t.me/taiga_ui">Contact Us</a>
</p>

Expand Down
17 changes: 9 additions & 8 deletions projects/phone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
"javascript",
"typescript"
],
"homepage": "https://tinkoff.github.io/maskito",
"bugs": "https://github.com/tinkoff/maskito/issues",
"homepage": "https://maskito.dev",
"bugs": "https://github.com/taiga-family/maskito/issues",
"repository": {
"type": "git",
"url": "https://github.com/tinkoff/maskito.git"
"url": "https://github.com/taiga-family/maskito.git"
},
"license": "Apache-2.0",
"author": {
"name": "Nikita Barsukov",
"email": "nikita.s.barsukov@gmail.com",
"url": "https://github.com/nsbarsukov"
"name": "Vladimir Potekhin",
"email": "vladimir.potekh@gmail.com",
"url": "https://github.com/vladimirpotekhin"
},
"contributors": [
"Alex Inkin <alexander@inkin.ru> (https://twitter.com/waterplea)",
Expand All @@ -29,10 +29,11 @@
"Nikita Barsukov <nikita.s.barsukov@gmail.com>"
],
"devDependencies": {
"libphonenumber-js": "^1.10.37"
"libphonenumber-js": "^1.10.0"
},
"peerDependencies": {
"@maskito/core": "^1.4.0",
"libphonenumber-js": "^1.10.37"
"@maskito/kit": "^1.4.0",
"libphonenumber-js": ">=1.0.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ export function maskitoCutPhonePostprocessorGenerator(
countryIsoCode: CountryCode,
): MaskitoPostprocessor {
return ({value, selection}) => {
if (value.length > MIN_LENGTH) {
return {
value: cutPhoneByValidLength({phone: value, countryIsoCode, metadata}),
selection,
};
}

return {value, selection};
return {
value:
value.length > MIN_LENGTH
? cutPhoneByValidLength({phone: value, countryIsoCode, metadata})
: value,
selection,
};
};
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {MaskExpression} from '@maskito/core/src/lib/types';
import {MaskExpression} from '@maskito/core';

import {TEMPLATE_FILLER} from '../constants';

Expand Down

0 comments on commit 25ee064

Please sign in to comment.