Skip to content

Commit

Permalink
feat(mon-pix): add tests for new SigninForm
Browse files Browse the repository at this point in the history
  • Loading branch information
bpetetot committed Sep 25, 2024
1 parent 14fa275 commit d4fd0aa
Show file tree
Hide file tree
Showing 5 changed files with 395 additions and 80 deletions.
6 changes: 5 additions & 1 deletion mon-pix/app/components/authentication/signin-form.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export default class SigninForm extends Component {
}
}

get isFormDisabled() {
return !this.login || !this.password;
}

@action
updateLogin(event) {
this.login = event.target.value?.trim();
Expand Down Expand Up @@ -148,7 +152,7 @@ export default class SigninForm extends Component {
</div>
</fieldset>

<PixButton @type="submit" @isLoading={{this.isLoading}} @size="large">
<PixButton @type="submit" @isLoading={{this.isLoading}} @isDisabled={{this.isFormDisabled}} @size="large">
{{t "pages.sign-in.actions.submit"}}
</PixButton>
</form>
Expand Down
71 changes: 0 additions & 71 deletions mon-pix/tests/acceptance/authentication-test.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import { visit } from '@1024pix/ember-testing-library';
import { click, currentURL, fillIn } from '@ember/test-helpers';
import { setupMirage } from 'ember-cli-mirage/test-support';
import { t } from 'ember-intl/test-support';
import { setupApplicationTest } from 'ember-qunit';
import { module, test } from 'qunit';

import { authenticateByEmail, authenticateByUsername } from '../../helpers/authentication';
import setupIntl from '../../helpers/setup-intl';

module('Acceptance | Authentication redirections', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
setupIntl(hooks);

let user;

hooks.beforeEach(function () {
user = server.create('user', 'withEmail');
});

module('when "New authentication design" feature toggle is disabled', function (hooks) {
hooks.beforeEach(function () {
server.create('feature-toggle', {
id: 0,
isNewAuthenticationDesignEnabled: false,
});
});

module('Success cases', function () {
module('Accessing to the default page page while disconnected', function () {
test('should redirect to the connexion page', async function (assert) {
// when
await visit('/');

// then
assert.strictEqual(currentURL(), '/connexion');
});
});

module('Log-in phase', function () {
test('should redirect to /accueil after connexion', async function (assert) {
// when
await authenticateByEmail(user);

// then
assert.strictEqual(currentURL(), '/accueil');
});
});
});

module('Error case', function () {
test('should stay in /connexion, when authentication failed', async function (assert) {
// given
const screen = await visit('/connexion');
await fillIn(screen.getByRole('textbox', { name: 'Adresse e-mail ou identifiant' }), '[email protected]');
await fillIn(screen.getByLabelText('Mot de passe'), 'Pix20!!');

// when
await click(screen.getByRole('button', { name: t('pages.sign-in.actions.submit') }));

// then
assert.strictEqual(currentURL(), '/connexion');
});

module('when user should change password', function () {
test('should redirect to /update-expired-password', async function (assert) {
// given
user = server.create('user', 'withUsername', 'shouldChangePassword');

// when
await authenticateByUsername(user);

// then
assert.strictEqual(currentURL(), '/mise-a-jour-mot-de-passe-expire');
});
});
});
});

module('when "New authentication design" feature toggle is enabled', function (hooks) {
hooks.beforeEach(function () {
server.create('feature-toggle', {
id: 0,
isNewAuthenticationDesignEnabled: true,
});
});

module('Success cases', function () {
module('Accessing to the default page page while disconnected', function () {
test('should redirect to the connexion page', async function (assert) {
// when
await visit('/');

// then
assert.strictEqual(currentURL(), '/connexion');
});
});

module('Log-in phase', function () {
test('should redirect to /accueil after connexion', async function (assert) {
// when
await authenticateByEmail(user);

// then
assert.strictEqual(currentURL(), '/accueil');
});
});
});

module('Error case', function () {
test('should stay in /connexion, when authentication failed', async function (assert) {
// given
const screen = await visit('/connexion');
await fillIn(screen.getByRole('textbox', { name: 'Adresse e-mail ou identifiant' }), '[email protected]');
await fillIn(screen.getByLabelText('Mot de passe'), 'Pix20!!');

// when
await click(screen.getByRole('button', { name: t('pages.sign-in.actions.submit') }));

// then
assert.strictEqual(currentURL(), '/connexion');
});

module('when user should change password', function () {
test('should redirect to /update-expired-password', async function (assert) {
// given
user = server.create('user', 'withUsername', 'shouldChangePassword');

// when
await authenticateByUsername(user);

// then
assert.strictEqual(currentURL(), '/mise-a-jour-mot-de-passe-expire');
});
});
});
});
});
15 changes: 7 additions & 8 deletions mon-pix/tests/acceptance/authentication/login-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module('Acceptance | Login', function (hooks) {
setupMirage(hooks);
setupIntl(hooks);

module('when feature toggle is false', function (hooks) {
module('when "New authentication design" feature toggle is disabled', function (hooks) {
hooks.beforeEach(function () {
server.create('feature-toggle', {
id: 0,
Expand Down Expand Up @@ -78,20 +78,19 @@ module('Acceptance | Login', function (hooks) {
});
});

module('when feature toggle is true', function (hooks) {
module('when "New authentication design" feature toggle is enabled', function (hooks) {
hooks.beforeEach(function () {
server.create('feature-toggle', {
id: 0,
isNewAuthenticationDesignEnabled: true,
});
server.create('feature-toggle', { id: 0, isNewAuthenticationDesignEnabled: true });
});

test('displays the new layout with a footer', async function (assert) {
test('displays the authentication layout with a footer', async function (assert) {
// when
const screen = await visit('/connexion');

// then
assert.dom(screen.getByRole('contentinfo')).exists();
});

module('when current url does not contain french tld (.fr)', function () {
module('when accessing the login page with "English" as selected language', function () {
module('when the user select "Français" as his language', function () {
Expand All @@ -104,7 +103,7 @@ module('Acceptance | Login', function (hooks) {

// then
assert.strictEqual(currentURL(), '/connexion');
assert.dom(screen.getByRole('heading', { name: t('pages.sign-in.title'), level: 1 })).exists();
assert.dom(screen.getByRole('heading', { name: t('pages.sign-in.first-title'), level: 1 })).exists();
assert.dom(screen.getByRole('button', { name: 'Sélectionnez une langue' })).exists();
});
});
Expand Down
Loading

0 comments on commit d4fd0aa

Please sign in to comment.