A set of sui-studio usable tools.
$ npm install @s-ui/studio-tools --save
Domain builder has the purpose of giving to you the possibility of mocking some of non implemented domain use cases meanwhile your team are developing them.
import { DomainBuilder } from '@s-ui/studio-tools'
import myDomain from 'domain'
const domain = DomainBuilder.extend({ myDomain }).build()
To mock an use case you need to call two functions: 'for' and 'respondWith'
Let's suppose that we want to mock an use case that isn't already implemented. Its name is 'get_products':
import { DomainBuilder } from '@s-ui/studio-tools'
import myDomain from 'domain'
const getProductsResponse = {
success: ['pineapple', 'apple', 'strawberry', 'coffee']
}
const domain = DomainBuilder.extend({ myDomain }).for({useCase: 'get_products'}).respondWith(getProductsResponse).build()
// Execute the use case and check if everything works
domain.get('current_user_use_case').execute().then((products) => {
console.log(products) // ['pineapple', 'apple', 'strawberry', 'coffee']
})
import { DomainBuilder } from '@s-ui/studio-tools'
import myDomain from 'domain'
const getProductsError = {
fail: 'Unexpected error :('
}
const domain = DomainBuilder.extend({ myDomain }).for({useCase: 'get_products'}).respondWith(getProductsError).build()
// Execute the use case and check if everything works
domain.get('current_user_use_case').execute().then((products) => {
// Never will be fired
}).catch((e) => {
console.log(e) // Unexpected error :(
})
THINGS TO KEEP IN MIND:
You CAN'T mock a use case if already exists on the domain. This means that we can ONLY mock use cases that doesn't exist on the domain
Function with the purpose of set our locales on rosseta.
The library accepts two types of flow
- Usecase given translations.
- Object given translations.
The locales are getted using a usecase of a domain. You pass the usecase not the domain.
import { i18n } from '@s-ui/studio-tools'
import myDomain from 'domain'
i18n({ literalsUseCase: myDomain.get('get_literals_from_backend') }).then((rossetaInstance) => {
rossetaInstance.t('myLocaleName');
})
The locales are getted by an object argument. No call is done to any use case.
Dictionary should be formed with this format:
'es-ES': { // Or your iso language
'LOGIN': 'INICIAR SESIÓN', // your locale names
'SIGNUP': 'CREAR UNA CUENTA'
}
import { i18n } from '@s-ui/studio-tools'
import myDomain from 'domain'
import myLocalesDictionary from '../../utils/dictionary' // Or wherever you have your locales object.
i18n({ dictionary: myLocalesDictionary }).then((rossetaInstance) => {
rossetaInstance.t('myLocaleName');
})
The function comes with a little customization feature. You can customizate:
- Culture - default es-ES
- Currency - default EUR
Send custom config is as easy as put a config property on your object arguments:
import { i18n } from '@s-ui/studio-tools'
import myDomain from 'domain'
import myLocalesDictionary from '../../utils/dictionary' // Or wherever you have your locales object.
i18n({
dictionary: myLocalesDictionary,
config: {
currency: 'EUR',
culture: 'es-ES'
}
}).then((rossetaInstance) => {
rossetaInstance.t('myLocaleName');
})