Skip to content

Commit dbe8d43

Browse files
committed
PD-5332
1 parent c8bedc4 commit dbe8d43

5 files changed

Lines changed: 204 additions & 168 deletions

File tree

projects/orcid-registry-ui/src/lib/components/auth-challenge/auth-challenge.component.html

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,7 @@ <h1 class="orc-font-heading-small text-center font-normal" i18n>
2525
>and</ng-container
2626
>&nbsp;}@if (showTwoFactorField) {<ng-container i18n
2727
>a two-factor authentication code</ng-container
28-
>&nbsp;}<ng-container
29-
i18n="
30-
auth challenge action clause|Clause in the verification sentence before
31-
a dynamic action fragment. actionDescription is a translated verb phrase
32-
like 'disable 2FA', 'unlink the alternate sign in account', or 'complete
33-
your password reset'. Keep the sentence natural in your
34-
language.@@authChallenge.toActionDescription"
35-
>to {{ actionDescription }}</ng-container
28+
>&nbsp;}<ng-container>{{ actionDescription }}</ng-container
3629
>@if (boldText) {&nbsp;<b>{{ boldText }}</b
3730
>}@if (trailingText) {&nbsp;{{ trailingText }}}
3831
</p>

src/app/core/wordpress/wordpress.service.spec.ts

Lines changed: 59 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,19 @@ import {
44
HttpClientTestingModule,
55
HttpTestingController,
66
} from '@angular/common/http/testing'
7-
import { RouterTestingModule } from '@angular/router/testing'
8-
import { PlatformInfoService } from 'src/app/cdk/platform-info'
9-
import { WINDOW_PROVIDERS } from 'src/app/cdk/window'
107
import { LOCALE_ID } from '@angular/core'
118

