Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(wizards/doTypes): Adjust regular expressions for v flag in template editor #1273

Merged
merged 5 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/wizards/foundation/limits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const nameStartChar =
'|[\u037F-\u1FFF]|[\u200C-\u200D]|[\u2070-\u218F]|[\u2C00-\u2FEF]' +
'|[\u3001-\uD7FF]|[\uF900-\uFDCF]|[\uFDF0-\uFFFD]';
const nameChar =
nameStartChar + '|[.0-9-]|\u00B7|[\u0300-\u036F]|[\u203F-\u2040]';
nameStartChar + '|[.0-9\\-]|\u00B7|[\u0300-\u036F]|[\u203F-\u2040]';
const name = nameStartChar + '(' + nameChar + ')*';
const nmToken = '(' + nameChar + ')+';

Expand All @@ -17,7 +17,7 @@ export const patterns = {
nmToken,
names: name + '( ' + name + ')*',
nmTokens: nmToken + '( ' + nmToken + ')*',
decimal: '[+-]?[0-9]+(([.][0-9]*)?|([.][0-9]+))',
decimal: '[+\\-]?[0-9]+(([.][0-9]*)?|([.][0-9]+))',
unsigned: '[+]?[0-9]+(([.][0-9]*)?|([.][0-9]+))',
alphanumericFirstUpperCase: '[A-Z][0-9,A-Z,a-z]*',
asciName: '[A-Za-z][0-9,A-Z,a-z_]*',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,6 @@ snapshots["DOType wizards defines a createDOTypeWizard looks like the latest sna
label="id"
maxlength="127"
minlength="1"
pattern="([:_A-Za-z]|[À-Ö]|[Ø-ö]|[ø-˿]|[Ͱ-ͽ]|[Ϳ-῿]|[‌-‍]|[⁰-↏]|[Ⰰ-⿯]|[、-퟿]|[豈-﷏]|[ﷰ-�]|[.0-9-]|·|[̀-ͯ]|[‿-⁀])+"
required=""
>
</wizard-textfield>
Expand All @@ -688,13 +687,11 @@ snapshots["DOType wizards defines a createDOTypeWizard looks like the latest sna
helper="[scl.desc]"
label="desc"
nullable=""
pattern="([ -~]|[…]|[ -퟿]|[-�])*"
>
</wizard-textfield>
<wizard-textfield
helper="[scl.cdc]"
label="cdc"
pattern="(SPS)|(DPS)|(INS)|(ENS)|(ACT)|(ACD)|(SEC)|(BCR)|(HST)|(VSS)|(MV)|(CMV)|(SAV)|(WYE)|(DEL)|(SEQ)|(HMV)|(HWYE)|(HDEL)|(SPC)|(DPC)|(INC)|(ENC)|(BSC)|(ISC)|(APC)|(BAC)|(SPG)|(ING)|(ENG)|(ORG)|(TSG)|(CUG)|(VSG)|(ASG)|(CURVE)|(CSG)|(DPL)|(LPL)|(CSD)|(CST)|(BTS)|(UTS)|(LTS)|(GTS)|(MTS)|(NTS)|(STS)|(CTS)|(OTS)|(VSD)"
required=""
>
</wizard-textfield>
Expand Down Expand Up @@ -783,7 +780,6 @@ snapshots["DOType wizards defines a dOTypeWizard looks like the latest snapshot"
label="id"
maxlength="127"
minlength="1"
pattern="([:_A-Za-z]|[À-Ö]|[Ø-ö]|[ø-˿]|[Ͱ-ͽ]|[Ϳ-῿]|[‌-‍]|[⁰-↏]|[Ⰰ-⿯]|[、-퟿]|[豈-﷏]|[ﷰ-�]|[.0-9-]|·|[̀-ͯ]|[‿-⁀])+"
required=""
>
</wizard-textfield>
Expand All @@ -792,13 +788,11 @@ snapshots["DOType wizards defines a dOTypeWizard looks like the latest snapshot"
helper="[scl.desc]"
label="desc"
nullable=""
pattern="([ -~]|[…]|[ -퟿]|[-�])*"
>
</wizard-textfield>
<wizard-textfield
helper="[scl.CDC]"
label="CDC"
pattern="([ -~]|[…]|[ -퟿]|[-�])*"
>
</wizard-textfield>
<mwc-list style="margin-top: 0px;">
Expand Down Expand Up @@ -1068,7 +1062,6 @@ snapshots["DOType wizards defines a sDOWizard to edit an existing SDO looks like
dialoginitialfocus=""
helper="[scl.name]"
label="name"
pattern="[a-z][0-9A-Za-z]*"
required=""
>
>
Expand All @@ -1078,7 +1071,6 @@ snapshots["DOType wizards defines a sDOWizard to edit an existing SDO looks like
helper="[scl.desc]"
label="desc"
nullable=""
pattern="([ -~]|[…]|[ -퟿]|[-�])*"
>
</wizard-textfield>
<mwc-select
Expand Down Expand Up @@ -1256,7 +1248,6 @@ snapshots["DOType wizards defines a sDOWizard to create a new SDO element looks
dialoginitialfocus=""
helper="[scl.name]"
label="name"
pattern="[a-z][0-9A-Za-z]*"
required=""
>
>
Expand All @@ -1266,7 +1257,6 @@ snapshots["DOType wizards defines a sDOWizard to create a new SDO element looks
helper="[scl.desc]"
label="desc"
nullable=""
pattern="([ -~]|[…]|[ -퟿]|[-�])*"
>
</wizard-textfield>
<mwc-select
Expand Down
137 changes: 133 additions & 4 deletions test/integration/editors/templates/dotype-wizarding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import TemplatesPlugin from '../../../../src/editors/Templates.js';
import { WizardTextField } from '../../../../src/wizard-textfield.js';
import { ListItemBase } from '@material/mwc-list/mwc-list-item-base';

import { patterns } from '../../../../src/wizards/foundation/limits.js';

describe('DOType wizards', () => {
if (customElements.get('templates-editor') === undefined)
customElements.define('templates-editor', TemplatesPlugin);
Expand Down Expand Up @@ -69,7 +71,41 @@ describe('DOType wizards', () => {
});

it('looks like the latest snapshot', async () => {
await expect(parent.wizardUI.dialog).to.equalSnapshot();
// prettier does not support escaping in regexes of the /v flag
await expect(parent.wizardUI.dialog).dom.to.equalSnapshot({
ignoreAttributes: [
{
tags: ['wizard-textfield'],
attributes: ['pattern'],
},
],
});
});

// work around, because the escapes get removed in snapshot by prettier
it('should have correct pattern', async () => {
expect(
parent.wizardUI.dialog!.querySelectorAll('wizard-textfield[pattern]')!
.length
).to.equal(3);

expect(
parent.wizardUI
.dialog!.querySelectorAll('wizard-textfield[pattern]')[0]
.getAttribute('pattern')
).to.equal(patterns.nmToken);

expect(
parent.wizardUI
.dialog!.querySelectorAll('wizard-textfield[pattern]')[1]
.getAttribute('pattern')
).to.equal(patterns.normalizedString);

expect(
parent.wizardUI
.dialog!.querySelectorAll('wizard-textfield[pattern]')[2]
.getAttribute('pattern')
).to.equal(patterns.cdc);
});

it('allows to add empty DOTypes to the project', async () => {
Expand Down Expand Up @@ -171,7 +207,41 @@ describe('DOType wizards', () => {
});

it('looks like the latest snapshot', async () => {
await expect(parent.wizardUI.dialog).to.equalSnapshot();
// prettier does not support escaping in regexes of the /v flag
await expect(parent.wizardUI.dialog).dom.to.equalSnapshot({
ignoreAttributes: [
{
tags: ['wizard-textfield'],
attributes: ['pattern'],
},
],
});
});

// work around, because the escapes get removed in snapshot by prettier
it('should have correct pattern', async () => {
expect(
parent.wizardUI.dialog!.querySelectorAll('wizard-textfield[pattern]')!
.length
).to.equal(3);

expect(
parent.wizardUI
.dialog!.querySelectorAll('wizard-textfield[pattern]')[0]
.getAttribute('pattern')
).to.equal(patterns.nmToken);

expect(
parent.wizardUI
.dialog!.querySelectorAll('wizard-textfield[pattern]')[1]
.getAttribute('pattern')
).to.equal(patterns.normalizedString);

expect(
parent.wizardUI
.dialog!.querySelectorAll('wizard-textfield[pattern]')[2]
.getAttribute('pattern')
).to.equal(patterns.normalizedString);
});

it('edits DOType attributes id', async () => {
Expand Down Expand Up @@ -242,8 +312,37 @@ describe('DOType wizards', () => {
});

it('looks like the latest snapshot', async () => {
await expect(parent.wizardUI.dialog).to.equalSnapshot();
// prettier does not support escaping in regexes of the /v flag
await expect(parent.wizardUI.dialog).dom.to.equalSnapshot({
ignoreAttributes: [
{
tags: ['wizard-textfield'],
attributes: ['pattern'],
},
],
});
});

// work around, because the escapes get removed in snapshot by prettier
it('should have correct pattern', async () => {
expect(
parent.wizardUI.dialog!.querySelectorAll('wizard-textfield[pattern]')!
.length
).to.equal(2);

expect(
parent.wizardUI
.dialog!.querySelectorAll('wizard-textfield[pattern]')[0]
.getAttribute('pattern')
).to.equal(patterns.tRestrName1stL);

expect(
parent.wizardUI
.dialog!.querySelectorAll('wizard-textfield[pattern]')[1]
.getAttribute('pattern')
).to.equal(patterns.normalizedString);
});

it('edits SDO attributes name', async () => {
expect(doc.querySelector('DOType[id="Dummy.WYE"] > SDO[name="phsA"]')).to
.exist;
Expand Down Expand Up @@ -330,8 +429,37 @@ describe('DOType wizards', () => {
});

it('looks like the latest snapshot', async () => {
await expect(parent.wizardUI.dialog).to.equalSnapshot();
// prettier does not support escaping in regexes of the /v flag
await expect(parent.wizardUI.dialog).dom.to.equalSnapshot({
ignoreAttributes: [
{
tags: ['wizard-textfield'],
attributes: ['pattern'],
},
],
});
});

// work around, because the escapes get removed in snapshot by prettier
it('should have correct pattern', async () => {
expect(
parent.wizardUI.dialog!.querySelectorAll('wizard-textfield[pattern]')!
.length
).to.equal(2);

expect(
parent.wizardUI
.dialog!.querySelectorAll('wizard-textfield[pattern]')[0]
.getAttribute('pattern')
).to.equal(patterns.tRestrName1stL);

expect(
parent.wizardUI
.dialog!.querySelectorAll('wizard-textfield[pattern]')[1]
.getAttribute('pattern')
).to.equal(patterns.normalizedString);
});

it('creates a new SDO element', async () => {
expect(
doc.querySelector(
Expand All @@ -349,6 +477,7 @@ describe('DOType wizards', () => {
)
).to.exist;
});

it('creates yet another new SDO element', async () => {
const name = 'newSDOElement2';
const desc = 'newSDOdesc';
Expand Down