Specification for V3BiAlertArray
Attributes
| Attribute | Type | Description |
|---|---|---|
items | V3BiAlertBase[] | Array of V3BiAlertBase objects representing different alerts |
Methods
| Method | Description |
|---|---|
constructor | Initializes a new instance of V3BiAlertArray with the provided array of alerts. |
getAlert | Returns a V3BiAlertBase object that matches the specified reference, or undefined if not found. |
getAlertByLanguage | Returns the alert message in the specified language for the given reference, or ‘unknown alert’ if not found. |
addAlert | Adds 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 ofV3BiAlertBaseobjects 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
| Scenario | Given | When | Then |
|---|---|---|---|
| Create an instance with alerts | An array of V3BiAlertBase objects | I create a new V3BiAlertArray with the provided alerts array | The instance should be created with the specified items array |
| Return an alert by reference | A V3BiAlertArray with multiple alerts | I call getAlert with a valid reference | The V3BiAlertBase object with the matching reference should be returned |
| Return undefined if reference does not exist | A V3BiAlertArray without the specified reference | I call getAlert with an invalid reference | undefined should be returned |
| Return an alert message in a specified language | A V3BiAlertArray with an alert containing translations | I call getAlertByLanguage with a valid reference and language | The alert message in the specified language should be returned |
| Return ‘unknown alert’ if language does not exist | A V3BiAlertArray with an alert but without the language | I call getAlertByLanguage with a valid reference but invalid language | ‘unknown alert’ should be returned |
| Add a new alert | A V3BiAlertArray without an alert with the same reference | I call addAlert with a new reference, state, and translations | The new V3BiAlertBase should be added to the items array |
| Do not add a duplicate alert | A V3BiAlertArray with an existing alert with the same reference | I call addAlert with a duplicate reference | The 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.