12-
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'
13-
149
describe('WordpressService', () => {
1510
let service: WordpressService
1611
let httpMock: HttpTestingController
1712

13+
const primaryIndexUrl = `${runtimeEnvironment.WORDPRESS_S3}/index.html`
14+
const fallbackIndexUrl = `${runtimeEnvironment.WORDPRESS_S3_FALLBACK}/index.html`
15+
1816
beforeEach(() => {
1917
TestBed.configureTestingModule({
20-
imports: [HttpClientTestingModule, RouterTestingModule],
21-
providers: [
22-
WINDOW_PROVIDERS,
23-
PlatformInfoService,
24-
{ provide: LOCALE_ID, useValue: 'en' },
25-
],
18+
imports: [HttpClientTestingModule],
19+
providers: [{ provide: LOCALE_ID, useValue: 'en' }],
2620
})
2721
service = TestBed.inject(WordpressService)
2822
httpMock = TestBed.inject(HttpTestingController)
@@ -36,133 +30,102 @@ describe('WordpressService', () => {
3630
expect(service).toBeTruthy()
3731
})
3832

39-
it('should fetch home page post from primary URL', () => {
40-
const mockHtml = '<html></html>'
33+
it('fetches home page post from primary URL', () => {
34+
const mockHtml =
35+
'<html><head></head><body><img src="./assets/image.png"></body></html>'
36+
4137
service.getHomePagePost().subscribe((html) => {
42-
expect(html).toContain(mockHtml)
38+
expect(html).toContain(`${runtimeEnvironment.WORDPRESS_S3}/assets/image.png`)
4339
})
4440

45-
const req = httpMock.expectOne(
46-
`${runtimeEnvironment.WORDPRESS_S3}/index.html`
47-
)
41+
const req = httpMock.expectOne(primaryIndexUrl)
4842
expect(req.request.method).toBe('GET')
4943
req.flush(mockHtml)
5044
})
5145

52-
it('should fetch home page post from fallback URL when primary fails', () => {
46+
it('fetches home page post from fallback URL when primary fails', () => {
5347
const mockHtml = '<html></html>'
48+
5449
service.getHomePagePost().subscribe((html) => {
5550
expect(html).toContain(mockHtml)
5651
})
5752

58-
const primaryReq = httpMock.expectOne(
59-
`${runtimeEnvironment.WORDPRESS_S3}/index.html`
60-
)
53+
const primaryReq = httpMock.expectOne(primaryIndexUrl)
6154
primaryReq.flush(null, { status: 500, statusText: 'Server Error' })
6255

63-
const fallbackReq = httpMock.expectOne(
64-
`${runtimeEnvironment.WORDPRESS_S3_FALLBACK}/index.html`
65-
)
56+
const fallbackReq = httpMock.expectOne(fallbackIndexUrl)
6657
expect(fallbackReq.request.method).toBe('GET')
6758
fallbackReq.flush(mockHtml)
6859
})
6960

70-
it('should fetch home page CSS from primary URL', () => {
71-
const mockCss = 'body { margin: 0; }'
61+
it('fetches home page CSS from the stylesheet declared in index.html', () => {
62+
const mockIndex =
63+
'<html><head><link href="./wordpress-homepage-d4235c1c61.css" rel="stylesheet" /></head><body></body></html>'
64+
const mockCss = '.hero{background:url("assets/bg.png")}'
65+
7266
service.getHomePageCSS().subscribe((css) => {
73-
expect(css).toContain(mockCss)
67+
expect(css).toContain(`${runtimeEnvironment.WORDPRESS_S3}/assets/bg.png`)
7468
})
7569

76-
const req = httpMock.expectOne(
77-
`${runtimeEnvironment.WORDPRESS_S3}/wordpress-homepage.css`
70+
const indexReq = httpMock.expectOne(primaryIndexUrl)
71+
indexReq.flush(mockIndex)
72+
const cssReq = httpMock.expectOne(
73+
`${runtimeEnvironment.WORDPRESS_S3}/wordpress-homepage-d4235c1c61.css`
7874
)
79-
expect(req.request.method).toBe('GET')
80-
req.flush(mockCss)
75+
cssReq.flush(mockCss)
8176
})
8277

83-
it('should fetch home page CSS from fallback URL when primary fails', () => {
84-
const mockCss = 'body { margin: 0; }'
78+
it('falls back to legacy CSS path if index.html has no stylesheet', () => {
79+
const mockIndex = '<html><head></head><body></body></html>'
80+
const mockCss = 'body{margin:0}'
81+
8582
service.getHomePageCSS().subscribe((css) => {
8683
expect(css).toContain(mockCss)
8784
})
8885

89-
const primaryReq = httpMock.expectOne(
86+
const indexReq = httpMock.expectOne(primaryIndexUrl)
87+
indexReq.flush(mockIndex)
88+
const cssReq = httpMock.expectOne(
9089
`${runtimeEnvironment.WORDPRESS_S3}/wordpress-homepage.css`
9190
)
92-
primaryReq.flush(null, { status: 500, statusText: 'Server Error' })
93-
94-
const fallbackReq = httpMock.expectOne(
95-
`${runtimeEnvironment.WORDPRESS_S3_FALLBACK}/wordpress-homepage.css`
96-
)
97-
expect(fallbackReq.request.method).toBe('GET')
98-
fallbackReq.flush(mockCss)
91+
cssReq.flush(mockCss)
9992
})
10093

101-
it('should fetch home page JS from primary URL', () => {
102-
const mockJs = 'console.log("Hello, World!");'
103-
service.getHomePageJS().subscribe((js) => {
104-
expect(js).toContain(mockJs)
105-
})
94+
it('fetches home page JS from script declared in index.html', () => {
95+
const mockIndex =
96+
'<html><head><script defer src="./wordpress-homepage-64bd37a0a7.js"></script></head><body></body></html>'
97+
const mockJs = 'const image = "./assets/test.png"'
10698

107-
const req = httpMock.expectOne(
108-
`${runtimeEnvironment.WORDPRESS_S3}/wordpress-homepage.js`
109-
)
110-
expect(req.request.method).toBe('GET')
111-
req.flush(mockJs)
112-
})
113-
114-
it('should fetch home page JS from fallback URL when primary fails', () => {
115-
const mockJs = 'console.log("Hello, World!");'
11699
service.getHomePageJS().subscribe((js) => {
117-
expect(js).toContain(mockJs)
118-
})
119-
120-
const primaryReq = httpMock.expectOne(
121-
`${runtimeEnvironment.WORDPRESS_S3}/wordpress-homepage.js`
122-
)
123-
primaryReq.flush(null, { status: 500, statusText: 'Server Error' })
124-
125-
const fallbackReq = httpMock.expectOne(
126-
`${runtimeEnvironment.WORDPRESS_S3_FALLBACK}/wordpress-homepage.js`
127-
)
128-
expect(fallbackReq.request.method).toBe('GET')
129-
fallbackReq.flush(mockJs)
130-
})
131-
132-
it('should fetch home page post from primary URL and update asset paths', () => {
133-
const mockHtml =
134-
'<html><head></head><body><img src="./assets/image.png"></body></html>'
135-
const expectedHtml = `<html><head></head><body><img src="${runtimeEnvironment.WORDPRESS_S3}/assets/image.png"></body></html>`
136-
137-
service.getHomePagePost().subscribe((html) => {
138-
expect(html).toBe(expectedHtml)
100+
expect(js).toContain(
101+
`const image = "${runtimeEnvironment.WORDPRESS_S3}/assets/test.png"`
102+
)
139103
})
140104

141-
const req = httpMock.expectOne(
142-
`${runtimeEnvironment.WORDPRESS_S3}/index.html`
105+
const indexReq = httpMock.expectOne(primaryIndexUrl)
106+
indexReq.flush(mockIndex)
107+
const jsReq = httpMock.expectOne(
108+
`${runtimeEnvironment.WORDPRESS_S3}/wordpress-homepage-64bd37a0a7.js`
143109
)
144-
expect(req.request.method).toBe('GET')
145-
req.flush(mockHtml)
110+
jsReq.flush(mockJs)
146111
})
147112

148-
it('should fetch home page post from fallback URL and update asset paths when primary fails', () => {
149-
const mockHtml =
150-
'<html><head></head><body><img src="./assets/image.png"></body></html>'
151-
const expectedHtml = `<html><head></head><body><img src="${runtimeEnvironment.WORDPRESS_S3_FALLBACK}/assets/image.png"></body></html>`
113+
it('fetches module JS from script declared in index.html', () => {
114+
const mockIndex =
115+
'<html><head><script type="module" src="./wordpress-homepage-modules-34238353bb.js"></script></head><body></body></html>'
116+
const mockJs = 'const icon = "./assets/icon.svg"'
152117

153-
service.getHomePagePost().subscribe((html) => {
154-
expect(html).toBe(expectedHtml)
118+
service.getHomePageModulesJS().subscribe((js) => {
119+
expect(js).toContain(
120+
`const icon = "${runtimeEnvironment.WORDPRESS_S3}/assets/icon.svg"`
121+
)
155122
})
156123

157-
const primaryReq = httpMock.expectOne(
158-
`${runtimeEnvironment.WORDPRESS_S3}/index.html`
159-
)
160-
primaryReq.flush(null, { status: 500, statusText: 'Server Error' })
161-
162-
const fallbackReq = httpMock.expectOne(
163-
`${runtimeEnvironment.WORDPRESS_S3_FALLBACK}/index.html`
124+
const indexReq = httpMock.expectOne(primaryIndexUrl)
125+
indexReq.flush(mockIndex)
126+
const jsReq = httpMock.expectOne(
127+
`${runtimeEnvironment.WORDPRESS_S3}/wordpress-homepage-modules-34238353bb.js`
164128
)
165-
expect(fallbackReq.request.method).toBe('GET')
166-
fallbackReq.flush(mockHtml)
129+
jsReq.flush(mockJs)
167130
})
168131
})

0 commit comments

Comments
 (0)