From 6d127b2fb32d705af8df863cf2c7aadd3eead648 Mon Sep 17 00:00:00 2001 From: cmoinier Date: Thu, 21 Nov 2024 15:37:26 +0100 Subject: [PATCH] feat: add tests --- .../src/e2e/dashboard.cy.ts | 13 +++++++- .../sidebar/sidebar.component.spec.ts | 31 +++++++++++++++++-- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/apps/metadata-editor-e2e/src/e2e/dashboard.cy.ts b/apps/metadata-editor-e2e/src/e2e/dashboard.cy.ts index 5cee3c2b69..45dd3406a9 100644 --- a/apps/metadata-editor-e2e/src/e2e/dashboard.cy.ts +++ b/apps/metadata-editor-e2e/src/e2e/dashboard.cy.ts @@ -342,8 +342,19 @@ describe('dashboard (authenticated)', () => { }) }) }) + describe('Account settings access', () => { + it('should navigate to the account settings page', () => { + cy.visit('/catalog/search') + cy.get('md-editor-sidebar') + .find('gn-ui-button') + .first() + .find('a') + .invoke('removeAttr', 'target') + .click() + cy.url().should('include', '/admin.console') + }) + }) }) - describe('when the user is not logged in', () => { beforeEach(() => { cy.visit('/catalog/search') diff --git a/apps/metadata-editor/src/app/dashboard/sidebar/sidebar.component.spec.ts b/apps/metadata-editor/src/app/dashboard/sidebar/sidebar.component.spec.ts index 50982f3777..f39911d8e5 100644 --- a/apps/metadata-editor/src/app/dashboard/sidebar/sidebar.component.spec.ts +++ b/apps/metadata-editor/src/app/dashboard/sidebar/sidebar.component.spec.ts @@ -1,9 +1,12 @@ import { ComponentFixture, TestBed } from '@angular/core/testing' -import { AvatarServiceInterface } from '@geonetwork-ui/api/repository' +import { + AuthService, + AvatarServiceInterface, +} from '@geonetwork-ui/api/repository' import { OrganizationsServiceInterface } from '@geonetwork-ui/common/domain/organizations.service.interface' import { PlatformServiceInterface } from '@geonetwork-ui/common/domain/platform.service.interface' import { TranslateModule } from '@ngx-translate/core' -import { MockBuilder, MockProviders } from 'ng-mocks' +import { MockBuilder, MockProvider, MockProviders } from 'ng-mocks' import { SidebarComponent } from './sidebar.component' describe('SidebarComponent', () => { @@ -23,6 +26,9 @@ describe('SidebarComponent', () => { AvatarServiceInterface, OrganizationsServiceInterface ), + MockProvider(AuthService, { + loginUrl: 'http://login.com/bla/catalog', + }), ], }).compileComponents() @@ -34,4 +40,25 @@ describe('SidebarComponent', () => { it('should create', () => { expect(component).toBeTruthy() }) + + describe('openSettings', () => { + it('should log out', async () => { + jest.spyOn(window, 'fetch').mockResolvedValue({ + ok: true, + } as Response) + + const expectedUrl = + 'http://login.com/bla/admin.console#/organization/users?userOrGroup=' + + const mockWindowOpen = jest.fn().mockReturnValue({ + focus: jest.fn(), + }) + window.open = mockWindowOpen + + await component.openSettings() + + expect(mockWindowOpen).toHaveBeenCalledWith(expectedUrl, '_blank') + expect(mockWindowOpen().focus).toHaveBeenCalled() + }) + }) })