-
Notifications
You must be signed in to change notification settings - Fork 8
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
16 changed files
with
830 additions
and
485 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
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,27 @@ | ||
import { getEvotingConfig } from '../index'; | ||
|
||
export namespace EvotingHooks { | ||
/** | ||
* Gets the current lao id | ||
* @returns The current lao id | ||
*/ | ||
export const useCurrentLaoId = () => { | ||
return getEvotingConfig().getCurrentLaoId(); | ||
}; | ||
|
||
/** | ||
* Gets the current lao | ||
* @returns The current lao | ||
*/ | ||
export const useCurrentLao = () => { | ||
return getEvotingConfig().getCurrentLao(); | ||
}; | ||
|
||
/** | ||
* Gets the onConfirmEventCreation helper function | ||
* @returns The onConfirmEventCreation function | ||
*/ | ||
export const useOnConfirmEventCreation = () => { | ||
return getEvotingConfig().onConfirmEventCreation; | ||
}; | ||
} |
38 changes: 38 additions & 0 deletions
38
fe1-web/src/features/evoting/hooks/__tests__/EvotingHooks.test.ts
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,38 @@ | ||
import { describe } from '@jest/globals'; | ||
import { configure } from 'features/evoting'; | ||
import { mockLao, mockLaoIdHash, mockMessageRegistry, mockReduxAction } from '__tests__/utils'; | ||
import { EvotingHooks } from '../index'; | ||
|
||
const onConfirmEventCreation = jest.fn(); | ||
|
||
beforeAll(() => { | ||
configure({ | ||
getCurrentLao: () => mockLao, | ||
getCurrentLaoId: () => mockLaoIdHash, | ||
addEvent: () => mockReduxAction, | ||
updateEvent: () => mockReduxAction, | ||
getEventFromId: () => undefined, | ||
messageRegistry: mockMessageRegistry, | ||
onConfirmEventCreation, | ||
}); | ||
}); | ||
|
||
describe('E-Voting hooks', () => { | ||
describe('EvotingHooks.useCurrentLao', () => { | ||
it('should return the current lao', () => { | ||
expect(EvotingHooks.useCurrentLao()).toEqual(mockLao); | ||
}); | ||
}); | ||
|
||
describe('EvotingHooks.useCurrentLaoId', () => { | ||
it('should return the current lao id', () => { | ||
expect(EvotingHooks.useCurrentLaoId()).toEqual(mockLaoIdHash); | ||
}); | ||
}); | ||
|
||
describe('EvotingHooks.useOnConfirmEventCreation', () => { | ||
it('should return the onConfirmEventCreation config option', () => { | ||
expect(EvotingHooks.useOnConfirmEventCreation()).toEqual(onConfirmEventCreation); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,27 +1 @@ | ||
import { getEvotingConfig } from '../index'; | ||
|
||
export namespace EvotingHooks { | ||
/** | ||
* Gets the current lao id | ||
* @returns The current lao id | ||
*/ | ||
export const useCurrentLaoId = () => { | ||
return getEvotingConfig().getCurrentLaoId(); | ||
}; | ||
|
||
/** | ||
* Gets the current lao | ||
* @returns The current lao | ||
*/ | ||
export const useCurrentLao = () => { | ||
return getEvotingConfig().getCurrentLao(); | ||
}; | ||
|
||
/** | ||
* Gets the onConfirmEventCreation helper function | ||
* @returns The onConfirmEventCreation function | ||
*/ | ||
export const useOnConfirmEventCreation = () => { | ||
return getEvotingConfig().onConfirmEventCreation; | ||
}; | ||
} | ||
export * from './EvotingHooks'; |
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.