Skip to content

Commit

Permalink
replaces usage of has-error-for Resource in NewLearningmaterial compo…
Browse files Browse the repository at this point in the history
…nent.
  • Loading branch information
stopfstedt committed Nov 4, 2024
1 parent bfbfff9 commit b00ab20
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
data-test-copyright-agreement
>
{{t "general.copyrightAgreement"}}
{{#if (has-error-for this "copyrightPermission")}}
{{#if this.hasErrorForCopyrightPermission}}
<br>
<span class="validation-error-message" data-test-agreement-validation-error-message>
{{t "errors.agreementRequired"}}
Expand Down
11 changes: 11 additions & 0 deletions packages/ilios-common/addon/components/new-learningmaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ export default class NewLearningmaterialComponent extends Component {

userModel = new TrackedAsyncData(this.currentUser.getModel());

@cached
get hasErrorForCopyrightPermissionData() {
return new TrackedAsyncData(this.hasErrorFor('copyrightPermission'));
}

get hasErrorForCopyrightPermission() {
return this.hasErrorForCopyrightPermissionData.isResolved
? this.hasErrorForCopyrightPermissionData.value
: false;
}

@cached
get currentUserModel() {
return this.userModel.isResolved ? this.userModel.value : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,21 @@ module('Integration | Component | new learningmaterial', function (hooks) {
await component.save();
assert.strictEqual(component.fileUpload.validationErrors[0].text, 'Missing file');
});

test('validate copyright permission', async function (assert) {
this.set('type', 'file');
await render(hbs`<NewLearningmaterial
@type={{this.type}}
@learningMaterialStatuses={{(array)}}
@learningMaterialUserRoles={{(array)}}
@save={{(noop)}}
@cancel={{(noop)}}
/>`);
assert.notOk(component.hasAgreementValidationError);
await component.save();
assert.ok(component.hasAgreementValidationError);
await component.agreement();
await component.save();
assert.notOk(component.hasAgreementValidationError);
});
});

0 comments on commit b00ab20

Please sign in to comment.