Skip to content

Commit

Permalink
feat: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cmoinier committed Nov 21, 2024
1 parent 52b9d22 commit 6d127b2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
13 changes: 12 additions & 1 deletion apps/metadata-editor-e2e/src/e2e/dashboard.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand All @@ -23,6 +26,9 @@ describe('SidebarComponent', () => {
AvatarServiceInterface,
OrganizationsServiceInterface
),
MockProvider(AuthService, {
loginUrl: 'http://login.com/bla/catalog',
}),
],
}).compileComponents()

Expand All @@ -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()
})
})
})

0 comments on commit 6d127b2

Please sign in to comment.