Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 33 additions & 16 deletions pages/institutions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait

import settings
from base.locators import (
Expand Down Expand Up @@ -58,37 +59,53 @@ class InstitutionAdminDashboardPage(BaseInstitutionPage):

url_addition = '/dashboard'

identity = Locator(By.CSS_SELECTOR, 'div[data-analytics-scope="Dashboard"]')
loading_indicator = Locator(By.CSS_SELECTOR, '.ball-scale', settings.LONG_TIMEOUT)
departments_listbox_trigger = Locator(
By.CSS_SELECTOR,
'div.ember-basic-dropdown-trigger.ember-power-select-trigger._select_tdvp4z',
identity = Locator(By.CSS_SELECTOR, 'img[alt="Center For Open Science [Test]"]')
loading_indicator = Locator(
By.CSS_SELECTOR, '.ball-scale', settings.LONG_TIMEOUT
)
total_user_count = Locator(
title_containers = GroupLocator(
By.CSS_SELECTOR,
'div.ember-view._panel_1dj7yu._sso-users-connected_1w5vdt > div > div._panel-body_1lht4i > div > h3',
'._title-container_1d9vmx',
)
total_project_count = Locator(
kpi_container = GroupLocator(
By.CSS_SELECTOR,
'div.ember-view._panel_1dj7yu._projects_1w5vdt > div > div._panel-body_1lht4i > div > div > h3',
'._kpi-container_1ge2xx',
)
public_project_count = Locator(
By.CSS_SELECTOR, 'div._projects-count_1ky9tx > span:nth-child(1) > strong'
)
private_project_count = Locator(
By.CSS_SELECTOR, 'div._projects-count_1ky9tx > span:nth-child(2) > strong'
)

department_options = GroupLocator(
By.CSS_SELECTOR, 'ul.ember-power-select-options > li.ember-power-select-option'
By.CSS_SELECTOR, 'ul._data-list_1d9vmx > li._data-container_1d9vmx'
)
user_table_rows = GroupLocator(
By.CSS_SELECTOR,
'div._table-wrapper_1w5vdt > div > div.ember-view > div > div > table > tbody > tr',
)
def get_expanded_total_by_expanded_name(self, department):
for element in self.department_options:
name_elem = element.find_element(By.CSS_SELECTOR, "[data-test-expanded-name]")
if name_elem.text.strip() == department:
total_elem = element.find_element(By.CSS_SELECTOR, "[data-test-expanded-total]")
return int(total_elem.text.strip())

def get_kpi_data_by_kpi_title(self, target_title):
for container in self.kpi_container:
title_element = container.find_element(By.CSS_SELECTOR, "[data-test-kpi-title]")
if title_element.text.strip() == target_title:
value_element = container.find_element(By.CSS_SELECTOR, "[data-test-kpi-data]")
return value_element.text.strip()

def click_on_listbox_trigger(self, section_title):
for section in self.title_containers:
title_element = section.find_element(By.CSS_SELECTOR, "[data-test-chart-title]")
if title_element.text.strip() == section_title:
button = section.find_element(By.CSS_SELECTOR, "[data-test-expand-additional-data]")
icon = section.find_element(By.CSS_SELECTOR, "[data-test-toggle-icon]")
button.click()
WebDriverWait(self.driver, 10).until(
lambda d: icon.get_attribute("data-icon") == "caret-up"
)

def select_department_from_listbox(self, department):
for option in self.department_options:
if option.text == department:
option.click()
break
28 changes: 10 additions & 18 deletions tests/test_institutions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import pytest
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

import markers
from api import osf_api
from pages.institutions import (
Expand Down Expand Up @@ -45,18 +41,14 @@ def test_institution_admin_dashboard(self, driver, session, must_be_logged_in):
dashboard_page.goto()
assert InstitutionAdminDashboardPage(driver, verify=True)
dashboard_page.loading_indicator.here_then_gone()

# Select 'QA' from Departments listbox and verify that the correct number
# of users are displayed in the table
dashboard_page.departments_listbox_trigger.click()
dashboard_page.select_department_from_listbox('QA')
WebDriverWait(driver, 10).until(
EC.visibility_of_element_located((By.CSS_SELECTOR, '[data-test-item-name]'))
)
dashboard_page.click_on_listbox_trigger('Total Users by Department')
user_table_rows = dashboard_page.get_expanded_total_by_expanded_name('QA')
api_qa_users = osf_api.get_institution_users_per_department(
session, institution_id='cos', department='QA'
)
assert len(dashboard_page.user_table_rows) == len(api_qa_users)
assert user_table_rows == len(api_qa_users)

# Get metrics data using the OSF api
metrics_data = osf_api.get_institution_metrics_summary(
Expand All @@ -66,23 +58,23 @@ def test_institution_admin_dashboard(self, driver, session, must_be_logged_in):
api_public_project_count = metrics_data['attributes']['public_project_count']
api_private_project_count = metrics_data['attributes']['private_project_count']

dashboard_page.scroll_into_view(dashboard_page.total_project_count.element)
total_project_count = dashboard_page.get_kpi_data_by_kpi_title('OSF Public and Private Projects')

# Verify Total User Count
displayed_user_count = dashboard_page.total_user_count.text
displayed_user_count = dashboard_page.get_kpi_data_by_kpi_title('Total Users')
assert int(displayed_user_count) == api_user_count

dashboard_page.click_on_listbox_trigger('Public vs Private Projects')

# Verify Public Project Count
displayed_public_project_count = dashboard_page.public_project_count.text
displayed_public_project_count = dashboard_page.get_expanded_total_by_expanded_name('Public Projects')
assert int(displayed_public_project_count) == api_public_project_count

# Verify Private Project Count
displayed_private_project_count = dashboard_page.private_project_count.text
displayed_private_project_count = dashboard_page.get_expanded_total_by_expanded_name('Private Projects')
assert int(displayed_private_project_count) == api_private_project_count

# Verify Total Project Count
total_project_count = dashboard_page.total_project_count.text
assert (
int(total_project_count)
== api_public_project_count + api_private_project_count
int(total_project_count) == api_public_project_count + api_private_project_count
)