diff --git a/e2e/src/navigating/navigateFromRegion.e2e-spec.js b/e2e/src/navigating/navigateFromRegion.e2e-spec.js index f2a24887f3be62d65f53a11f7484b19c81ad8360..0cbe20e896a45c7dd16d2392acbe49a1e6b9efeb 100644 --- a/e2e/src/navigating/navigateFromRegion.e2e-spec.js +++ b/e2e/src/navigating/navigateFromRegion.e2e-spec.js @@ -4,41 +4,48 @@ const TEST_DATA = [ { url: "/?templateSelected=MNI+152+ICBM+2009c+Nonlinear+Asymmetric&parcellationSelected=JuBrain+Cytoarchitectonic+Atlas", templateName: 'MNI 152 ICBM 2009c Nonlinear Asymmetric', - position: [600, 490], - expectedRegion: 'Area 6ma (preSMA, mesial SFG) - left hemisphere', + position: [450, 200], + expectedRegion: 'Area hOc1 (V1, 17, CalcS) - left hemisphere', expectedTemplateLabels: [ { - buttonText: 'Big Brain (Histology)', - expectedPosition: [-9349145, 27783956, 38734628] + name: 'Big Brain (Histology)', + expectedPosition: [3187941, -50436480, 3430986] }, { - buttonText: 'MNI Colin 27', - afterSelectNavigation: [-4083913, 4296092, 58555023] + name: 'MNI Colin 27', + expectedPosition: [ + -8533787, + -84646549, + 1855106 + ] }, ], }, { url: "/?templateSelected=Big+Brain+%28Histology%29&parcellationSelected=Cytoarchitectonic+Maps&cNavigation=0.0.0.-W000.._eCwg.2-FUe3._-s_W.2_evlu..7LIx..1n5q~.1FYC.2Is-..1B9C", templateName: 'Big Brain (Histology)', - position: [370, 150], + position: [691,678], // [370, 150], expectedRegion: 'Area STS1 (STS)', expectedTemplateLabels: [ { - buttonText: 'MNI Colin 27', - hemisphere:'Left', - afterSelectNavigation: [-54514755, -16753913, -5260713] + name: 'MNI Colin 27', + hemisphere: 'Left', + expectedPosition: [-54514755, -16753913, -5260713] }, { - buttonText: 'MNI Colin 27 - Right', - afterSelectNavigation: [54536567, -17992636, -5712544] + name: 'MNI Colin 27', + hemisphere: 'Right', + expectedPosition: [54536567, -17992636, -5712544] }, { - buttonText: 'MNI 152 ICBM 2009c Nonlinear Asymmetric - Left', - afterSelectNavigation: [-55442669, -18314601, -6381831] + name: 'MNI 152 ICBM 2009c Nonlinear Asymmetric', + hemisphere: 'Left', + expectedPosition: [-55442669, -18314601, -6381831] }, { - buttonText: 'MNI 152 ICBM 2009c Nonlinear Asymmetric - Right', - afterSelectNavigation: [52602966, -18339402, -5666868] + name: 'MNI 152 ICBM 2009c Nonlinear Asymmetric', + hemisphere: 'Right', + expectedPosition: [52602966, -18339402, -5666868] }, ], }, @@ -55,12 +62,12 @@ describe('explore same region in different templates', () => { TEST_DATA.forEach(template => { template.expectedTemplateLabels.forEach(expectedTemplate => { - it (`testing ${template.expectedRegion} exploring at: ${template.templateName}`, async () => { + it (`testing ${template.expectedRegion} exploring at: ${template.name}`, async () => { if (template.url) { await iavPage.goto(template.url) } else { await iavPage.goto() - await iavPage.selectTitleTemplateParcellation(template.templateName) + await iavPage.selectTitleTemplateParcellation(template.name) } const {position} = template @@ -68,23 +75,37 @@ describe('explore same region in different templates', () => { await tag.click() await iavPage.wait(1000) await iavPage.waitUntilAllChunksLoaded() - await iavPage.showRegionMenu( {position} ) - await iavPage.wait(5000) - await iavPage.wait(5000) - await iavPage.wait(5000) + await iavPage.cursorMoveToAndClick({ position }) - await iavPage.changeTemplateFromRegionMenu(expectedTemplate.buttonText, expectedTemplate.hemisphere && expectedTemplate.hemisphere) + await iavPage.showOtherTemplateMenu() + await iavPage.wait(500) - await iavPage.wait(1000) - await iavPage.waitUntilAllChunksLoaded() + const otherTemplates = await iavPage.getAllOtherTemplates() + const { name, hemisphere, expectedPosition } = expectedTemplate + const idx = otherTemplates.findIndex(template => { + if (hemisphere) { + if (template.indexOf(hemisphere) < 0) return false + } + return template.indexOf(name) >= 0 + }) - const navState = await iavPage.getNavigationState() + expect(idx).toBeGreaterThanOrEqual(0) - expect(navState.position).toEqual(expectedTemplate.expectedPosition) + await iavPage.clickNthItemAllOtherTemplates(idx) + await iavPage.wait(500) + await iavPage.waitUntilAllChunksLoaded() + + const navState = await iavPage.getNavigationState() + + // somehow there are slight deviations (1nm in most cases) + // giving a tolerance of 0.1um + for (const idx in navState.position) { + expect( + Math.abs(navState.position[idx] - expectedPosition[idx]) + ).toBeLessThanOrEqual(100) + } }) }) - }) - }) diff --git a/e2e/src/util.js b/e2e/src/util.js index e33b6cbf35a6c665390e63078bc7bcaea23f7bed..0b8e60e8e38d0ef98ce089bd581b83d37ef8a70b 100644 --- a/e2e/src/util.js +++ b/e2e/src/util.js @@ -23,6 +23,20 @@ async function _getIndexFromArrayOfWebElements(search, webElements) { const regionSearchAriaLabelText = 'Search for any region of interest in the atlas selected' +const vertifyPos = position => { + + if (!position) throw new Error(`cursorGoto: position must be defined!`) + const x = Array.isArray(position) ? position[0] : position.x + const y = Array.isArray(position) ? position[1] : position.y + if (!x) throw new Error(`cursorGoto: position.x or position[0] must be defined`) + if (!y) throw new Error(`cursorGoto: position.y or position[1] must be defined`) + + return { + x, + y + } +} + class WdBase{ constructor() { browser.waitForAngularEnabled(false) @@ -79,12 +93,7 @@ class WdBase{ } async cursorMoveTo({ position }) { - if (!position) throw new Error(`cursorGoto: position must be defined!`) - const x = Array.isArray(position) ? position[0] : position.x - const y = Array.isArray(position)? position[1] : position.y - if (!x) throw new Error(`cursorGoto: position.x or position[0] must be defined`) - if (!y) throw new Error(`cursorGoto: position.y or position[1] must be defined`) - + const { x, y } = vertifyPos(position) return this._driver.actions() .move() .move({ @@ -95,28 +104,17 @@ class WdBase{ .perform() } - async showRegionMenu({position}) { - if (!position) throw new Error(`cursorGoto: position must be defined!`) - const x = Array.isArray(position) ? position[0] : position.x - const y = Array.isArray(position) ? position[1] : position.y - if (!x) throw new Error(`cursorGoto: position.x or position[0] must be defined`) - if (!y) throw new Error(`cursorGoto: position.y or position[1] must be defined`) - - const atlasViewer = await this._driver.findElement(By.tagName('atlas-viewer')) - - console.log(x + ',' + y) - + async cursorMoveToAndClick({ position }) { + const { x, y } = vertifyPos(position) return this._driver.actions() .move() .move({ x, y, - duration: 1000, + duration: 1000 }) .click() .perform() - - console.log(1) } async initHttpInterceptor(){ @@ -485,6 +483,37 @@ class WdLayoutPage extends WdBase{ else await menuItems[index].click() } + // other templates + async showOtherTemplateMenu(){ + await this._driver + .findElement( By.css('[aria-label="Show availability in other reference spaces"]') ) + .click() + } + + _getOtherTemplateMenu(){ + return this._driver + .findElement( By.css('[aria-label="Availability in other reference spaces"]') ) + } + + _getAllOtherTemplates(){ + return this._getOtherTemplateMenu().findElements( By.css('[mat-menu-item]') ) + } + + async getAllOtherTemplates(){ + const els = await this._getAllOtherTemplates() + const returnArr = [] + for (const el of els) { + returnArr.push(await _getTextFromWebElement(el)) + } + return returnArr + } + + async clickNthItemAllOtherTemplates(index){ + const arr = await this._getAllOtherTemplates() + if (!arr[index]) throw new Error(`index out of bound: trying to access ${index} from arr with length ${arr.length}`) + await arr[index].click() + } + _getFavDatasetIcon(){ return this._driver .findElement( By.css('[aria-label="Show pinned datasets"]') ) @@ -710,16 +739,6 @@ class WdIavPage extends WdLayoutPage{ } } - async changeTemplateFromRegionMenu(templateName, hemisphere) { - const regionMenu = await this._driver.findElement(By.tagName('region-menu')) - const changeTemplate = await regionMenu.findElement(By.xpath("//button[contains(.,'Change template')]")) - await changeTemplate.click() - await this.wait(200) - const templateToChange = hemisphere? await regionMenu.findElement(By.xpath(`//button[contains(.,'${templateName}') and contains(.,'${hemisphere}')]`)) - : await regionMenu.findElement(By.xpath(`//button[contains(.,'${templateName}')]`)) - await templateToChange.click() - } - async getNavigationState() { const actualNav = await this._browser.executeScript(async () => { let returnObj, sub diff --git a/src/ui/parcellationRegion/regionMenu/regionMenu.component.ts b/src/ui/parcellationRegion/regionMenu/regionMenu.component.ts index 5b4f60fccb5146abbd33ca729ccdff5597e99584..6d58ff5be48a65adbae8a72d1200e7dae2e7167c 100644 --- a/src/ui/parcellationRegion/regionMenu/regionMenu.component.ts +++ b/src/ui/parcellationRegion/regionMenu/regionMenu.component.ts @@ -12,7 +12,6 @@ import { RegionBase } from '../region.base' }) export class RegionMenuComponent extends RegionBase implements OnInit, OnDestroy { - @ViewChild('additionalActionsMenuButton', {read: MatMenuTrigger}) actionsMenuTriggerButton: MatMenuTrigger @ViewChild('additionalActionsPanel', {read: ElementRef}) additionalActionsPanelElement: ElementRef private subscriptions: Subscription[] = [] diff --git a/src/ui/parcellationRegion/regionMenu/regionMenu.template.html b/src/ui/parcellationRegion/regionMenu/regionMenu.template.html index fc3758057d2bf6587e2aa027e89a11a9d0255da0..d5234089fd8ef778a51966485d297d9152a84d6d 100644 --- a/src/ui/parcellationRegion/regionMenu/regionMenu.template.html +++ b/src/ui/parcellationRegion/regionMenu/regionMenu.template.html @@ -11,7 +11,7 @@ <mat-card-content> {{ region.description }} </mat-card-content> - <div class="d-flex flex-row flex-wrap" #actionCard> + <div class="d-flex flex-row flex-wrap"> <button mat-button (click)="toggleRegionSelected()" [color]="isSelected ? 'primary': 'basic'"> @@ -51,9 +51,9 @@ <!-- Menu to navigate between template spaces to explore same region --> <div> <button mat-button - *ngIf="sameRegionTemplate.length" - [matMenuTriggerFor]="additionalActions" - #additionalActionsMenuButton="matMenuTrigger"> + aria-label="Show availability in other reference spaces" + *ngIf="sameRegionTemplate.length" + [matMenuTriggerFor]="additionalActions"> <i class="fas fa-brain"></i> <span> Change template @@ -62,7 +62,11 @@ </button> </div> - <mat-menu #additionalActions="matMenu" xPosition="before" (click)="$event.stopPropagation()" hasBackdrop="false"> + <mat-menu + [aria-label]="'Availability in other reference spaces'" + #additionalActions="matMenu" + xPosition="before" + hasBackdrop="false"> <div> <button mat-menu-item *ngFor="let sameRegion of sameRegionTemplate; let i = index" (click)="changeView(i)" class="d-flex"> <span class="overflow-x-hidden text-truncate"> {{sameRegion.template.name}} </span>