Skip to content

Commit

Permalink
Fixes for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pablotransifex committed Feb 22, 2023
1 parent 233a81a commit 93ec30c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface ILanguage {
code: string;
name: string;
localized_name: string;
rtl?: boolean;
}

export interface ITranslateParams {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ describe('LanguagePickerComponent', () => {
sanitize: false,
};
const languages: ILanguage[] = [
{ code: 'en', name: 'English', localized_name: 'English' },
{ code: 'el', name: 'Greek', localized_name: 'Ελληνικά' },
{ code: 'en', name: 'English', localized_name: 'English', rtl: false },
{ code: 'el', name: 'Greek', localized_name: 'Ελληνικά', rtl: false },
];

beforeEach(async () => {
Expand All @@ -48,7 +48,7 @@ describe('LanguagePickerComponent', () => {

it('should get languages', async () => {
// setup
spyOn(service, 'getLanguages').and.returnValue(Promise.resolve(languages));
spyOn(service, 'getLanguages').and.resolveTo(languages);

// act
await component.getLanguages();
Expand All @@ -60,7 +60,7 @@ describe('LanguagePickerComponent', () => {

it('should show a select component with languages', async () => {
// setup
spyOn(service, 'getLanguages').and.returnValue(Promise.resolve(languages));
spyOn(service, 'getLanguages').and.resolveTo(languages);

// act
await component.ngOnInit();
Expand All @@ -76,7 +76,7 @@ describe('LanguagePickerComponent', () => {

it('should detect language change', async () => {
// setup
spyOn(service, 'getLanguages').and.returnValue(Promise.resolve(languages));
spyOn(service, 'getLanguages').and.resolveTo(languages);
spyOn(service, 'setCurrentLocale').and.returnValue(Promise.resolve());
spyOn(component, 'onChange').and.callThrough();

Expand Down Expand Up @@ -104,7 +104,7 @@ describe('LanguagePickerComponent', () => {
component.instance = instance;
const instanceReadySpy = spyOnProperty(component, 'instanceReady', 'get')
.and.returnValue(of(true));
spyOn(service, 'getLanguages').and.returnValue(Promise.resolve(languages));
spyOn(service, 'getLanguages').and.resolveTo(languages);

// act
await instance.ngOnInit();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import { not } from '@angular/compiler/src/output/output_ast';
import { TestBed } from '@angular/core/testing';
import { tx } from '@transifex/native';
import { tx, ILanguage, ITranslationConfig } from '@transifex/native';

import { TranslationService } from '../src/lib/translation.service';
import { ILanguage, ITranslationServiceConfig } from '../src/public-api';
import { ITranslationServiceConfig } from '../src/public-api';

describe('TranslationService', () => {
let service: TranslationService;
const txConfig: ITranslationServiceConfig = {
token: '',
cache: () => { },
cdsHost: '',
errorPolicy: undefined,
filterTags: '',
filterStatus: '',
missingPolicy: undefined,
stringRenderer: undefined,
};
const txTranslationConfig: ITranslationConfig = {
token: '',
cdsHost: '',
filterTags: '',
filterStatus: '',
};
const translationParams = {
_key: '',
Expand All @@ -28,8 +30,8 @@ describe('TranslationService', () => {
sanitize: false,
};
const languages: ILanguage[] = [
{ code: 'en', name: 'English', localized_name: 'English' },
{ code: 'el', name: 'Greek', localized_name: 'Ελληνικά' },
{ code: 'en', name: 'English', localized_name: 'English', rtl: false },
{ code: 'el', name: 'Greek', localized_name: 'Ελληνικά', rtl: false },
];

beforeEach(() => {
Expand Down Expand Up @@ -60,7 +62,7 @@ describe('TranslationService', () => {
// assert
expect(service).toBeTruthy();
expect(tx.init).toHaveBeenCalledWith(
{ ...txConfig },
{ ...txTranslationConfig },
);
});

Expand Down Expand Up @@ -136,7 +138,7 @@ describe('TranslationService', () => {

it('should get languages', async () => {
// setup
spyOn(tx, 'getLanguages').and.returnValue(Promise.resolve(languages));
spyOn(tx, 'getLanguages').and.resolveTo(languages);

// act
const result = await service.getLanguages();
Expand All @@ -148,7 +150,7 @@ describe('TranslationService', () => {

it('should add a controlled instance successfully', async () => {
// setup
spyOn(tx, 'controllerOf').and.returnValue({});
spyOn(tx, 'controllerOf').and.resolveTo();

const instanceConfig = {
token: 'token',
Expand All @@ -166,7 +168,7 @@ describe('TranslationService', () => {

it('should add a not controlled instance successfully', async () => {
// setup
spyOn(tx, 'controllerOf').and.returnValue({});
spyOn(tx, 'controllerOf').and.resolveTo();

const instanceConfig = {
token: 'token',
Expand All @@ -184,7 +186,7 @@ describe('TranslationService', () => {

it('should not add a malformed instance (alias)', async () => {
// setup
spyOn(tx, 'controllerOf').and.returnValue({});
spyOn(tx, 'controllerOf').and.resolveTo();

const instanceConfig = {
token: 'token',
Expand All @@ -200,7 +202,7 @@ describe('TranslationService', () => {

it('should not add a malformed instance (token)', async () => {
// setup
spyOn(tx, 'controllerOf').and.returnValue({});
spyOn(tx, 'controllerOf').and.resolveTo();

const instanceConfig = {
token: '',
Expand All @@ -222,7 +224,7 @@ describe('TranslationService', () => {
controlled: false,
};
await service.addInstance(instanceConfig);
spyOn(tx, 'controllerOf').and.returnValue({});
spyOn(tx, 'controllerOf').and.resolveTo();

// act
const result = await service.addInstance(instanceConfig);
Expand Down Expand Up @@ -252,9 +254,7 @@ describe('TranslationService', () => {

it('should fetch translations on demand without custom instance', async () => {
// setup
spyOn(tx, 'fetchTranslations').and.returnValue(
Promise.resolve({}),
);
spyOn(tx, 'fetchTranslations').and.resolveTo();
spyOn(service, 'getInstance').and.returnValue(
{
currentLocale: 'en',
Expand All @@ -276,9 +276,7 @@ describe('TranslationService', () => {
it('should fetch translations on demand without custom instance no fetched tags',
async () => {
// setup
spyOn(tx, 'fetchTranslations').and.returnValue(
Promise.resolve({}),
);
spyOn(tx, 'fetchTranslations').and.resolveTo();
spyOn(service, 'getInstance').and.returnValue(
{
currentLocale: 'en',
Expand All @@ -299,9 +297,7 @@ describe('TranslationService', () => {

it('should fetch translations on demand with custom instance', async () => {
// setup
spyOn(tx, 'fetchTranslations').and.returnValue(
Promise.resolve({}),
);
spyOn(tx, 'fetchTranslations').and.resolveTo();
spyOn(service, 'getInstance').and.returnValue(
{
currentLocale: 'en',
Expand All @@ -323,9 +319,7 @@ describe('TranslationService', () => {

it('should not fetch translations on demand if no instance', async () => {
// setup
spyOn(tx, 'fetchTranslations').and.returnValue(
Promise.resolve({}),
);
spyOn(tx, 'fetchTranslations').and.resolveTo();

// act
await service.fetchTranslations('tag1');
Expand Down

0 comments on commit 93ec30c

Please sign in to comment.