Add PHPUnit tests

Functional Javascript Test cases

Logged in as user with "access announcements" permission for first time.

  1. Alert Icon should display a red dot over it.
  2. All alerts items should display as unread alerts, having darker background and dot icon to indicate unread.

Logged in as user with "access announcements" permission for second time.

  1. Alert Icon should not display a red dot over it.
  2. All alerts icons should display as read alerts, having light background and no dot icon.

Login as another user and access the alert icon

  1. Alert Icon should display a red dot over it.
  2. All should be shown as unread

User with out "access announcements" permission.

  1. No alert icon should display

Add new items to the announce-feed and logged in as a user who has "access announcements" permission.

  1. Alert Icon should display a red dot over it.
  2. The new items in the feed should show as unread. Old items should show as read

Access the alert icon again

  1. Alert Icon should not display a red dot over it.
  2. All items should show as read

Login as another user and access the alert icon

  1. Alert Icon should display a red dot over it.
  2. The new items for that user should be shown as unread

Remove items from the feed

  1. Removed items should not display in the announcement model
  2. If the removed item is only item the user hasn't read the the red dot should not show

Empty feed

  1. Show a message, Feed is empty

Kernel Test cases

Kernel test for the 2 services on the public methods

Issue fork announce-3198730

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

vimaljoseph created an issue. See original summary.

vimaljoseph’s picture

Issue summary: View changes
tedbow’s picture

Version: » 1.x-dev
Issue summary: View changes
tedbow’s picture

Issue summary: View changes
tedbow’s picture

A few suggestions on where to look at core for similar tests.

  1. You will need a test module that can serve multiple fake json feeds. For example serve a feed with 1 item, have the user look at the feed and then serve another with a new item to ensure the user gets the new item indication.

    See this merge request https://git.drupalcode.org/project/drupal/-/merge_requests/284 because it also deals with a single json feed like this module. You can checkout that branch and then look at:
    core/modules/system/tests/modules/advisory_feed_test: This is a test module that serves the feed. Look at the route advisory_feed_test.json_test in this test module for how it serves the json. The actual json files are in core/modules/system/tests/fixtures/psa_feed

    You may be able to get away with just directly using the fixtures and not having a controller method like\Drupal\advisory_feed_test\Controller\AdvisoryTestController::getPsaJson(). We had to have the controller method there because we need to change the Json files slightly.

  2. One difference between the merge request I mention above and the current Announce module is that in the Announce module the URL for retrieving the feed is set in config and the merge request uses a hard-coded URL(see core/modules/system/src/SecurityAdvisories/SecurityAdvisoriesFetcher.php and search for <code>updates.drupal.org/psa.json).

    Using the config URL is easier for testing but it does open the possibility that someone could change the URL to a different json feed. If we only want to support the json feed from drupal.org I would suggest this module also switch to a hard-coded feed URL.

    To test the hard-coded feed the test module uses a service decorator on the http_client service.
    See: AdvisoriesTestHttpClient
    and the service definition http_client.advisory_feed_test
    The service also has helper method setting the endpoint to test: \Drupal\advisory_feed_test\AdvisoriesTestHttpClient::setTestEndpoint()

    You should be able to copy this test module, do some renames and remove the parts you don't need.

  3. core/modules/system/tests/src/Functional/SecurityAdvisories/SecurityAdvisoryTest.php is the function test that uses the fake json feed.

    In your case you will probably want this to be FunctionalJavascript test to opening the announcements dialog.

    see core/modules/workspaces/tests/src/FunctionalJavascript/WorkspaceToolbarIntegrationTest.php for example of FunctionalJavascript test that opens the off-canvas dialog that this test is also using

  4. You will also need tests for services announce.fetcher and announce.user_status

    This should probably be kernel tests. You can look at core/modules/system/tests/src/Kernel/SecurityAdvisories/SecurityAdvisoriesFetcherTest.php in the same merge request. This is similar to what you will need as it tests the public method of the class with mocked feed items. It uses different method than the functional test to provide fake feed items. See \Drupal\Tests\system\Kernel\SecurityAdvisories\SecurityAdvisoriesFetcherTest::setFeedItems().

mitthukumawat’s picture

Assigned: Unassigned » mitthukumawat
mitthukumawat’s picture

Issue summary: View changes

vimaljoseph’s picture

Assigned: mitthukumawat » Unassigned
Category: Feature request » Task
Status: Active » Needs review

Commited the initial tests. Needs review.

tedbow’s picture

Status: Needs review » Needs work

The test are looking pretty good!

since these have already been committed I created an MR to just had a review of the tests. I have only started with AlertsJsonFeedTest but I think some of comments will apply to the other classes too.

Let me know if you have questions by leaving MR comments and ping to review the changes

Lal_ made their first commit to this issue’s fork.

mohit_aghera’s picture

Status: Needs work » Needs review
mohit_aghera’s picture

@tedbow, I am merging this feedback PR
I am opening up a new PR of the module against Drupal core for the maintainer's feedback.

I'll share the PR here as well, so you can do another round of review in the main PR itself.

  • mohit_aghera committed 176b3cb on 1.x authored by tedbow
    Issue #3198730 by tedbow, mohit_aghera, Lal_, vimaljoseph, mitthukumawat...
Lal_’s picture

Status: Needs review » Fixed

Since the issue is merged, moving this to fixed... Let's work on the core PR if there are any suggestions.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.