Project

General

Profile

Actions

Bug #41781

open

mgr/dashboard: test coding best practice: replace element queries to CSS/angular attributes with alternatives

Added by Ernesto Puerta over 4 years ago. Updated about 3 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
General
Target version:
-
% Done:

0%

Source:
Tags:
Backport:
Regression:
No
Severity:
3 - minor
Reviewed:
Affected Versions:
ceph-qa-suite:
Pull request ID:
Crash signature (v1):
Crash signature (v2):

Description

Most unit & e2e tests use CSS (e.g.: ".card-title") or Angular component attributes ([cardTitle="Cluster Status"]) to retrieve HTML/DOM contents for assertions/navigation.

While this works, it means that we are anchoring tests to elements that might change due to refactors. For example:

  • CSS classes might change with framework updates (e.g.: the recent Bootstrap 3 to 4 refresh) or simple cleanups.
  • Adding new elements with the same attributes would modify/break the query results.
  • Angular component attributes include literal strings that might change ("Cluster Status" -> "Cluster Health").

HTML5 provides free-from "data-*" attributes that might perfectly fit for this purpose:

  • Either by adding data-testid/data-description/data-id to semantically describe/identify elements: reference
  • If we are to add semantic descriptors, why not using ARIA attributes and also improve accessibility for our dashboard (reference)
    const anchor = fixture.debugElement.nativeElement                                                
-      .querySelector('.card-title')                                                                     
+      .querySelector('[aria-label="Card Title"]')                                                                     
Actions

Also available in: Atom PDF