mirror of
https://github.com/bitwarden/browser
synced 2026-01-05 18:13:26 +00:00
refactor feature flag state fetching and update tests
This commit is contained in:
@@ -11,10 +11,9 @@ import { DefaultDomainSettingsService, DomainSettingsService } from "./domain-se
|
||||
|
||||
describe("DefaultDomainSettingsService", () => {
|
||||
let domainSettingsService: DomainSettingsService;
|
||||
const configServiceMock = mock<ConfigService>();
|
||||
let configService: MockProxy<ConfigService>;
|
||||
const mockUserId = Utils.newGuid() as UserId;
|
||||
const accountService: FakeAccountService = mockAccountServiceWith(mockUserId);
|
||||
let mockConfigService: MockProxy<ConfigService>;
|
||||
const fakeStateProvider: FakeStateProvider = new FakeStateProvider(accountService);
|
||||
|
||||
const mockEquivalentDomains = [
|
||||
@@ -24,8 +23,9 @@ describe("DefaultDomainSettingsService", () => {
|
||||
];
|
||||
|
||||
beforeEach(() => {
|
||||
domainSettingsService = new DefaultDomainSettingsService(fakeStateProvider, mockConfigService);
|
||||
jest.spyOn(configServiceMock, "getFeatureFlag$").mockReturnValue(of(false));
|
||||
configService = mock<ConfigService>();
|
||||
configService.getFeatureFlag$.mockImplementation(() => of(false));
|
||||
domainSettingsService = new DefaultDomainSettingsService(fakeStateProvider, configService);
|
||||
|
||||
jest.spyOn(domainSettingsService, "getUrlEquivalentDomains");
|
||||
domainSettingsService.equivalentDomains$ = of(mockEquivalentDomains);
|
||||
|
||||
@@ -99,7 +99,12 @@ export class DefaultDomainSettingsService implements DomainSettingsService {
|
||||
|
||||
this.blockedInteractionsUris$ = this.configService
|
||||
.getFeatureFlag$(FeatureFlag.BlockBrowserInjectionsByDomain)
|
||||
.pipe(switchMap((enabled) => (enabled ? this.blockedInteractionsUrisState.state$ : of({}))));
|
||||
.pipe(
|
||||
switchMap((featureIsEnabled) =>
|
||||
featureIsEnabled ? this.blockedInteractionsUrisState.state$ : of({} as NeverDomains),
|
||||
),
|
||||
map((disabledUris) => (Object.keys(disabledUris).length ? disabledUris : null)),
|
||||
);
|
||||
|
||||
this.equivalentDomainsState = this.stateProvider.getActive(EQUIVALENT_DOMAINS);
|
||||
this.equivalentDomains$ = this.equivalentDomainsState.state$.pipe(map((x) => x ?? null));
|
||||
|
||||
Reference in New Issue
Block a user