Bona Iqiniso Application Board

V3BiInfluenceBase

Specification for V3BiInfluenceBase

Attributes

AttributeTypeDescription
influencerstringUnique identifier or name of the influencer
influenceV3BiTranslationBase[]Array of translations describing the influence in different languages

Methods

MethodDescription
constructorInitializes a new instance of V3BiInfluenceBase with the provided influencer and influence.
getInfluencerReturns 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

ScenarioGivenWhenThen
Create an instance with all attributesThe influencer is 'influencer1' and influence is a valid arrayI create a new V3BiInfluenceBase with influencer and influenceThe instance should be created with the specified attributes
Return the correct influence description for a languageThe influencer is 'influencer2' and influence is a valid arrayI call getInfluencer with a valid language codeThe correct influence description for the given language should be returned
Return undefined if the language does not existThe influencer is 'influencer3' and influence is a valid arrayI call getInfluencer with an invalid language codeThe 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

AttributeTypeDescription
influencerstringUnique identifier or name of the influencer
influenceV3BiTranslationBase[]Array of translations describing the influence in different languages
MethodDescription
constructorInitializes a new instance of V3BiInfluenceBase with the provided influencer and influence.
getInfluencerReturns 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.