@@ -19,6 +19,7 @@ import {
19
19
INSTALL_SOURCE_SUGGESTIONS ,
20
20
MOZILLA_COLLECTIONS_EDIT ,
21
21
} from 'amo/constants' ;
22
+ import { hrefLangs } from 'amo/languages' ;
22
23
import {
23
24
FETCH_CURRENT_COLLECTION ,
24
25
FETCH_CURRENT_COLLECTION_PAGE ,
@@ -63,6 +64,7 @@ import {
63
64
fakeI18n ,
64
65
fakePreview ,
65
66
getElement ,
67
+ getElements ,
66
68
getMockConfig ,
67
69
renderPage as defaultRender ,
68
70
screen ,
@@ -1147,6 +1149,49 @@ describe(__filename, () => {
1147
1149
) ;
1148
1150
} ) ;
1149
1151
1152
+ it ( 'renders canonical and alternate links for mozilla collections' , async ( ) => {
1153
+ renderWithCollection ( {
1154
+ detailProps : { authorId : mozillaUserId } ,
1155
+ userId : mozillaUserId ,
1156
+ } ) ;
1157
+
1158
+ const getExpectedURL = ( locale , app ) => {
1159
+ return `${ config . get (
1160
+ 'baseURL' ,
1161
+ ) } /${ locale } /${ app } /collections/${ mozillaUserId } /${ defaultSlug } /`;
1162
+ } ;
1163
+
1164
+ await waitFor ( ( ) =>
1165
+ expect ( getElement ( 'link[rel="canonical"]' ) ) . toHaveAttribute (
1166
+ 'href' ,
1167
+ getExpectedURL ( 'en-US' , 'firefox' ) ,
1168
+ ) ,
1169
+ ) ;
1170
+
1171
+ await waitFor ( ( ) =>
1172
+ expect ( getElement ( 'link[rel="alternate"]' ) ) . toBeInTheDocument ( ) ,
1173
+ ) ;
1174
+
1175
+ expect ( getElements ( 'link[rel="alternate"]' ) ) . toHaveLength ( hrefLangs . length ) ;
1176
+
1177
+ const hrefLangsMap = config . get ( 'hrefLangsMap' ) ;
1178
+ hrefLangs . forEach ( ( hrefLang ) => {
1179
+ const locale = hrefLangsMap [ hrefLang ] || hrefLang ;
1180
+ expect (
1181
+ getElement ( `link[rel="alternate"][hreflang="${ hrefLang } "]` ) ,
1182
+ ) . toHaveAttribute ( 'href' , getExpectedURL ( locale , 'firefox' ) ) ;
1183
+ } ) ;
1184
+ } ) ;
1185
+
1186
+ it ( 'does not render canonical and alternate links for non-mozilla collections' , async ( ) => {
1187
+ renderWithCollection ( ) ;
1188
+
1189
+ await waitFor ( ( ) =>
1190
+ expect ( getElement ( 'meta[name="description"]' ) ) . toBeInTheDocument ( ) ,
1191
+ ) ;
1192
+ expect ( getElements ( 'link[rel="canonical"]' ) ) . toHaveLength ( 0 ) ;
1193
+ } ) ;
1194
+
1150
1195
describe ( 'errorHandler - extractId' , ( ) => {
1151
1196
it ( 'returns a unique ID based on params' , ( ) => {
1152
1197
const props = {
0 commit comments