-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add conditional "rejected" badge (#580)
* Add `has-rejected-doc` helper * Refactor out helpers * Grammar tweaks * Badge logic refactor
- Loading branch information
Showing
9 changed files
with
165 additions
and
96 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import Component from "@glimmer/component"; | ||
import { HermesDocument } from "hermes/types/document"; | ||
import Person from "hermes/components/person"; | ||
|
||
interface EditableFieldReadValuePersonSignature { | ||
Args: { | ||
email: string; | ||
document?: HermesDocument; | ||
}; | ||
} | ||
|
||
export default class EditableFieldReadValuePerson extends Component<EditableFieldReadValuePersonSignature> { | ||
/** | ||
* Whether the document has been approved by the user. | ||
* True if the email is in the approvedBy list. | ||
* Dictates the badge on the Person component. | ||
*/ | ||
protected get hasApprovedDoc(): boolean { | ||
const { document, email } = this.args; | ||
return !!document?.approvedBy?.some((e) => e === email); | ||
} | ||
|
||
/** | ||
* Whether the document has been rejected by the user. | ||
* True if the email is in the changesRequestedBy list. | ||
* Dictates the badge on the Person component. | ||
*/ | ||
protected get hasRejectedDoc(): boolean { | ||
const { document, email } = this.args; | ||
return !!document?.changesRequestedBy?.some((e) => e === email); | ||
} | ||
|
||
/** | ||
* The conditional badge value to pass to the Person component. | ||
* Return badges for "approved" and "rejected" scenarios. | ||
*/ | ||
protected get maybeBadgeValue(): string | undefined { | ||
if (this.hasApprovedDoc) return "approved"; | ||
if (this.hasRejectedDoc) return "rejected"; | ||
} | ||
|
||
<template> | ||
<Person @badge={{this.maybeBadgeValue}} @email={{@email}} /> | ||
</template> | ||
} | ||
|
||
declare module "@glint/environment-ember-loose/registry" { | ||
export default interface Registry { | ||
"EditableField::ReadValue::Person": typeof EditableFieldReadValuePerson; | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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
69 changes: 69 additions & 0 deletions
69
web/tests/integration/components/editable-field/read-value/person-test.ts
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { render } from "@ember/test-helpers"; | ||
import { hbs } from "ember-cli-htmlbars"; | ||
import { MirageTestContext, setupMirage } from "ember-cli-mirage/test-support"; | ||
import { setupRenderingTest } from "ember-qunit"; | ||
import { TEST_USER_EMAIL, authenticateTestUser } from "hermes/mirage/utils"; | ||
import { HermesDocument } from "hermes/types/document"; | ||
import { module, test } from "qunit"; | ||
|
||
const BADGE = "[data-test-person-badge]"; | ||
const APPROVED_BADGE = '[data-test-person-badge-type="approved"]'; | ||
const REJECTED_BADGE = '[data-test-person-badge-type="rejected"]'; | ||
const ICON = "[data-test-person-badge-icon]"; | ||
|
||
interface Context extends MirageTestContext { | ||
document: HermesDocument; | ||
email: string; | ||
} | ||
|
||
module( | ||
"Integration | Component | editable-field/read-value/person", | ||
function (hooks) { | ||
setupRenderingTest(hooks); | ||
setupMirage(hooks); | ||
|
||
hooks.beforeEach(function (this: Context) { | ||
authenticateTestUser(this); | ||
}); | ||
|
||
test("it renders a conditional badge", async function (this: Context, assert) { | ||
this.set("document", { | ||
approvedBy: [], | ||
changesRequestedBy: [], | ||
}); | ||
|
||
this.set("email", TEST_USER_EMAIL); | ||
|
||
await render<Context>(hbs` | ||
<EditableField::ReadValue::Person | ||
@email={{this.email}} | ||
@document={{this.document}} | ||
/> | ||
`); | ||
|
||
assert.dom(BADGE).doesNotExist(); | ||
|
||
this.set("document", { | ||
approvedBy: [TEST_USER_EMAIL], | ||
}); | ||
|
||
assert.dom(APPROVED_BADGE).exists(); | ||
|
||
assert | ||
.dom(ICON) | ||
.hasClass("text-color-palette-green-200") | ||
.hasAttribute("data-test-icon", "check-circle-fill"); | ||
|
||
this.set("document", { | ||
changesRequestedBy: [TEST_USER_EMAIL], | ||
}); | ||
|
||
assert.dom(REJECTED_BADGE).exists(); | ||
|
||
assert | ||
.dom(ICON) | ||
.hasClass("text-color-foreground-faint") | ||
.hasAttribute("data-test-icon", "x-circle-fill"); | ||
}); | ||
}, | ||
); |
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 was deleted.
Oops, something went wrong.