-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
250 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { act } from 'react-dom/test-utils'; | ||
|
||
import { DeleteConfirmation } from './DeleteConfirmation'; | ||
|
||
jest.mock('../../i18n/components/translate', () => { | ||
return 'span'; | ||
}) | ||
|
||
const noop = jest.fn(); | ||
|
||
let container; | ||
|
||
beforeEach(() => { | ||
container = document.createElement('div'); | ||
document.body.appendChild(container); | ||
}); | ||
|
||
afterEach(() => { | ||
document.body.removeChild(container); | ||
container = null; | ||
}); | ||
|
||
test('Delete confirmation', () => { | ||
act(() => { | ||
ReactDOM.render( | ||
<DeleteConfirmation title={`message.delete-filter-title`} body={`message.delete-filter-body`}> | ||
{(block) => <button onClick={() => block(() => noop())}></button>} | ||
</DeleteConfirmation>, | ||
container); | ||
}); | ||
|
||
const initiator = container.querySelector('button'); | ||
|
||
act(() => { | ||
initiator.dispatchEvent(new MouseEvent('click', { bubbles: true })); | ||
}); | ||
|
||
let modal = container.querySelector('.modal'); | ||
const confirm = container.querySelector('.btn-danger'); | ||
|
||
expect(modal).toBeDefined(); | ||
expect(confirm).toBeDefined(); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
160 changes: 160 additions & 0 deletions
160
ui/src/app/metadata/domain/provider/BaseProviderDefinition.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
import { BaseProviderDefinition } from './BaseProviderDefinition'; | ||
import schema from '../../../../testing/dynamic-http.schema'; | ||
const addErrorMockFn = jest.fn(); | ||
|
||
const providers = [ | ||
{ | ||
resourceId: 1, | ||
name: 'foo', | ||
xmlId: 'bar' | ||
}, | ||
{ | ||
resourceId: 2, | ||
name: 'baz', | ||
xmlId: 'xmlId' | ||
} | ||
]; | ||
|
||
const e = { | ||
name: { addError: addErrorMockFn }, | ||
xmlId: { addError: addErrorMockFn } | ||
}; | ||
|
||
describe('validator function', () => { | ||
it('should validate against the providers', () => { | ||
const validator = BaseProviderDefinition.validator(providers, 2); | ||
const errors = validator({ | ||
name: 'foo', | ||
xmlId: 'xmlId' | ||
}, e); | ||
|
||
expect(addErrorMockFn).toHaveBeenCalledTimes(2); | ||
}); | ||
|
||
it('should check against the current id', () => { | ||
const validator = BaseProviderDefinition.validator(providers, 1); | ||
const errors = validator({ | ||
name: 'foo', | ||
xmlId: 'naz' | ||
}, e); | ||
|
||
expect(addErrorMockFn).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
|
||
describe('parser function', () => { | ||
|
||
const base = { | ||
metadataFilters: [ | ||
{ | ||
resourceId: 'foo', | ||
name: 'foo', | ||
'@type': 'NameIDFormat' | ||
} | ||
] | ||
}; | ||
|
||
const changes = { | ||
metadataFilters: [ | ||
{ | ||
'@type': "RequiredValidUntil", | ||
audId: 19, | ||
createdBy: "root", | ||
createdDate: "2021-06-11T13:29:18.384219", | ||
current: false, | ||
filterEnabled: false, | ||
maxValidityInterval: "PT30S", | ||
resourceId: "299feea8-3e2c-433e-bc2e-48d28bf84a8c" | ||
} | ||
] | ||
}; | ||
|
||
it('should validate against the providers', () => { | ||
const parsed = BaseProviderDefinition.parser( | ||
changes, base | ||
); | ||
|
||
expect(parsed.metadataFilters.length).toBe(2); | ||
}); | ||
}); | ||
|
||
describe('formatter function', () => { | ||
|
||
const md = { | ||
metadataFilters: [ | ||
{ | ||
resourceId: 'foo', | ||
name: 'foo', | ||
'@type': 'NameIDFormat' | ||
}, | ||
{ | ||
'@type': "RequiredValidUntil", | ||
audId: 19, | ||
createdBy: "root", | ||
createdDate: "2021-06-11T13:29:18.384219", | ||
current: false, | ||
filterEnabled: false, | ||
maxValidityInterval: "PT30S", | ||
resourceId: "299feea8-3e2c-433e-bc2e-48d28bf84a8c" | ||
} | ||
] | ||
}; | ||
|
||
it('should validate against the providers', () => { | ||
const parsed = BaseProviderDefinition.formatter( | ||
md, schema | ||
); | ||
|
||
expect(parsed.metadataFilters.length).toBe(3); | ||
}); | ||
|
||
it('should return no changes if no filters are on the provider', () => { | ||
const parsed = BaseProviderDefinition.formatter( | ||
{}, schema | ||
); | ||
|
||
expect(parsed.metadataFilters).toBeUndefined(); | ||
}); | ||
|
||
it('should return no changes if no provider is passed', () => { | ||
const parsed = BaseProviderDefinition.formatter( | ||
null, schema | ||
); | ||
|
||
expect(parsed).toBeNull(); | ||
}); | ||
}); | ||
|
||
describe('display function', () => { | ||
|
||
const md = { | ||
metadataFilters: [ | ||
{ | ||
resourceId: 'foo', | ||
name: 'foo', | ||
'@type': 'NameIDFormat' | ||
}, | ||
{ | ||
'@type': "RequiredValidUntil", | ||
audId: 19, | ||
createdBy: "root", | ||
createdDate: "2021-06-11T13:29:18.384219", | ||
current: false, | ||
filterEnabled: false, | ||
maxValidityInterval: "PT30S", | ||
resourceId: "299feea8-3e2c-433e-bc2e-48d28bf84a8c" | ||
} | ||
] | ||
}; | ||
|
||
it('should validate against the providers', () => { | ||
const parsed = BaseProviderDefinition.display(md); | ||
expect(Array.isArray(parsed)).toBe(false); | ||
}); | ||
|
||
it('should return an unmodified provider if no filters are present', () => { | ||
const local = {}; | ||
const parsed = BaseProviderDefinition.display(local); | ||
expect(parsed).toEqual(local); | ||
}); | ||
}); |
15 changes: 15 additions & 0 deletions
15
ui/src/app/metadata/domain/source/SourceDefinition.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { SourceBase } from './SourceDefinition'; | ||
|
||
describe('SourceDefinition', () => { | ||
describe('parser', () => { | ||
it('should remove null values', () => { | ||
expect(SourceBase.parser({ | ||
foo: null, | ||
bar: 'baz', | ||
baz: { | ||
bar: null | ||
} | ||
})).toEqual({bar: 'baz'}); | ||
}); | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters