-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from TRIPTYK/prefab-input-email
Prefab input email
- Loading branch information
Showing
7 changed files
with
637 additions
and
437 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
.../tests/integration/components/ember-input-validation/prefabs/tpk-validation-email-test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { module, test } from 'qunit'; | ||
import { | ||
render, | ||
settled, | ||
triggerEvent, | ||
type TestContext, | ||
} from '@ember/test-helpers'; | ||
import { hbs } from 'ember-cli-htmlbars'; | ||
import { ImmerChangeset } from 'ember-immer-changeset'; | ||
import { setupRenderingTest } from 'ember-qunit'; | ||
import { setupIntl } from 'ember-intl/test-support'; | ||
|
||
module( | ||
'Integreation | Component | Prefabs | tpk-validation-email', | ||
function (hooks) { | ||
setupRenderingTest(hooks); | ||
setupIntl(hooks, 'fr-fr'); | ||
|
||
async function renderComponent() { | ||
await render(hbs` | ||
<Prefabs::TpkValidationEmail | ||
@changeset={{this.changeset}} | ||
@validationField="email" | ||
@label="Email validation field" | ||
/> | ||
`); | ||
} | ||
|
||
function setupChangeset(this: TestContext, email: string) { | ||
const changeset = new ImmerChangeset({ | ||
email, | ||
}); | ||
|
||
this.set('changeset', changeset); | ||
return changeset; | ||
} | ||
|
||
test('the type of the input is email', async function (assert) { | ||
setupChangeset.call(this, 'email'); | ||
|
||
await renderComponent(); | ||
assert.dom('input').hasAttribute('type', 'email'); | ||
}); | ||
|
||
test('It changes data-has-error attribute on error', async function (assert) { | ||
const changeset = setupChangeset.call(this, ''); | ||
|
||
await renderComponent(); | ||
|
||
changeset.addError({ | ||
message: 'required', | ||
value: '', | ||
originalValue: '', | ||
key: 'email', | ||
}); | ||
await settled(); | ||
assert.dom('[data-test-tpk-input-input]').hasNoText(); | ||
assert | ||
.dom('[data-test-tpk-input]') | ||
.hasAttribute('data-has-error', 'true'); | ||
}); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
packages/ember-input-validation/src/components/prefabs/tpk-validation-email.gts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import type { TpkInputSignature } from '@triptyk/ember-input/components/tpk-input'; | ||
import { hash } from '@ember/helper'; | ||
import TpkValidationInputComponent, { | ||
type TpkValidationInputComponentSignature, | ||
} from '../tpk-validation-input.gts'; | ||
import { | ||
type BaseValidationSignature, | ||
BaseValidationComponent, | ||
} from '../base.ts'; | ||
import TpkValidationErrorsComponent from './tpk-validation-errors.gts'; | ||
|
||
export interface TpkValidationEmailComponentSignature | ||
extends BaseValidationSignature { | ||
Args: Omit< | ||
TpkValidationInputComponentSignature['Args'], | ||
| 'type' | ||
| 'min' | ||
| 'max' | ||
| 'step' | ||
| 'mask' | ||
| 'unmaskValue' | ||
| 'maskOptions' | ||
| 'mask' | ||
>; | ||
Blocks: { | ||
default: []; | ||
}; | ||
Element: HTMLDivElement; | ||
} | ||
|
||
export default class TpkValidationEmailComponent extends BaseValidationComponent<TpkValidationEmailComponentSignature> { | ||
<template> | ||
<TpkValidationInputComponent | ||
@type='email' | ||
@label={{@label}} | ||
@classless={{@classless}} | ||
@disabled={{@disabled}} | ||
@changeEvent={{@changeEvent}} | ||
@placeholder={{@placeholder}} | ||
@validationField={{@validationField}} | ||
@changeset={{@changeset}} | ||
@mandatory={{@mandatory}} | ||
...attributes | ||
data-test-input='email' | ||
as |V| | ||
> | ||
<V.Label /> | ||
<V.Input /> | ||
<TpkValidationErrorsComponent | ||
@errors={{V.errors}} | ||
@classless={{@classless}} | ||
/> | ||
</TpkValidationInputComponent> | ||
</template> | ||
} |
35 changes: 35 additions & 0 deletions
35
packages/ember-input-validation/src/components/prefabs/tpk-validation-errors.gts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { helper } from '@ember/component/helper'; | ||
import Component from '@glimmer/component'; | ||
import { htmlSafe as HS } from '@ember/template'; | ||
import { t } from 'ember-intl'; | ||
|
||
export interface TpkValidationErrorsComponentSignature { | ||
Args: { | ||
errors: any; | ||
classless?: boolean; | ||
}; | ||
Blocks: { | ||
default: []; | ||
}; | ||
Element: HTMLDivElement; | ||
} | ||
|
||
export default class TpkValidationErrorsComponent extends Component<TpkValidationErrorsComponentSignature> { | ||
htmlSafe = helper(function htmlSafe(params: [string]) { | ||
return HS(params.join()); | ||
}); | ||
|
||
<template> | ||
<aside class={{unless @classless "tpk-validation-errors"}}> | ||
{{#each @errors as |error|}} | ||
<span> | ||
{{#if error.message}} | ||
{{this.htmlSafe (t error.message error.params)}} | ||
{{else}} | ||
{{error}} | ||
{{/if}} | ||
</span> | ||
{{/each}} | ||
</aside> | ||
</template> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.