-
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
34 changed files
with
2,206 additions
and
2,089 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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,67 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import { Contention, ContentionActions, filterKeys, getContention, openContentionModalAction, reducer, resolveContentionAction } from "./ContentionContext"; | ||
|
||
jest.mock('../../i18n/hooks', () => ({ | ||
useTranslator: () => (value) => value, | ||
useTranslation: (value) => value | ||
})); | ||
|
||
describe('filterKeys', () => { | ||
it('should filter keys that arent displayed to user', () => { | ||
expect(filterKeys({ | ||
version: 'foo', | ||
name: 'bar' | ||
})).toBe(true) | ||
}) | ||
}); | ||
|
||
describe('getContention', () => { | ||
it('should return an object describing conflicts', () => { | ||
const contention = getContention({ name: 'baz', version: 0 }, { name: 'foo', version: 1 }, { name: 'bar', version: 2 }); | ||
expect(contention.theirChanges[0].conflict).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('openContentionModalAction', () => { | ||
it('should create a reducer action', () => { | ||
const action = openContentionModalAction({}, {name: 'foo'}, {name: 'bar'}, jest.fn(), jest.fn()); | ||
expect(action.type).toEqual(ContentionActions.OPEN_CONTENTION_MODAL); | ||
}) | ||
}); | ||
|
||
describe('resolveContentionAction', () => { | ||
it('should create a reducer action', () => { | ||
const action = resolveContentionAction(); | ||
expect(action.type).toEqual(ContentionActions.END_CONTENTION); | ||
}) | ||
}); | ||
|
||
describe('reducer', () => { | ||
it('should set show to true', () => { | ||
const state = reducer({}, {type: ContentionActions.OPEN_CONTENTION_MODAL}); | ||
expect(state.show).toBe(true); | ||
}) | ||
|
||
it('should set show to false', () => { | ||
const state = reducer({}, { type: ContentionActions.END_CONTENTION }); | ||
expect(state.show).toBe(false); | ||
}) | ||
|
||
it('should not change state', () => { | ||
const init = {}; | ||
const state = reducer(init, { type: 'foo' }); | ||
expect(state).toBe(init); | ||
}) | ||
}); | ||
|
||
describe('context component', () => { | ||
|
||
it('should provide the contention context', async () => { | ||
render(<Contention> | ||
<div>test</div> | ||
</Contention>); | ||
|
||
expect(screen.getByText('test')).toBeInTheDocument(); | ||
}); | ||
|
||
}) |
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
62 changes: 62 additions & 0 deletions
62
ui/src/app/metadata/contention/component/ChangeItem.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,62 @@ | ||
import React from 'react'; | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
|
||
import { ChangeItem } from './ChangeItem'; | ||
|
||
jest.mock('../../../i18n/hooks', () => ({ | ||
useTranslator: () => (value) => value, | ||
useTranslation: (value) => value | ||
})); | ||
|
||
describe('Contention Modal', () => { | ||
|
||
it('should render strings', () => { | ||
render(<ChangeItem | ||
item={{ | ||
label: 'foo', | ||
value: 'bar', | ||
conflict: true | ||
}} />); | ||
expect(screen.getByText('foo')).toBeInTheDocument(); | ||
expect(screen.getByText('bar')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render objects', () => { | ||
const item = { | ||
label: 'foo', | ||
value: { | ||
bar: 'baz' | ||
} | ||
}; | ||
render(<ChangeItem | ||
item={item} />); | ||
expect(screen.getByText('baz')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render arrays of primitives', () => { | ||
const item = { | ||
label: 'foo', | ||
value: [ | ||
'bar', | ||
'baz' | ||
] | ||
}; | ||
render(<ChangeItem | ||
item={item} />); | ||
expect(screen.getByText('baz')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render arrays of objects', () => { | ||
const item = { | ||
label: 'foo', | ||
value: [ | ||
{ barlabel: 'bar' }, | ||
{ bazlabel: 'baz' } | ||
] | ||
}; | ||
render(<ChangeItem | ||
item={item} />); | ||
expect(screen.getByText('baz')).toBeInTheDocument(); | ||
expect(screen.getByText('bar')).toBeInTheDocument(); | ||
}); | ||
}); |
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
58 changes: 58 additions & 0 deletions
58
ui/src/app/metadata/contention/component/ContentionModal.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,58 @@ | ||
import React from 'react'; | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
|
||
import { ContentionModal } from './ContentionModal'; | ||
import { getContention } from '../ContentionContext'; | ||
|
||
jest.mock('../../../i18n/hooks', () => ({ | ||
useTranslator: () => (value) => value, | ||
useTranslation: (value) => value | ||
})); | ||
|
||
|
||
describe('Contention Modal', () => { | ||
|
||
let contention, mockUseTheirs, mockUseOurs; | ||
|
||
beforeEach(() => { | ||
mockUseOurs = jest.fn(); | ||
mockUseTheirs = jest.fn(); | ||
contention = getContention({ name: 'baz', version: 0 }, { name: 'foo', version: 1 }, { name: 'bar', version: 2 }); | ||
render(<ContentionModal | ||
show={true} | ||
theirs={contention.theirChanges} | ||
ours={contention.ourChanges} | ||
onUseOurs={mockUseOurs} | ||
onUseTheirs={mockUseTheirs} />); | ||
}) | ||
|
||
|
||
it('should render', () => { | ||
expect(screen.getByText('message.data-version-contention')).toBeInTheDocument(); | ||
expect(screen.getByText('message.contention-new-version')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should allow the user to discard their changes', () => { | ||
fireEvent.click(screen.getByText('action.use-theirs')); | ||
expect(mockUseTheirs).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should allow the user to resolve differences', () => { | ||
fireEvent.click(screen.getByText('action.use-mine')); | ||
expect(mockUseOurs).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should allow the user to cancel if there are no real changes', () => { | ||
|
||
contention = getContention({ name: 'baz', version: 0 }, { name: 'foo', version: 1 }, { name: 'bar', version: 2 }); | ||
render(<ContentionModal | ||
show={true} | ||
theirs={[]} | ||
ours={contention.ourChanges} | ||
onUseOurs={mockUseOurs} | ||
onUseTheirs={mockUseTheirs} />); | ||
|
||
fireEvent.click(screen.getByText('action.cancel')); | ||
expect(mockUseTheirs).toHaveBeenCalled(); | ||
}); | ||
}); |
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions
6
...ilter/EntityAttributesFilterDefinition.js → ...ition/EntityAttributesFilterDefinition.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
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
...a/domain/filter/NameIdFilterDefinition.js → ...lter/definition/NameIdFilterDefinition.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
File renamed without changes.
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
Oops, something went wrong.