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

change form validation rules to prevent empty school admin emails fro… #7966

Merged
merged 1 commit into from
Jul 15, 2024
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 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: 'admin@school.edu',
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, 'admin@school.edu');
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: 'admin@school.edu',
changeAlertRecipients: 'email1@school.edu, email2@school.edu',
});
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, 'admin@school.edu');
assert.strictEqual(
component.changeAlertRecipients.value,
'email1@school.edu, email2@school.edu',
);
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