Add module-specific settings CTAs to error report emails. - #13253
Add module-specific settings CTAs to error report emails.#13253mehidi258 wants to merge 1 commit into
Conversation
📦 Build files for 20fff8a:
🎭 Playwright reports for 20fff8a: |
| /** | ||
| * Gets template subject mappings that differ from their title. | ||
| * | ||
| * Only templates whose email subject must diverge from their | ||
| * in-email title/heading need an entry here; every other template | ||
| * falls back to `get_title()` in `get_subject()`. | ||
| * | ||
| * @since n.e.x.t | ||
| * | ||
| * @return array Mapping of template names to subject strings. | ||
| */ | ||
| protected static function get_all_subjects() { | ||
| return array( | ||
| 'error-email' => __( 'Action needed: your Site Kit report couldn’t be generated', 'google-site-kit' ), | ||
| ); | ||
| } |
There was a problem hiding this comment.
This is oddly named and described, was it done by an LLM by any chance?
"get_all_subjects" implies that this will return all subjects available, but that's not the case. I'd expect this function to be named get_templates_with_custom_subjects.
And the comment/description seems like it would be better written as:
| /** | |
| * Gets template subject mappings that differ from their title. | |
| * | |
| * Only templates whose email subject must diverge from their | |
| * in-email title/heading need an entry here; every other template | |
| * falls back to `get_title()` in `get_subject()`. | |
| * | |
| * @since n.e.x.t | |
| * | |
| * @return array Mapping of template names to subject strings. | |
| */ | |
| protected static function get_all_subjects() { | |
| return array( | |
| 'error-email' => __( 'Action needed: your Site Kit report couldn’t be generated', 'google-site-kit' ), | |
| ); | |
| } | |
| /** | |
| * Get a mapping of all templates with custom subjects (eg. ones | |
| * that differ from their title). | |
| * | |
| * Templates not in this mapping use `get_title()` as their subject. | |
| * | |
| * @since n.e.x.t | |
| * | |
| * @return array Mapping of template names to subject strings. | |
| */ | |
| protected static function get_all_subjects() { | |
| return array( | |
| 'error-email' => __( 'Action needed: your Site Kit report couldn’t be generated', 'google-site-kit' ), | |
| ); | |
| } |
| * Only the four module-specific error keys define a CTA, each | ||
| * linking to that module's settings screen; every other key | ||
| * (including the generic `error-email` key) defines no CTA. | ||
| * |
There was a problem hiding this comment.
The documentation here will need to be updated every time we change the content here, which seems needless; it's evident from the simple code here what's happening. I think we can omit this. 🙂
| * Only the four module-specific error keys define a CTA, each | |
| * linking to that module's settings screen; every other key | |
| * (including the generic `error-email` key) defines no CTA. | |
| * |
| * | ||
| * @since n.e.x.t | ||
| * | ||
| * @param string $content_key Content key (e.g. 'error-email-report-analytics-4'). |
There was a problem hiding this comment.
Isn't this the name of the template? Why use a generic name like "content key"?
| $subject = Content_Map::get_subject( 'error-email' ); | ||
| $title = Content_Map::get_title( 'error-email' ); | ||
|
|
||
| $this->assertSame( 'Action needed: your Site Kit report couldn’t be generated', $subject, 'Generic error email subject should match the corrected copy.' ); |
There was a problem hiding this comment.
What do you mean by "corrected copy"? I'm not sure what that means. 🤔
| $title = Content_Map::get_title( 'error-email' ); | ||
|
|
||
| $this->assertSame( 'Action needed: your Site Kit report couldn’t be generated', $subject, 'Generic error email subject should match the corrected copy.' ); | ||
| $this->assertSame( 'Email reports are failing to send', $title, 'Generic error email title/heading should remain unchanged.' ); |
There was a problem hiding this comment.
Remain unchanged from what?
|
|
||
| $this->assertSame( 'Action needed: your Site Kit report couldn’t be generated', $subject, 'Generic error email subject should match the corrected copy.' ); | ||
| $this->assertSame( 'Email reports are failing to send', $title, 'Generic error email title/heading should remain unchanged.' ); | ||
| $this->assertNotSame( $subject, $title, 'Generic error email subject should differ from its title.' ); |
There was a problem hiding this comment.
Arguably this isn't needed given the tests above cover this scenario…
| $this->assertNotSame( $subject, $title, 'Generic error email subject should differ from its title.' ); | |
| $this->assertNotSame( $subject, $title, 'Error emails should use a custom subject, not the title of the email.' ); |
| $subject = Content_Map::get_subject( $content_key ); | ||
| $title = Content_Map::get_title( $content_key ); | ||
|
|
||
| $this->assertSame( $title, $subject, "Subject for '$content_key' should equal its title." ); |
There was a problem hiding this comment.
Isn't this the default behaviour? What's the value in asserting it for each template?
| $cta = Content_Map::get_cta( $content_key, $this->build_golinks() ); | ||
|
|
||
| $this->assertSame( 'Request access', $cta['label'], "CTA label for '$content_key' should be 'Request access'." ); | ||
| $this->assertStringContainsString( 'module=' . $module_slug, $cta['url'], "CTA url for '$content_key' should target the $module_slug module settings." ); |
There was a problem hiding this comment.
This line uses a mix of string interpolation and concatenation, let's just use one (interpolation) for consistency/ease-of-reading 😅
| /** | ||
| * @dataProvider data_report_ctas | ||
| */ | ||
| public function test_get_cta_returns_go_to_settings_for_report_keys( $content_key, $module_slug ) { | ||
| $cta = Content_Map::get_cta( $content_key, $this->build_golinks() ); | ||
|
|
||
| $this->assertSame( 'Go to settings', $cta['label'], "CTA label for '$content_key' should be 'Go to settings'." ); | ||
| $this->assertStringContainsString( 'module=' . $module_slug, $cta['url'], "CTA url for '$content_key' should target the $module_slug module settings." ); | ||
| } | ||
|
|
||
| public function data_report_ctas() { | ||
| return array( | ||
| 'search-console' => array( 'error-email-report-search-console', 'search-console' ), | ||
| 'analytics-4' => array( 'error-email-report-analytics-4', 'analytics-4' ), | ||
| ); | ||
| } |
There was a problem hiding this comment.
These data provider tests are pretty roundabout and harder to read than just placing the content right into the tests. I know we use them elsewhere, but for two lines… I think it'd be just as many lines of code to manually write each test's code and assertions… let's do that instead because it'll be MUCH easier to read and make sense of, which is very valuable in tests.
Tests aren't about "Don't Repeat Yourself", they're about making clear the intention of the code, so I think it's fine (arguably better) if they're a bit verbose in exchange for being more immediately understandable.
Summary
Related issue(s):
PR Author Checklist
Do not alter or remove anything below. The following sections will be managed by moderators only.
Code Reviewer Checklist
Merge Reviewer Checklist