Bona Iqiniso Application Board

V3BiAlertArray

Specification for V3BiAlertArray

Attributes

AttributeTypeDescription
itemsV3BiAlertBase[]Array of V3BiAlertBase objects representing different alerts

Methods

MethodDescription
constructorInitializes a new instance of V3BiAlertArray with the provided array of alerts.
getAlertReturns a V3BiAlertBase object that matches the specified reference, or undefined if not found.
getAlertByLanguageReturns the alert message in the specified language for the given reference, or ‘unknown alert’ if not found.
addAlertAdds a new V3BiAlertBase to the items array if an alert with the same reference does not already exist.

Constructor

Signature:

constructor(items: V3BiAlertBase[])

Parameters:

  • items (V3BiAlertBase[]): Array of V3BiAlertBase objects representing different alerts.

Description:
The constructor initializes the V3BiAlertArray instance with the provided items array.

Method: getAlert

Signature:

getAlert(reference: string): V3BiAlertBase | undefined

Parameters:

  • reference (string): The reference identifier of the alert to retrieve.

Description:
Returns the V3BiAlertBase object that matches the specified reference, or undefined if no match is found.

Method: getAlertByLanguage

Signature:

getAlertByLanguage(reference: string, language: string): string

Parameters:

  • reference (string): The reference identifier of the alert to retrieve.
  • language (string): The language code for which the alert message is requested.

Description:
Returns the alert message in the specified language for the given reference, or ‘unknown alert’ if the alert is not found.

Method: addAlert

Signature:

addAlert(reference: string, state: string, translations: V3BiTranslationBase[]): void

Parameters:

  • reference (string): The reference identifier of the alert to add.
  • state (string): The state of the alert.
  • translations (V3BiTranslationBase[]): Array of translations for different languages.

Description:
Adds a new V3BiAlertBase to the items array if an alert with the same reference does not already exist.

Example Usage

const translations = [
  new V3BiTranslationBase('en', 'Error occurred'),
  new V3BiTranslationBase('es', 'Ocurrió un error')
];

const alertArray = new V3BiAlertArray([]);
alertArray.addAlert('alert1', 'error', translations);
console.log(alertArray.getAlertByLanguage('alert1', 'en')); // Output: Error occurred
console.log(alertArray.getAlertByLanguage('alert1', 'fr')); // Output: unknown alert

Scenario Table

ScenarioGivenWhenThen
Create an instance with alertsAn array of V3BiAlertBase objectsI create a new V3BiAlertArray with the provided alerts arrayThe instance should be created with the specified items array
Return an alert by referenceA V3BiAlertArray with multiple alertsI call getAlert with a valid referenceThe V3BiAlertBase object with the matching reference should be returned
Return undefined if reference does not existA V3BiAlertArray without the specified referenceI call getAlert with an invalid referenceundefined should be returned
Return an alert message in a specified languageA V3BiAlertArray with an alert containing translationsI call getAlertByLanguage with a valid reference and languageThe alert message in the specified language should be returned
Return ‘unknown alert’ if language does not existA V3BiAlertArray with an alert but without the languageI call getAlertByLanguage with a valid reference but invalid language‘unknown alert’ should be returned
Add a new alertA V3BiAlertArray without an alert with the same referenceI call addAlert with a new reference, state, and translationsThe new V3BiAlertBase should be added to the items array
Do not add a duplicate alertA V3BiAlertArray with an existing alert with the same referenceI call addAlert with a duplicate referenceThe new V3BiAlertBase should not be added to the items array

These scenarios ensure that the V3BiAlertArray class behaves correctly under different conditions and covers the creation of instances, retrieval of alerts by reference and language, and the addition of new alerts.