Skip to content

Commit

Permalink
change form validation rules to prevent empty school admin emails fro…
Browse files Browse the repository at this point in the history
…m being submitted.

the corresponding backend model asserts that school admin emails have to
be at least one character long.
this realigns the frontend form validation rules with the asserts on the
backend data model.
  • Loading branch information
stopfstedt committed Jul 15, 2024
1 parent fcec5a7 commit 23b7b83
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/frontend/app/components/school/emails-editor.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { dropTask } from 'ember-concurrency';
import { validatable, Custom, IsEmail, Length } from 'ilios-common/decorators/validation';
import { validatable, Custom, IsEmail, Length, NotBlank } from 'ilios-common/decorators/validation';
import { action } from '@ember/object';
import { service } from '@ember/service';
import { isBlank, typeOf } from '@ember/utils';
Expand All @@ -11,7 +11,7 @@ import EmailValidator from 'validator/es/lib/isEmail';
export default class SchoolEmailsEditorComponent extends Component {
@service intl;

@tracked @Length(0, 100) @IsEmail() administratorEmail =
@tracked @Length(1, 100) @NotBlank() @IsEmail() administratorEmail =
this.args.school.iliosAdministratorEmail || '';
@tracked
@Length(0, 300)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module('Integration | Component | school/emails-editor', function (hooks) {
assert.notOk(component.changeAlertRecipients.hasError);
});

test('save with empty data', async function (assert) {
test('save with empty change alerts recipients', async function (assert) {
assert.expect(8);
const school = this.server.create('school', {
iliosAdministratorEmail: '[email protected]',
Expand All @@ -58,7 +58,7 @@ module('Integration | Component | school/emails-editor', function (hooks) {
const schoolModel = await this.owner.lookup('service:store').findRecord('school', school.id);
this.set('school', schoolModel);
this.set('save', (administratorEmail, changeAlertRecipients) => {
assert.strictEqual(administratorEmail, '');
assert.strictEqual(administratorEmail, '[email protected]');
assert.strictEqual(changeAlertRecipients, '');
});
await render(
Expand All @@ -71,14 +71,37 @@ module('Integration | Component | school/emails-editor', function (hooks) {
);
assert.notOk(component.administratorEmail.hasError);
assert.notOk(component.changeAlertRecipients.hasError);
await component.administratorEmail.set('');
await component.changeAlertRecipients.set('');
await component.save();
assert.notOk(component.administratorEmail.hasError);
assert.notOk(component.changeAlertRecipients.hasError);
});

test('validation fails', async function (assert) {
test('validation fails if given admin email is empty', async function (assert) {
assert.expect(6);
const school = this.server.create('school', {
iliosAdministratorEmail: '[email protected]',
changeAlertRecipients: '[email protected], [email protected]',
});
const schoolModel = await this.owner.lookup('service:store').findRecord('school', school.id);
this.set('school', schoolModel);
await render(
hbs`<School::EmailsEditor @school={{this.school}} @save={{(noop)}} @cancel={{(noop)}} />`,
);
assert.strictEqual(component.administratorEmail.value, '[email protected]');
assert.strictEqual(
component.changeAlertRecipients.value,
'[email protected], [email protected]',
);
assert.notOk(component.administratorEmail.hasError);
assert.notOk(component.changeAlertRecipients.hasError);
await component.administratorEmail.set('');
await component.save();
assert.ok(component.administratorEmail.hasError);
assert.notOk(component.changeAlertRecipients.hasError);
});

test('validation fails if input contains invalid emails', async function (assert) {
const school = this.server.create('school');
const schoolModel = await this.owner.lookup('service:store').findRecord('school', school.id);
this.set('school', schoolModel);
Expand Down

0 comments on commit 23b7b83

Please sign in to comment.