-
Notifications
You must be signed in to change notification settings - Fork 1
MAS-129 Daily email all fields no branding #34
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
base: master
Are you sure you want to change the base?
Changes from all commits
d39d527
fa92be8
9d7d7d6
794ce4f
756da19
6adbe19
12df1d8
fa65508
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <div class='evidenceType'><strong>Some evidence type</strong><div class='item'>Some Title<br>Some source<br>Some speciality<br>Some short summary<br><a href='https://www.medicinesresources.nhs.uk/abc'>SPS Comment</a></div></div><div class='evidenceType'><strong>Some evidence type 2</strong><div class='item'>Some Title<br>Some source<br>Some speciality 2<br>Some short summary<br><a href='https://www.medicinesresources.nhs.uk/abc'>SPS Comment</a></div></div> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <div class='evidenceType'><strong>Some evidence type</strong><div class='item'>Some Title<br>Some source<br>Some speciality<br>Some short summary<br><a href='https://www.medicinesresources.nhs.uk/abc'>SPS Comment</a></div><div class='item'>Some Title<br>Some source<br>Some speciality<br>Some short summary<br><a href='https://www.medicinesresources.nhs.uk/abc'>SPS Comment</a></div></div> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <div class='evidenceType'><strong>Some evidence type</strong><div class='item'>Some Title<br>Some source<br>Some speciality<br>Some short summary<br><a href='https://www.medicinesresources.nhs.uk/abc'>SPS Comment</a></div></div> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <div class='evidenceType'><strong>Some evidence type</strong><div class='item'>Some Title<br>Some source<br>Some speciality | Another speciality<br>Some short summary<br><a href='https://www.medicinesresources.nhs.uk/abc'>SPS Comment</a></div></div> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| using MAS.Models; | ||
| using MAS.Tests.Infrastructure; | ||
| using Shouldly; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
| using Xunit; | ||
|
|
||
| namespace MAS.Tests.UnitTests | ||
| { | ||
| public class DailyEmailTests : TestBase | ||
| { | ||
| Item exampleItem = new Item() | ||
| { | ||
| Id = "123", | ||
| Title = "Some Title", | ||
| Slug = "abc", | ||
| ShortSummary = "Some short summary", | ||
| ResourceLinks = "", | ||
| Comment = "", | ||
| Speciality = new List<Speciality> | ||
| { | ||
| new Speciality() | ||
| { | ||
| Key = "1a", | ||
| Title = "Some speciality", | ||
|
|
||
| } | ||
| }, | ||
| EvidenceType = new EvidenceType() | ||
| { | ||
| Key = "1b", | ||
| Title = "Some evidence type" | ||
| }, | ||
| Source = new Source() | ||
| { | ||
| Id = "1c", | ||
| Title = "Some source" | ||
| } | ||
| }; | ||
| Item exampleItem2 = new Item() | ||
| { | ||
| Id = "123", | ||
| Title = "Some Title", | ||
| Slug = "abc", | ||
| ShortSummary = "Some short summary", | ||
| ResourceLinks = "", | ||
| Comment = "", | ||
| Speciality = new List<Speciality> | ||
| { | ||
| new Speciality() | ||
| { | ||
| Key = "1a", | ||
| Title = "Some speciality 2", | ||
|
|
||
| } | ||
| }, | ||
| EvidenceType = new EvidenceType() | ||
| { | ||
| Key = "1c", | ||
| Title = "Some evidence type 2" | ||
| }, | ||
| Source = new Source() | ||
| { | ||
| Id = "1c", | ||
| Title = "Some source" | ||
| } | ||
| }; | ||
|
|
||
| [Fact] | ||
| public void CanCreateSingleItemEmail() | ||
| { | ||
| var email = new DailyEmail() | ||
| { | ||
| Items = new List<Item>() | ||
| { | ||
| exampleItem | ||
| } | ||
| }; | ||
|
|
||
| var expectedHtml = "<div class='evidenceType'><strong>Some evidence type</strong><div class='item'>Some Title<br>Some source<br>Some speciality<br>Some short summary<br><a href='https://www.medicinesresources.nhs.uk/abc'>SPS Comment</a></div></div>"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should use the extension method ShouldMatchApproved
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good shout! |
||
|
|
||
| expectedHtml.ShouldMatchApproved(email.HTML); | ||
|
|
||
| } | ||
|
|
||
| [Fact] | ||
| public void CanCreateEmailWithTwoItemsSharingEvidenceType() | ||
| { | ||
| var email = new DailyEmail() | ||
| { | ||
| Items = new List<Item>() | ||
| { | ||
| exampleItem, | ||
| exampleItem | ||
| } | ||
| }; | ||
|
|
||
| var expectedHtml = "<div class='evidenceType'><strong>Some evidence type</strong><div class='item'>Some Title<br>Some source<br>Some speciality<br>Some short summary<br><a href='https://www.medicinesresources.nhs.uk/abc'>SPS Comment</a></div><div class='item'>Some Title<br>Some source<br>Some speciality<br>Some short summary<br><a href='https://www.medicinesresources.nhs.uk/abc'>SPS Comment</a></div></div>"; | ||
| expectedHtml.ShouldMatchApproved(email.HTML); | ||
|
|
||
| } | ||
|
|
||
| [Fact] | ||
| public void CanCreateEmailWithTwoItemsDifferentEvidenceType() | ||
| { | ||
| var email = new DailyEmail() | ||
| { | ||
| Items = new List<Item>() | ||
| { | ||
| exampleItem, | ||
| exampleItem2 | ||
| } | ||
| }; | ||
|
|
||
| var expectedHtml = "<div class='evidenceType'><strong>Some evidence type</strong><div class='item'>Some Title<br>Some source<br>Some speciality<br>Some short summary<br><a href='https://www.medicinesresources.nhs.uk/abc'>SPS Comment</a></div></div><div class='evidenceType'><strong>Some evidence type 2</strong><div class='item'>Some Title<br>Some source<br>Some speciality 2<br>Some short summary<br><a href='https://www.medicinesresources.nhs.uk/abc'>SPS Comment</a></div></div>"; | ||
| expectedHtml.ShouldMatchApproved(email.HTML); | ||
|
|
||
| } | ||
|
|
||
| [Fact] | ||
| public void ItemsWithManySpecialitiesRenderCorrectly() | ||
| { | ||
| exampleItem.Speciality.Add(new Speciality() { Key = "abcd", Title = "Another speciality" }); | ||
| var email = new DailyEmail() | ||
| { | ||
| Items = new List<Item>() | ||
| { | ||
| exampleItem | ||
| } | ||
| }; | ||
|
|
||
| var expectedHtml = "<div class='evidenceType'><strong>Some evidence type</strong><div class='item'>Some Title<br>Some source<br>Some speciality | Another speciality<br>Some short summary<br><a href='https://www.medicinesresources.nhs.uk/abc'>SPS Comment</a></div></div>"; | ||
| expectedHtml.ShouldMatchApproved(email.HTML); | ||
|
|
||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace MAS.Models | ||
| { | ||
| public class DailyEmail | ||
| { | ||
| public List<Item> Items { get; set; } | ||
|
|
||
| public List<IGrouping<string, Item>> GroupedItems | ||
| { | ||
| get | ||
| { | ||
| return Items.GroupBy(x => x.EvidenceType.Title).ToList(); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| public string HTML | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure why this is a model
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It makes sense to me to have a daily email model. I agree with you that HTML property may not belong in this class - but im unsure as I've seen business logic in models before and the HTML is after all just a string property returning a string interpretation of the rest of the class. The HTML properties logic could be moved into a separate service which perhaps returns a dynamic view. However, for this card I think what we currently have is ok. Perhaps in the branding card, we can look at this. What do you think? |
||
| { | ||
| get | ||
| { | ||
| var body = new StringBuilder(); | ||
|
|
||
| foreach (var group in GroupedItems) | ||
| { | ||
| var evidenceType = group.Key; | ||
|
|
||
| body.Append("<div class='evidenceType'>"); | ||
| body.Append("<strong>" + evidenceType + "</strong>"); | ||
|
|
||
| foreach(var item in group) | ||
| { | ||
| body.Append("<div class='item'>"); | ||
| body.Append(item.Title); | ||
| body.Append("<br>"); | ||
| body.Append(item.Source.Title); | ||
| body.Append("<br>"); | ||
| body.Append(String.Join(" | ", item.Speciality.Select(x => x.Title))); | ||
| body.Append("<br>"); | ||
| body.Append(item.ShortSummary); | ||
| body.Append("<br>"); | ||
| body.Append("<a href='https://www.medicinesresources.nhs.uk/" + @item.Slug + "'>SPS Comment</a>"); | ||
| body.Append("</div>"); | ||
| } | ||
|
|
||
| body.Append("</div>"); | ||
| } | ||
|
|
||
| return body.ToString(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace MAS.Models | ||
| { | ||
| public class Speciality | ||
| { | ||
| public string Title { get; set; } | ||
|
|
||
| public string Key { get; set; } | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.