Skip to content
Snippets Groups Projects
Commit 7928200f authored by Omkar Deshpande's avatar Omkar Deshpande Committed by Chris Wells
Browse files

Issue #3477314 by shalini_jha, lostcarpark, omkar-pd, chrisfromredfin,...

Issue #3477314 by shalini_jha, lostcarpark, omkar-pd, chrisfromredfin, narendrar, phenaproxima: Format plural for number of installs
parent 86e6517c
No related branches found
No related tags found
No related merge requests found
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
......@@ -85,8 +85,12 @@
variant="module-details"
classes="pb-detail-modal__module-details-icon-sidebar"
/>
{numberFormatter.format(project.project_usage_total)}{Drupal.t(
' sites report using this module',
{Drupal.formatPlural(
project.project_usage_total,
`${numberFormatter.format(1)} site reports using this module`,
`${numberFormatter.format(
project.project_usage_total,
)} sites report using this module`,
)}
</div>
{/if}
......
......@@ -9,6 +9,7 @@
import Image from './Image.svelte';
import Categories from './Categories.svelte';
import ProjectIcon from './ProjectIcon.svelte';
import { numberFormatter } from '../util';
import { focusedElement, mediaQueryValues } from '../stores';
import { FULL_MODULE_PATH } from '../constants';
......@@ -77,11 +78,13 @@
{#if toggleView === 'Grid' && project.project_usage_total !== -1}
{#if project.project_usage_total !== 0}
<div class="pb-project__install-count-container">
<span class="pb-project__install-count"
>{Drupal.t('@count installs ', {
'@count': project.project_usage_total.toLocaleString(),
})}</span
>
<span class="pb-project__install-count">
{Drupal.formatPlural(
project.project_usage_total,
`${numberFormatter.format(1)} install`,
`${numberFormatter.format(project.project_usage_total)} installs`,
)}
</span>
</div>
{/if}
{/if}
......@@ -100,7 +103,13 @@
</div>
{#if project.project_usage_total !== 0}
<div class="pb-project__active-installs-text">
{project.project_usage_total.toLocaleString()} Active Installs
{Drupal.formatPlural(
project.project_usage_total,
`${numberFormatter.format(1)} Active Install`,
`${numberFormatter.format(
project.project_usage_total,
)} Active Installs`,
)}
</div>
{/if}
</div>
......
......@@ -380,8 +380,8 @@
"field_project_images": [],
"field_project_machine_name": "grapefruit",
"project_usage": {
"7.x-1.x": 12,
"8.x-2.x": 20
"7.x-1.x": 0,
"8.x-2.x": 1
},
"taxonomy_vocabulary_3": [
{
......@@ -390,7 +390,7 @@
}
],
"taxonomy_vocabulary_44": {
"id": "13032",
"id": "9990",
"resource": "taxonomy_term"
},
"taxonomy_vocabulary_46": {
......
......@@ -73,22 +73,22 @@ class ProjectBrowserUiTest extends WebDriverTestBase {
$assert_session->waitForElementVisible('css', '#pb-project-browser .pb-display__button[value="Grid"]');
$grid_text = $this->getElementText('#project-browser .pb-display__button[value="Grid"]');
$this->assertEquals('Grid', $grid_text);
$this->svelteInitHelper('text', '9 Results');
$assert_session->elementsCount('css', '#project-browser .pb-project.pb-project--grid', 9);
$this->svelteInitHelper('text', '10 Results');
$assert_session->elementsCount('css', '#project-browser .pb-project.pb-project--grid', 10);
$this->assertTrue($assert_session->waitForText('Results'));
$assert_session->pageTextNotContains('No modules found');
$page->pressButton('List');
$this->assertNotNull($assert_session->waitForElementVisible('css', '#project-browser .pb-project.pb-project--list'));
$assert_session->elementsCount('css', '#project-browser .pb-project.pb-project--list', 9);
$assert_session->elementsCount('css', '#project-browser .pb-project.pb-project--list', 10);
$page->pressButton('Grid');
$this->assertNotNull($assert_session->waitForElementVisible('css', '#project-browser .pb-project.pb-project--grid'));
$this->getSession()->resizeWindow(1100, 1000);
$assert_session->assertNoElementAfterWait('css', '.pb-display__button[value="List"]');
$this->assertNotNull($assert_session->waitForElementVisible('css', '#project-browser .pb-project.pb-project--list'));
$assert_session->elementsCount('css', '#project-browser .pb-project.pb-project--list', 9);
$assert_session->elementsCount('css', '#project-browser .pb-project.pb-project--list', 10);
$this->getSession()->resizeWindow(1210, 1210);
$this->assertNotNull($assert_session->waitForElementVisible('css', '#project-browser .pb-project.pb-project--grid'));
$assert_session->elementsCount('css', '#project-browser .pb-project.pb-project--grid', 9);
$assert_session->elementsCount('css', '#project-browser .pb-project.pb-project--grid', 10);
}
/**
......@@ -126,7 +126,7 @@ class ProjectBrowserUiTest extends WebDriverTestBase {
$this->drupalGet('admin/modules/browse');
$this->svelteInitHelper('css', '.pb-filter__multi-dropdown');
// Initial results count on page load.
$this->assertTrue($assert_session->waitForText('9 Results'));
$this->assertTrue($assert_session->waitForText('10 Results'));
// Open category drop-down.
$this->clickWithWait('.pb-filter__multi-dropdown', 'E-commerce', TRUE);
......@@ -153,7 +153,7 @@ class ProjectBrowserUiTest extends WebDriverTestBase {
], TRUE);
// Clear the checkbox to verify the results revert to their initial state.
$this->clickWithWait('#104', '9 Results');
$this->clickWithWait('#104', '10 Results');
// Use blur event to close drop-down so Clear is visible.
$this->assertSession()->elementExists('css', '.pb-filter__multi-dropdown')->blur();
......@@ -236,7 +236,7 @@ class ProjectBrowserUiTest extends WebDriverTestBase {
$assert_session = $this->assertSession();
$this->drupalGet('admin/modules/browse');
$this->svelteInitHelper('text', '9 Results');
$this->svelteInitHelper('text', '10 Results');
$this->assertProjectsVisible([
'Cream cheese on a bagel',
......@@ -247,6 +247,7 @@ class ProjectBrowserUiTest extends WebDriverTestBase {
'Octopus',
'Helvetica',
'Unwritten&:/',
'Grapefruit',
'Astronaut Simulator',
]);
$this->assertPagerItems([]);
......@@ -280,10 +281,10 @@ class ProjectBrowserUiTest extends WebDriverTestBase {
'Ruh roh',
'Fire',
'Looper',
'Grapefruit',
'Become a Banana',
'Unwritten&:/',
'Doomer',
'Grapefruit',
]);
$this->assertPagerItems(['First', 'Previous', '1', '2', '3', 'Next', 'Last']);
......@@ -353,6 +354,7 @@ class ProjectBrowserUiTest extends WebDriverTestBase {
'Octopus',
'Helvetica',
'Unwritten&:/',
'Grapefruit',
'Astronaut Simulator',
]);
......@@ -399,7 +401,7 @@ class ProjectBrowserUiTest extends WebDriverTestBase {
'Helvetica',
'1 Starts With a Number',
'Become a Banana',
'Astronaut Simulator',
'Grapefruit',
]);
// Click the "Show all" filter for security.
......@@ -416,7 +418,7 @@ class ProjectBrowserUiTest extends WebDriverTestBase {
'Helvetica',
'1 Starts With a Number',
'Become a Banana',
'Astronaut Simulator',
'Grapefruit',
]);
// Clear all filters.
......@@ -541,7 +543,7 @@ class ProjectBrowserUiTest extends WebDriverTestBase {
// Clear filters.
$this->drupalGet('admin/modules/browse');
$this->svelteInitHelper('text', '9 Results');
$this->svelteInitHelper('text', '10 Results');
$this->pressWithWait('Clear filters', '25 Results');
// Tests for the presence of search bar placeholder text.
......@@ -733,7 +735,7 @@ class ProjectBrowserUiTest extends WebDriverTestBase {
$this->assertEquals('Show actively maintained projects', $this->getElementText(self::MAINTENANCE_OPTION_SELECTOR . self::OPTION_CHECKED));
// Make sure the second filter applied is the security covered filter.
$this->assertEquals('Show projects covered by a security policy', $this->getElementText(self::SECURITY_OPTION_SELECTOR . self::OPTION_CHECKED));
$this->assertTrue($assert_session->waitForText('9 Results'));
$this->assertTrue($assert_session->waitForText('10 Results'));
}
/**
......@@ -754,7 +756,7 @@ class ProjectBrowserUiTest extends WebDriverTestBase {
$tab_count = $page->findAll('css', '.pb-tabs__link');
$this->assertCount(2, $tab_count);
// Get result count for first tab.
$this->assertEquals('9 Results', $this->getElementText('.pb-search-results'));
$this->assertEquals('10 Results', $this->getElementText('.pb-search-results'));
// Get second tab text.
$second_tab_text = $assert_session->buttonExists('random_data')->getText();
......@@ -956,10 +958,10 @@ class ProjectBrowserUiTest extends WebDriverTestBase {
$assert_session->elementsCount('css', '#project-browser .pb-layout__main ul li:nth-child(7) .pb-project-categories ul li', 1);
$grid_text = $this->getElementText('#project-browser .pb-layout__main ul li:nth-child(7) .pb-project-categories ul li:nth-child(1)');
$this->assertEquals('E-commerce', $grid_text);
$assert_session->elementsCount('css', '#project-browser .pb-layout__main ul li:nth-child(9) .pb-project-categories ul li', 2);
$assert_session->elementsCount('css', '#project-browser .pb-layout__main ul li:nth-child(10) .pb-project-categories ul li', 2);
$grid_text = $this->getElementText('#project-browser .pb-layout__main ul li:nth-child(7) .pb-project-categories ul li:nth-child(1)');
$this->assertEquals('E-commerce', $grid_text);
$grid_text = $this->getElementText('#project-browser .pb-layout__main ul li:nth-child(9) .pb-project-categories ul li:nth-child(2)');
$grid_text = $this->getElementText('#project-browser .pb-layout__main ul li:nth-child(10) .pb-project-categories ul li:nth-child(2)');
$this->assertEquals('E-commerce', $grid_text);
}
}
......@@ -1191,4 +1193,42 @@ class ProjectBrowserUiTest extends WebDriverTestBase {
$this->assertFalse($assert_session->waitForText('The module is actively maintained by the maintainers'));
}
/**
* Tests that count of installs is formatted for plurals correctly.
*/
public function testInstallCountPluralFormatting(): void {
$assert_session = $this->assertSession();
$page = $this->getSession()->getPage();
$this->drupalGet('admin/modules/browse');
// Ensure the project list is loaded.
$this->assertNotEmpty($assert_session->waitForElementVisible('css', '#project-browser .pb-project'));
$this->assertTrue($assert_session->waitForText('Results'));
// Expect Grapefruit to have 1 install.
$assert_session->waitForElementVisible('xpath', '//span[contains(@class, "pb-project__install-count") and text()="1 install"]');
// Locate and click the Grapefruit project link.
$grapefruit_link = $page->find('xpath', '//button[contains(@class, "pb-project__link") and contains(text(), "Grapefruit")]');
$grapefruit_link->click();
// Verify the text for Grapefruit (singular case).
$this->assertTrue($assert_session->waitForText('site reports using this module'));
// Go back to the project list.
$close_button = $page->find('xpath', '//button[contains(@class, "ui-dialog-titlebar-close") and contains(text(), "Close")]');
$close_button->click();
// Expect Octopus to have 235 installs.
$assert_session->elementExists('xpath', '//span[contains(@class, "pb-project__install-count") and text()="235 installs"]');
// Locate and click the Octopus project link.
$octopus_link = $page->find('xpath', '//button[contains(@class, "pb-project__link") and contains(text(), "Octopus")]');
$octopus_link->click();
// Verify the text for Octopus (plural case).
$this->assertTrue($assert_session->waitForText('sites report using this module'));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment