Skip to content

Commit

Permalink
feat: unit and e2e testing
Browse files Browse the repository at this point in the history
  • Loading branch information
cmoinier committed Aug 7, 2024
1 parent a443a94 commit 5d9df54
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
45 changes: 45 additions & 0 deletions apps/metadata-editor-e2e/src/e2e/edit.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,49 @@ describe('editor form', () => {
})
cy.get('md-editor-publish-button').click()
})

describe('Access and contact', () => {
describe('Open data switch', () => {
describe('When the open data switch is checked', () => {
beforeEach(() => {
cy.visit('/edit/accroche_velos')
cy.get('md-editor-page-selector').find('gn-ui-button').last().click()
})
it('should not display the licence section', () => {
cy.get('gn-ui-form-field-license').should('not.exist')
})
it('should display the license section when toggled', () => {
cy.get('gn-ui-check-toggle').find('span').first().click()
cy.get('gn-ui-form-field-license').should('be.visible')
cy.get('gn-ui-form-field-license')
.find('button')
.children('div')
.first()
.invoke('text')
.should('eq', ' Open Licence (Etalab) ')
})
})
describe('When the open data switch is unchecked', () => {
beforeEach(() => {
cy.visit(
'/edit/fr-120066022-jdd-f20f8125-877e-46dc-8cf8-2a8a372045eb'
)
cy.get('md-editor-page-selector').find('gn-ui-button').last().click()
})
it('should display the licence section', () => {
cy.get('gn-ui-form-field-license').should('be.visible')
cy.get('gn-ui-form-field-license')
.find('button')
.children('div')
.first()
.invoke('text')
.should('eq', ' Creative Commons CC-BY ')
})
it('should hide the license section when toggled', () => {
cy.get('gn-ui-check-toggle').find('span').first().click()
cy.get('gn-ui-form-field-license').should('not.exist')
})
})
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,19 @@ describe('RecordFormComponent', () => {
)
})
})

describe('onOpenDataToggled', () => {
it('should set isHidden and call the facade to set the license', () => {
component.onOpenDataToggled([true, [{ text: 'license' }]])
expect(component.isHidden).toBe(true)
expect(component.facade.updateRecordField).toHaveBeenCalledWith(
'licenses',
[
{
text: 'license',
},
]
)
})
})
})
19 changes: 19 additions & 0 deletions libs/ui/inputs/src/lib/check-toggle/check-toggle.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'

import { CheckToggleComponent } from './check-toggle.component'
import { getGlobalConfig } from '@geonetwork-ui/util/app-config'

jest.mock('@geonetwork-ui/util/app-config')

describe('CheckToggleComponent', () => {
let component: CheckToggleComponent
let fixture: ComponentFixture<CheckToggleComponent>

beforeEach(async () => {
;(getGlobalConfig as jest.Mock).mockReturnValue({ LICENSES: ['CC-BY'] })

await TestBed.configureTestingModule({
imports: [CheckToggleComponent],
}).compileComponents()
Expand All @@ -19,4 +24,18 @@ describe('CheckToggleComponent', () => {
it('should create', () => {
expect(component).toBeTruthy()
})

it('should emit the new license value on toggle', () => {
const toggledSpy = jest.spyOn(component.toggled, 'emit')
component.model = 'licenses'
component.toggle(true)
expect(toggledSpy).toHaveBeenCalledWith([true, [{ text: 'CC-BY' }]])
})

it('should emit the event value on toggle when model is not licenses', () => {
const toggledSpy = jest.spyOn(component.toggled, 'emit')
component.model = 'not-licenses'
component.toggle(true)
expect(toggledSpy).toHaveBeenCalledWith(true)
})
})

0 comments on commit 5d9df54

Please sign in to comment.