mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 07:23:03 +00:00
63825: use CookieService instead of ClientCookieService
This commit is contained in:
@@ -44,8 +44,8 @@ import { ActivatedRoute, Router } from '@angular/router';
|
|||||||
import { RouteService } from './shared/services/route.service';
|
import { RouteService } from './shared/services/route.service';
|
||||||
import { MockActivatedRoute } from './shared/mocks/mock-active-router';
|
import { MockActivatedRoute } from './shared/mocks/mock-active-router';
|
||||||
import { MockRouter } from './shared/mocks/mock-router';
|
import { MockRouter } from './shared/mocks/mock-router';
|
||||||
import { ClientCookieService } from './shared/services/client-cookie.service';
|
import { CookieService } from './shared/services/cookie.service';
|
||||||
import { MockClientCookieService } from './shared/mocks/mock-client-cookie.service';
|
import { MockCookieService } from './shared/mocks/mock-cookie.service';
|
||||||
|
|
||||||
let comp: AppComponent;
|
let comp: AppComponent;
|
||||||
let fixture: ComponentFixture<AppComponent>;
|
let fixture: ComponentFixture<AppComponent>;
|
||||||
@@ -80,7 +80,7 @@ describe('App component', () => {
|
|||||||
{ provide: MenuService, useValue: menuService },
|
{ provide: MenuService, useValue: menuService },
|
||||||
{ provide: CSSVariableService, useClass: CSSVariableServiceStub },
|
{ provide: CSSVariableService, useClass: CSSVariableServiceStub },
|
||||||
{ provide: HostWindowService, useValue: new HostWindowServiceStub(800) },
|
{ provide: HostWindowService, useValue: new HostWindowServiceStub(800) },
|
||||||
{ provide: ClientCookieService, useValue: new MockClientCookieService()},
|
{ provide: CookieService, useValue: new MockCookieService()},
|
||||||
AppComponent,
|
AppComponent,
|
||||||
RouteService
|
RouteService
|
||||||
],
|
],
|
||||||
|
@@ -34,6 +34,7 @@ import { HostWindowService } from './shared/host-window.service';
|
|||||||
import { Theme } from '../config/theme.inferface';
|
import { Theme } from '../config/theme.inferface';
|
||||||
import { ClientCookieService } from './shared/services/client-cookie.service';
|
import { ClientCookieService } from './shared/services/client-cookie.service';
|
||||||
import { isNotEmpty } from './shared/empty.util';
|
import { isNotEmpty } from './shared/empty.util';
|
||||||
|
import { CookieService } from './shared/services/cookie.service';
|
||||||
|
|
||||||
export const LANG_COOKIE = 'language_cookie';
|
export const LANG_COOKIE = 'language_cookie';
|
||||||
|
|
||||||
@@ -65,7 +66,7 @@ export class AppComponent implements OnInit, AfterViewInit {
|
|||||||
private cssService: CSSVariableService,
|
private cssService: CSSVariableService,
|
||||||
private menuService: MenuService,
|
private menuService: MenuService,
|
||||||
private windowService: HostWindowService,
|
private windowService: HostWindowService,
|
||||||
private clientCookie: ClientCookieService
|
private cookie: CookieService
|
||||||
) {
|
) {
|
||||||
// Load all the languages that are defined as active from the config file
|
// Load all the languages that are defined as active from the config file
|
||||||
translate.addLangs(config.languages.filter((LangConfig) => LangConfig.active === true).map((a) => a.code));
|
translate.addLangs(config.languages.filter((LangConfig) => LangConfig.active === true).map((a) => a.code));
|
||||||
@@ -74,7 +75,7 @@ export class AppComponent implements OnInit, AfterViewInit {
|
|||||||
translate.setDefaultLang(config.defaultLanguage);
|
translate.setDefaultLang(config.defaultLanguage);
|
||||||
|
|
||||||
// Attempt to get the language from a cookie
|
// Attempt to get the language from a cookie
|
||||||
const lang = clientCookie.get(LANG_COOKIE);
|
const lang = cookie.get(LANG_COOKIE);
|
||||||
if (isNotEmpty(lang)) {
|
if (isNotEmpty(lang)) {
|
||||||
// Cookie found
|
// Cookie found
|
||||||
// Use the language from the cookie
|
// Use the language from the cookie
|
||||||
|
@@ -6,9 +6,9 @@ import {HttpClientTestingModule, HttpTestingController} from '@angular/common/ht
|
|||||||
import { GLOBAL_CONFIG } from '../../../config';
|
import { GLOBAL_CONFIG } from '../../../config';
|
||||||
import {LangConfig} from '../../../config/lang-config.interface';
|
import {LangConfig} from '../../../config/lang-config.interface';
|
||||||
import {Observable, of} from 'rxjs';
|
import {Observable, of} from 'rxjs';
|
||||||
import { ClientCookieService } from '../services/client-cookie.service';
|
|
||||||
import { MockClientCookieService } from '../mocks/mock-client-cookie.service';
|
|
||||||
import { By } from '@angular/platform-browser';
|
import { By } from '@angular/platform-browser';
|
||||||
|
import { CookieService } from '../services/cookie.service';
|
||||||
|
import { MockCookieService } from '../mocks/mock-cookie.service';
|
||||||
|
|
||||||
// This test is completely independent from any message catalogs or keys in the codebase
|
// This test is completely independent from any message catalogs or keys in the codebase
|
||||||
// The translation module is instantiated with these bogus messages that we aren't using anyway.
|
// The translation module is instantiated with these bogus messages that we aren't using anyway.
|
||||||
@@ -31,12 +31,12 @@ class CustomLoader implements TranslateLoader {
|
|||||||
/* tslint:enable:quotemark */
|
/* tslint:enable:quotemark */
|
||||||
/* tslint:enable:object-literal-key-quotes */
|
/* tslint:enable:object-literal-key-quotes */
|
||||||
|
|
||||||
let clientCookie: ClientCookieService;
|
let cookie: CookieService;
|
||||||
|
|
||||||
describe('LangSwitchComponent', () => {
|
describe('LangSwitchComponent', () => {
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
clientCookie = Object.assign(new MockClientCookieService());
|
cookie = Object.assign(new MockCookieService());
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('with English and Deutsch activated, English as default', () => {
|
describe('with English and Deutsch activated, English as default', () => {
|
||||||
@@ -73,7 +73,7 @@ describe('LangSwitchComponent', () => {
|
|||||||
providers: [
|
providers: [
|
||||||
TranslateService,
|
TranslateService,
|
||||||
{ provide: GLOBAL_CONFIG, useValue: mockConfig },
|
{ provide: GLOBAL_CONFIG, useValue: mockConfig },
|
||||||
{ provide: ClientCookieService, useValue: clientCookie }
|
{ provide: CookieService, useValue: cookie }
|
||||||
]
|
]
|
||||||
}).compileComponents()
|
}).compileComponents()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
@@ -111,7 +111,7 @@ describe('LangSwitchComponent', () => {
|
|||||||
describe('when selecting a language', () => {
|
describe('when selecting a language', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
spyOn(translate, 'use');
|
spyOn(translate, 'use');
|
||||||
spyOn(clientCookie, 'set');
|
spyOn(cookie, 'set');
|
||||||
const langItem = fixture.debugElement.query(By.css('.dropdown-item')).nativeElement;
|
const langItem = fixture.debugElement.query(By.css('.dropdown-item')).nativeElement;
|
||||||
langItem.click();
|
langItem.click();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
@@ -122,7 +122,7 @@ describe('LangSwitchComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should set the client\'s language cookie', () => {
|
it('should set the client\'s language cookie', () => {
|
||||||
expect(clientCookie.set).toHaveBeenCalled();
|
expect(cookie.set).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -162,7 +162,7 @@ describe('LangSwitchComponent', () => {
|
|||||||
providers: [
|
providers: [
|
||||||
TranslateService,
|
TranslateService,
|
||||||
{ provide: GLOBAL_CONFIG, useValue: mockConfig },
|
{ provide: GLOBAL_CONFIG, useValue: mockConfig },
|
||||||
{ provide: ClientCookieService, useValue: clientCookie }
|
{ provide: CookieService, useValue: cookie }
|
||||||
]
|
]
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
translate = TestBed.get(TranslateService);
|
translate = TestBed.get(TranslateService);
|
||||||
|
@@ -4,6 +4,7 @@ import {TranslateService} from '@ngx-translate/core';
|
|||||||
import {LangConfig} from '../../../config/lang-config.interface';
|
import {LangConfig} from '../../../config/lang-config.interface';
|
||||||
import { ClientCookieService } from '../services/client-cookie.service';
|
import { ClientCookieService } from '../services/client-cookie.service';
|
||||||
import { LANG_COOKIE } from '../../app.component';
|
import { LANG_COOKIE } from '../../app.component';
|
||||||
|
import { CookieService } from '../services/cookie.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-lang-switch',
|
selector: 'ds-lang-switch',
|
||||||
@@ -26,7 +27,7 @@ export class LangSwitchComponent implements OnInit {
|
|||||||
constructor(
|
constructor(
|
||||||
@Inject(GLOBAL_CONFIG) public config: GlobalConfig,
|
@Inject(GLOBAL_CONFIG) public config: GlobalConfig,
|
||||||
public translate: TranslateService,
|
public translate: TranslateService,
|
||||||
public clientCookie: ClientCookieService
|
public cookie: CookieService
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,7 +56,7 @@ export class LangSwitchComponent implements OnInit {
|
|||||||
*/
|
*/
|
||||||
useLang(lang: string) {
|
useLang(lang: string) {
|
||||||
this.translate.use(lang);
|
this.translate.use(lang);
|
||||||
this.clientCookie.set(LANG_COOKIE, lang);
|
this.cookie.set(LANG_COOKIE, lang);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* Mock for [[ClientCookieService]]
|
* Mock for [[CookieService]]
|
||||||
*/
|
*/
|
||||||
export class MockClientCookieService {
|
export class MockCookieService {
|
||||||
cookies: Map<string, string>;
|
cookies: Map<string, string>;
|
||||||
|
|
||||||
constructor(cookies: Map<string, string> = new Map()) {
|
constructor(cookies: Map<string, string> = new Map()) {
|
Reference in New Issue
Block a user