Specification for V3BiInfluenceBase
Attributes
| Attribute | Type | Description |
|---|---|---|
influencer | string | Unique identifier or name of the influencer |
influence | V3BiTranslationBase[] | Array of translations describing the influence in different languages |
Methods
| Method | Description |
|---|---|
constructor | Initializes a new instance of V3BiInfluenceBase with the provided influencer and influence. |
getInfluencer | Returns the influence description in the specified language, or undefined if the translation is not found. |
Constructor
Signature:
constructor(influencer: string, influence: V3BiTranslationBase[])
Parameters:
influencer(string): Unique identifier or name of the influencer.influence(V3BiTranslationBase[]): Array of translations describing the influence in different languages.
Description:
The constructor initializes the V3BiInfluenceBase instance with the provided influencer and influence.
Method: getInfluencer
Signature:
getInfluencer(language: string): V3BiTranslationBase | undefined
Parameters:
language(string): The language code for which the influence description is requested.
Description:
Returns the influence description in the specified language, or undefined if the translation is not found.
Example Usage
const translations = [
new V3BiTranslationBase('en', 'Influence description in English'),
new V3BiTranslationBase('es', 'Descripción de la influencia en español')
];
const influence = new V3BiInfluenceBase('influencer1', translations);
console.log(influence.getInfluencer('en')); // Output: Influence description in English
console.log(influence.getInfluencer('fr')); // Output: undefined
Scenario Table
| Scenario | Given | When | Then |
|---|---|---|---|
| Create an instance with all attributes | The influencer is 'influencer1' and influence is a valid array | I create a new V3BiInfluenceBase with influencer and influence | The instance should be created with the specified attributes |
| Return the correct influence description for a language | The influencer is 'influencer2' and influence is a valid array | I call getInfluencer with a valid language code | The correct influence description for the given language should be returned |
Return undefined if the language does not exist | The influencer is 'influencer3' and influence is a valid array | I call getInfluencer with an invalid language code | The result should be undefined |
Tests in Jasmine
Here’s how you can create unit tests for V3BiInfluenceBase using the given scenarios:
import { V3BiInfluenceBase } from './V3BiInfluenceBase';
import { V3BiTranslationBase } from './V3BiTranslationBase';
describe('V3BiInfluenceBase', () => {
let translations: V3BiTranslationBase[];
beforeEach(() => {
translations = [
new V3BiTranslationBase('en', 'Influence description in English'),
new V3BiTranslationBase('es', 'Descripción de la influencia en español')
];
});
it('should create an instance with all attributes', () => {
const influence = new V3BiInfluenceBase('influencer1', translations);
expect(influence).toBeTruthy();
expect(influence.influencer).toBe('influencer1');
expect(influence.influence).toEqual(translations);
});
it('should return the correct influence description for a given language', () => {
const influence = new V3BiInfluenceBase('influencer2', translations);
const result = influence.getInfluencer('en');
expect(result?.text).toBe('Influence description in English');
});
it('should return undefined if the language does not exist', () => {
const influence = new V3BiInfluenceBase('influencer3', translations);
const result = influence.getInfluencer('fr');
expect(result).toBeUndefined();
});
});
Overview Table
| Attribute | Type | Description |
|---|---|---|
influencer | string | Unique identifier or name of the influencer |
influence | V3BiTranslationBase[] | Array of translations describing the influence in different languages |
| Method | Description |
|---|---|
constructor | Initializes a new instance of V3BiInfluenceBase with the provided influencer and influence. |
getInfluencer | Returns the influence description in the specified language, or undefined if the translation is not found. |
This setup ensures that the V3BiInfluenceBase class is correctly instantiated and that its methods function as expected under various scenarios.