-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
73 additions
and
212 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,19 @@ | ||
import { render } from '@ember/test-helpers'; | ||
import { hbs } from 'ember-cli-htmlbars'; | ||
import { module, test } from 'qunit'; | ||
|
||
import { RegisterChangeset } from 'ember-boilerplate/changesets/register'; | ||
import { setupRenderingTest } from 'ember-boilerplate/tests/helpers'; | ||
import { pagesFormsRegister } from 'ember-boilerplate/tests/pages/forms/register'; | ||
import validationsRegister from 'ember-boilerplate/validations/register'; | ||
|
||
import { setupIntl } from 'ember-intl/test-support'; | ||
|
||
import type { TestContext } from '@ember/test-helpers'; | ||
|
||
interface RegisterTestContext extends TestContext { | ||
changeset: RegisterChangeset; | ||
saveFunction: (changeset: RegisterChangeset) => void; | ||
validationSchema: typeof validationsRegister; | ||
} | ||
import RegisterForm from 'ember-boilerplate/components/forms/register'; | ||
import type { Schema } from 'yup'; | ||
|
||
module('Integration | Component | forms/register', function (hooks) { | ||
setupRenderingTest(hooks); | ||
setupIntl(hooks, ['fr-fr']); | ||
|
||
let changeset: RegisterChangeset; | ||
|
||
hooks.beforeEach<RegisterTestContext>(function () { | ||
changeset = new RegisterChangeset({ | ||
function createChangeset(): RegisterChangeset { | ||
return new RegisterChangeset({ | ||
email: '[email protected]', | ||
lastName: 'triptyk', | ||
firstName: 'papa', | ||
|
@@ -33,34 +22,33 @@ module('Integration | Component | forms/register', function (hooks) { | |
password: '', | ||
confirmPassword: '', | ||
}); | ||
} | ||
|
||
this.set('changeset', changeset); | ||
}); | ||
|
||
function renderForm() { | ||
return render<RegisterTestContext>( | ||
hbs` | ||
<Forms::Register | ||
@changeset={{this.changeset}} | ||
@saveFunction={{this.saveFunction}} | ||
@validationSchema={{this.validationSchema}} | ||
function renderForm( | ||
changeset: RegisterChangeset, | ||
saveFunction: (changeset: RegisterChangeset) => void, | ||
validationSchema: Schema | ||
) { | ||
return render( | ||
<template> | ||
<RegisterForm | ||
@changeset={{changeset}} | ||
@saveFunction={{saveFunction}} | ||
@validationSchema={{validationSchema}} | ||
/> | ||
`, | ||
</template> | ||
); | ||
} | ||
|
||
test('Submit with missing field returns errors', async function (assert) { | ||
// Testing makes Amaury happy so do your tests | ||
this.set('saveFunction', () => {}); | ||
this.set('validationSchema', validationsRegister); | ||
await renderForm(); | ||
await renderForm(createChangeset(), () => {}, validationsRegister); | ||
await pagesFormsRegister.submit(); | ||
assert.true(pagesFormsRegister.errors.length > 0); | ||
}); | ||
|
||
// note : saveFunction when form is valid is already tested by the component YupForm. No need to test this behavior in the future. | ||
test('Edit form and trigger saveFunction', async function (assert) { | ||
this.set('saveFunction', (changeset: RegisterChangeset) => { | ||
let saveFunction = (changeset: RegisterChangeset) => { | ||
assert.strictEqual(changeset.get('lastName'), 'triptyk'); | ||
assert.strictEqual(changeset.get('firstName'), 'papa'); | ||
assert.strictEqual(changeset.get('email'), '[email protected]'); | ||
|
@@ -69,32 +57,24 @@ module('Integration | Component | forms/register', function (hooks) { | |
assert.strictEqual(changeset.get('password'), 'hello'); | ||
assert.strictEqual(changeset.get('confirmPassword'), 'hello'); | ||
assert.step('saveFunction'); | ||
}); | ||
this.set('validationSchema', validationsRegister); | ||
await renderForm(); | ||
}; | ||
await renderForm(createChangeset(), saveFunction, validationsRegister); | ||
|
||
await pagesFormsRegister | ||
.gift('234,23 €') | ||
.password('hello') | ||
.confirmPassword('hello'); | ||
await pagesFormsRegister.gift('234,23 €').password('hello').confirmPassword('hello'); | ||
|
||
await pagesFormsRegister.submit(); | ||
assert.verifySteps(['saveFunction']); | ||
}); | ||
|
||
test('confirmPassword which does not match password returns an error', async function (assert) { | ||
this.set('saveFunction', () => {}); | ||
this.set('validationSchema', validationsRegister); | ||
await renderForm(); | ||
await renderForm(createChangeset(), () => {}, validationsRegister); | ||
|
||
await pagesFormsRegister.password('hello').confirmPassword('hellos'); | ||
|
||
await pagesFormsRegister.submit(); | ||
|
||
assert.true( | ||
pagesFormsRegister.errors[0]?.text?.includes( | ||
'validations.confirm_password.not_matching', | ||
), | ||
pagesFormsRegister.errors[0]?.text?.includes('validations.confirm_password.not_matching') | ||
); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,19 +1,19 @@ | ||
/* eslint-disable qunit/require-expect */ | ||
import { render, type TestContext } from '@ember/test-helpers'; | ||
import { render } from '@ember/test-helpers'; | ||
import click from '@ember/test-helpers/dom/click'; | ||
import { hbs } from 'ember-cli-htmlbars'; | ||
import { module, test } from 'qunit'; | ||
import { setupRenderingTest } from 'ember-qunit'; | ||
|
||
import { loginPage } from 'ember-boilerplate/tests/pages/login'; | ||
import loginSchema from 'ember-boilerplate/validations/login'; | ||
import { type Changeset,ImmerChangeset } from 'ember-immer-changeset'; | ||
import { type Changeset, ImmerChangeset } from 'ember-immer-changeset'; | ||
|
||
import { setupIntl } from 'ember-intl/test-support'; | ||
|
||
import type { LoginChangeset } from 'ember-boilerplate/changesets/login'; | ||
import { LoginChangeset } from 'ember-boilerplate/changesets/login'; | ||
import LoginForm from 'ember-boilerplate/components/forms/login'; | ||
|
||
interface LoginTestContext extends TestContext { | ||
interface LoginTestContext { | ||
changeset: LoginChangeset; | ||
saveFunction: (changeset: Changeset) => void; | ||
validationSchema: typeof loginSchema; | ||
|
@@ -23,18 +23,31 @@ module('Integration | Component | FormsLogin', function (hooks) { | |
setupRenderingTest(hooks); | ||
setupIntl(hooks, ['fr-fr']); | ||
|
||
function renderForm(context: LoginTestContext) { | ||
return render<LoginTestContext>( | ||
<template> | ||
<LoginForm | ||
@validationSchema={{context.validationSchema}} | ||
@changeset={{context.changeset}} | ||
@saveFunction={{context.saveFunction}} | ||
/> | ||
</template> | ||
); | ||
} | ||
|
||
test('Create (empty changeset)', async function (assert) { | ||
this.set('changeset', new ImmerChangeset({})); | ||
this.set('validationSchema', loginSchema); | ||
this.set('saveFunction', (changeset: Changeset) => { | ||
let validationSchema = loginSchema; | ||
let saveFunction = (changeset: Changeset) => { | ||
assert.step('saveFunction'); | ||
assert.strictEqual(changeset.get('email'), '[email protected]'); | ||
assert.strictEqual(changeset.get('password'), 'edited'); | ||
}); | ||
}; | ||
|
||
await render<LoginTestContext>( | ||
hbs`<Forms::Login @validationSchema={{this.validationSchema}} @changeset={{this.changeset}} @saveFunction={{this.saveFunction}} />`, | ||
); | ||
await renderForm({ | ||
changeset: new LoginChangeset({} as never), | ||
validationSchema, | ||
saveFunction, | ||
}); | ||
|
||
assert.dom('[data-test-input="email"] input').hasValue(''); | ||
assert.dom('[data-test-input="password"] input').hasValue(''); | ||
|
@@ -46,24 +59,23 @@ module('Integration | Component | FormsLogin', function (hooks) { | |
}); | ||
|
||
test('Edit (populated changeset)', async function (assert) { | ||
this.set( | ||
'changeset', | ||
new ImmerChangeset({ | ||
email: 'hello', | ||
password: 'hello', | ||
}), | ||
); | ||
this.set('validationSchema', loginSchema); | ||
let changeset = new ImmerChangeset({ | ||
email: 'hello', | ||
password: 'hello', | ||
}); | ||
let validationSchema = loginSchema; | ||
|
||
this.set('saveFunction', (changeset: Changeset) => { | ||
let saveFunction = (changeset: Changeset) => { | ||
assert.strictEqual(changeset.get('email'), '[email protected]'); | ||
assert.strictEqual(changeset.get('password'), 'helloEdited'); | ||
assert.step('saveFunction'); | ||
}); | ||
}; | ||
|
||
await render<LoginTestContext>( | ||
hbs`<Forms::Login @validationSchema={{this.validationSchema}} @saveFunction={{this.saveFunction}} @changeset={{this.changeset}}/>`, | ||
); | ||
await renderForm({ | ||
changeset, | ||
validationSchema, | ||
saveFunction, | ||
}); | ||
|
||
assert.dom('[data-test-input="email"] input').hasValue('hello'); | ||
assert.dom('[data-test-input="password"] input').hasValue('hello'); | ||
|
This file was deleted.
Oops, something went wrong.
67 changes: 0 additions & 67 deletions
67
tests/integration/components/yeti-table/pagination/component.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.