Skip to content

Commit 8f2fda1

Browse files
committed
fix: updated terms and services test cases
1 parent e7b3e1d commit 8f2fda1

File tree

2 files changed

+191
-202
lines changed

2 files changed

+191
-202
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,201 +1,182 @@
1-
// import {
2-
// ComponentFixture,
3-
// TestBed,
4-
// fakeAsync,
5-
// tick,
6-
// } from '@angular/core/testing';
7-
// import { By } from '@angular/platform-browser';
8-
// import { BehaviorSubject } from 'rxjs';
9-
10-
// import { FirebaseUI } from '../../provider';
11-
// import { TermsAndPrivacyComponent } from './terms-and-privacy.component';
12-
13-
// class MockFirebaseUI {
14-
// private _config = new BehaviorSubject<any>({
15-
// tosUrl: 'https://example.com/terms',
16-
// privacyPolicyUrl: 'https://example.com/privacy',
17-
// });
18-
19-
// private _termsText = new BehaviorSubject<string>('Terms of Service');
20-
// private _privacyText = new BehaviorSubject<string>('Privacy Policy');
21-
// private _templateText = new BehaviorSubject<string>(
22-
// 'By continuing, you agree to our {tos} and {privacy}',
23-
// );
24-
25-
// config() {
26-
// return this._config.asObservable();
27-
// }
28-
29-
// translation(section: string, key: string) {
30-
// if (section === 'labels' && key === 'termsOfService') {
31-
// return this._termsText.asObservable();
32-
// }
33-
// if (section === 'labels' && key === 'privacyPolicy') {
34-
// return this._privacyText.asObservable();
35-
// }
36-
// if (section === 'messages' && key === 'termsAndPrivacy') {
37-
// return this._templateText.asObservable();
38-
// }
39-
// return new BehaviorSubject<string>(`${section}.${key}`).asObservable();
40-
// }
41-
42-
// setConfig(config: any) {
43-
// this._config.next(config);
44-
// }
45-
46-
// setTranslation(section: string, key: string, value: string) {
47-
// if (section === 'labels' && key === 'termsOfService') {
48-
// this._termsText.next(value);
49-
// } else if (section === 'labels' && key === 'privacyPolicy') {
50-
// this._privacyText.next(value);
51-
// } else if (section === 'messages' && key === 'termsAndPrivacy') {
52-
// this._templateText.next(value);
53-
// }
54-
// }
55-
// }
56-
57-
// describe('TermsAndPrivacyComponent', () => {
58-
// let component: TermsAndPrivacyComponent;
59-
// let fixture: ComponentFixture<TermsAndPrivacyComponent>;
60-
// let mockFirebaseUI: MockFirebaseUI;
61-
62-
// beforeEach(async () => {
63-
// mockFirebaseUI = new MockFirebaseUI();
64-
65-
// await TestBed.configureTestingModule({
66-
// imports: [TermsAndPrivacyComponent],
67-
// providers: [{ provide: FirebaseUI, useValue: mockFirebaseUI }],
68-
// }).compileComponents();
69-
70-
// fixture = TestBed.createComponent(TermsAndPrivacyComponent);
71-
// component = fixture.componentInstance;
72-
// fixture.detectChanges();
73-
// });
74-
75-
// it('renders component with terms and privacy links', fakeAsync(() => {
76-
// tick(); // Let async operations complete
77-
// fixture.detectChanges();
78-
79-
// // Check that the container is rendered
80-
// const container = fixture.debugElement.query(By.css('.text-text-muted'));
81-
// expect(container).toBeTruthy();
82-
83-
// // Check that the text contains "By continuing, you agree to our"
84-
// const textContent = container.nativeElement.textContent;
85-
// expect(textContent).toContain('By continuing, you agree to our');
86-
87-
// // Check for the TOS link
88-
// const tosLink = fixture.debugElement.query(
89-
// By.css('a[href="https://example.com/terms"]'),
90-
// );
91-
// expect(tosLink).toBeTruthy();
92-
// expect(tosLink.nativeElement.textContent.trim()).toBe('Terms of Service');
93-
// expect(tosLink.nativeElement.getAttribute('target')).toBe('_blank');
94-
// expect(tosLink.nativeElement.getAttribute('rel')).toBe(
95-
// 'noopener noreferrer',
96-
// );
97-
98-
// // Check for the Privacy Policy link
99-
// const privacyLink = fixture.debugElement.query(
100-
// By.css('a[href="https://example.com/privacy"]'),
101-
// );
102-
// expect(privacyLink).toBeTruthy();
103-
// expect(privacyLink.nativeElement.textContent.trim()).toBe('Privacy Policy');
104-
// expect(privacyLink.nativeElement.getAttribute('target')).toBe('_blank');
105-
// expect(privacyLink.nativeElement.getAttribute('rel')).toBe(
106-
// 'noopener noreferrer',
107-
// );
108-
// }));
109-
110-
// it('does not render when both tosUrl and privacyPolicyUrl are not provided', fakeAsync(() => {
111-
// // Set config with no URLs
112-
// mockFirebaseUI.setConfig({
113-
// tosUrl: undefined,
114-
// privacyPolicyUrl: undefined,
115-
// });
116-
117-
// tick(); // Let async operations complete
118-
// fixture.detectChanges();
119-
120-
// // Check that the container is not rendered
121-
// const container = fixture.debugElement.query(By.css('.text-text-muted'));
122-
// expect(container).toBeFalsy();
123-
// }));
124-
125-
// it('renders with tosUrl when privacyPolicyUrl is not provided', fakeAsync(() => {
126-
// // Set config with only tosUrl
127-
// mockFirebaseUI.setConfig({
128-
// tosUrl: 'https://example.com/terms',
129-
// privacyPolicyUrl: undefined,
130-
// });
131-
132-
// tick(); // Let async operations complete
133-
// fixture.detectChanges();
134-
135-
// // Check that the container is rendered
136-
// const container = fixture.debugElement.query(By.css('.text-text-muted'));
137-
// expect(container).toBeTruthy();
138-
139-
// // Check for the TOS link
140-
// const tosLink = fixture.debugElement.query(
141-
// By.css('a[href="https://example.com/terms"]'),
142-
// );
143-
// expect(tosLink).toBeTruthy();
144-
// expect(tosLink.nativeElement.textContent.trim()).toBe('Terms of Service');
145-
146-
// // Check that privacy link doesn't exist
147-
// const privacyLink = fixture.debugElement.query(
148-
// By.css('a[href="https://example.com/privacy"]'),
149-
// );
150-
// expect(privacyLink).toBeFalsy();
151-
// }));
152-
153-
// it('renders with privacyPolicyUrl when tosUrl is not provided', fakeAsync(() => {
154-
// // Set config with only privacyPolicyUrl
155-
// mockFirebaseUI.setConfig({
156-
// tosUrl: undefined,
157-
// privacyPolicyUrl: 'https://example.com/privacy',
158-
// });
159-
160-
// tick(); // Let async operations complete
161-
// fixture.detectChanges();
162-
163-
// // Check that the container is rendered
164-
// const container = fixture.debugElement.query(By.css('.text-text-muted'));
165-
// expect(container).toBeTruthy();
166-
167-
// // Check that TOS link doesn't exist
168-
// const tosLink = fixture.debugElement.query(
169-
// By.css('a[href="https://example.com/terms"]'),
170-
// );
171-
// expect(tosLink).toBeFalsy();
172-
173-
// // Check for the privacy link
174-
// const privacyLink = fixture.debugElement.query(
175-
// By.css('a[href="https://example.com/privacy"]'),
176-
// );
177-
// expect(privacyLink).toBeTruthy();
178-
// expect(privacyLink.nativeElement.textContent.trim()).toBe('Privacy Policy');
179-
// }));
180-
181-
// it('uses custom template text when provided', fakeAsync(() => {
182-
// // Set custom template
183-
// mockFirebaseUI.setTranslation(
184-
// 'messages',
185-
// 'termsAndPrivacy',
186-
// 'Custom template with {tos} and {privacy}',
187-
// );
188-
189-
// tick(); // Let async operations complete
190-
// fixture.detectChanges();
191-
192-
// // Check that the container is rendered with custom text
193-
// const container = fixture.debugElement.query(By.css('.text-text-muted'));
194-
// expect(container).toBeTruthy();
195-
196-
// const textContent = container.nativeElement.textContent;
197-
// expect(textContent).toContain('Custom template with');
198-
// expect(textContent).toContain('Terms of Service');
199-
// expect(textContent).toContain('Privacy Policy');
200-
// }));
201-
// });
1+
import { TestBed, fakeAsync, tick } from '@angular/core/testing';
2+
import { By } from '@angular/platform-browser';
3+
import { BehaviorSubject } from 'rxjs';
4+
5+
import { FirebaseUI, FirebaseUIPolicies } from '../../provider';
6+
import { TermsAndPrivacyComponent } from './terms-and-privacy.component';
7+
8+
class MockFirebaseUI {
9+
private _termsText = new BehaviorSubject<string>('Terms of Service');
10+
private _privacyText = new BehaviorSubject<string>('Privacy Policy');
11+
private _templateText = new BehaviorSubject<string>(
12+
'By continuing, you agree to our {tos} and {privacy}',
13+
);
14+
15+
translation(section: string, key: string) {
16+
if (section === 'labels' && key === 'termsOfService') {
17+
return this._termsText.asObservable();
18+
}
19+
if (section === 'labels' && key === 'privacyPolicy') {
20+
return this._privacyText.asObservable();
21+
}
22+
if (section === 'messages' && key === 'termsAndPrivacy') {
23+
return this._templateText.asObservable();
24+
}
25+
return new BehaviorSubject<string>(`${section}.${key}`).asObservable();
26+
}
27+
28+
setTranslation(section: string, key: string, value: string) {
29+
if (section === 'labels' && key === 'termsOfService') {
30+
this._termsText.next(value);
31+
} else if (section === 'labels' && key === 'privacyPolicy') {
32+
this._privacyText.next(value);
33+
} else if (section === 'messages' && key === 'termsAndPrivacy') {
34+
this._templateText.next(value);
35+
}
36+
}
37+
}
38+
39+
function configureComponentTest({
40+
tosUrl,
41+
privacyPolicyUrl,
42+
}: {
43+
tosUrl?: string | null;
44+
privacyPolicyUrl?: string | null;
45+
}) {
46+
const mockFirebaseUI = new MockFirebaseUI();
47+
48+
TestBed.configureTestingModule({
49+
imports: [TermsAndPrivacyComponent],
50+
providers: [
51+
{ provide: FirebaseUI, useValue: mockFirebaseUI },
52+
{
53+
provide: FirebaseUIPolicies,
54+
useValue: {
55+
termsOfServiceUrl: tosUrl,
56+
privacyPolicyUrl: privacyPolicyUrl,
57+
},
58+
},
59+
],
60+
}).compileComponents();
61+
62+
const fixture = TestBed.createComponent(TermsAndPrivacyComponent);
63+
const component = fixture.componentInstance;
64+
65+
return { fixture, component, mockFirebaseUI };
66+
}
67+
68+
describe('TermsAndPrivacyComponent', () => {
69+
it('renders component with terms and privacy links', fakeAsync(() => {
70+
const { fixture } = configureComponentTest({
71+
tosUrl: 'https://example.com/terms',
72+
privacyPolicyUrl: 'https://example.com/privacy',
73+
});
74+
75+
tick();
76+
fixture.detectChanges();
77+
78+
const container = fixture.debugElement.query(By.css('.text-text-muted'));
79+
expect(container).toBeTruthy();
80+
81+
const textContent = container.nativeElement.textContent;
82+
expect(textContent).toContain('By continuing, you agree to our');
83+
84+
const tosLink = fixture.debugElement
85+
.queryAll(By.css('a'))
86+
.find((el) => el.nativeElement.textContent.includes('Terms of Service'));
87+
expect(tosLink).toBeTruthy();
88+
expect(tosLink!.nativeElement.getAttribute('target')).toBe('_blank');
89+
expect(tosLink!.nativeElement.getAttribute('rel')).toBe(
90+
'noopener noreferrer',
91+
);
92+
93+
const privacyLink = fixture.debugElement.query(
94+
By.css('a[href="https://example.com/privacy"]'),
95+
);
96+
expect(privacyLink).toBeTruthy();
97+
expect(privacyLink.nativeElement.textContent.trim()).toBe('Privacy Policy');
98+
}));
99+
100+
it('does not render when both tosUrl and privacyPolicyUrl are not provided', fakeAsync(() => {
101+
const { fixture } = configureComponentTest({
102+
tosUrl: null,
103+
privacyPolicyUrl: null,
104+
});
105+
106+
tick();
107+
fixture.detectChanges();
108+
109+
const container = fixture.debugElement.query(By.css('.text-text-muted'));
110+
expect(container).toBeFalsy();
111+
}));
112+
113+
it('renders with tosUrl when privacyPolicyUrl is not provided', fakeAsync(() => {
114+
const { fixture } = configureComponentTest({
115+
tosUrl: 'https://example.com/terms',
116+
privacyPolicyUrl: null,
117+
});
118+
119+
tick();
120+
fixture.detectChanges();
121+
122+
const container = fixture.debugElement.query(By.css('.text-text-muted'));
123+
expect(container).toBeTruthy();
124+
125+
const tosLink = fixture.debugElement.query(
126+
By.css('a[href="https://example.com/terms"]'),
127+
);
128+
expect(tosLink).toBeTruthy();
129+
130+
const privacyLink = fixture.debugElement.query(
131+
By.css('a[href="https://example.com/privacy"]'),
132+
);
133+
expect(privacyLink).toBeFalsy();
134+
}));
135+
136+
it('renders with privacyPolicyUrl when tosUrl is not provided', fakeAsync(() => {
137+
const { fixture } = configureComponentTest({
138+
tosUrl: null,
139+
privacyPolicyUrl: 'https://example.com/privacy',
140+
});
141+
142+
tick();
143+
fixture.detectChanges();
144+
145+
const container = fixture.debugElement.query(By.css('.text-text-muted'));
146+
expect(container).toBeTruthy();
147+
148+
const tosLink = fixture.debugElement.query(
149+
By.css('a[href="https://example.com/terms"]'),
150+
);
151+
expect(tosLink).toBeFalsy();
152+
153+
const privacyLink = fixture.debugElement.query(
154+
By.css('a[href="https://example.com/privacy"]'),
155+
);
156+
expect(privacyLink).toBeTruthy();
157+
}));
158+
159+
it('uses custom template text when provided', fakeAsync(() => {
160+
const { fixture, mockFirebaseUI } = configureComponentTest({
161+
tosUrl: 'https://example.com/terms',
162+
privacyPolicyUrl: 'https://example.com/privacy',
163+
});
164+
165+
mockFirebaseUI.setTranslation(
166+
'messages',
167+
'termsAndPrivacy',
168+
'Custom template with {tos} and {privacy}',
169+
);
170+
171+
tick();
172+
fixture.detectChanges();
173+
174+
const container = fixture.debugElement.query(By.css('.text-text-muted'));
175+
expect(container).toBeTruthy();
176+
177+
const textContent = container.nativeElement.textContent;
178+
expect(textContent).toContain('Custom template with');
179+
expect(textContent).toContain('Terms of Service');
180+
expect(textContent).toContain('Privacy Policy');
181+
}));
182+
});

0 commit comments

Comments
 (0)