1
+ import config from 'config' ;
1
2
import { waitFor } from '@testing-library/react' ;
2
3
import userEvent from '@testing-library/user-event' ;
3
4
@@ -17,6 +18,7 @@ import {
17
18
CLIENT_APP_FIREFOX ,
18
19
SET_VIEW_CONTEXT ,
19
20
} from 'amo/constants' ;
21
+ import { hrefLangs } from 'amo/languages' ;
20
22
import { fetchAddon , loadAddon } from 'amo/reducers/addons' ;
21
23
import {
22
24
changeLocation ,
@@ -700,6 +702,56 @@ describe(__filename, () => {
700
702
expect ( getElements ( 'meta[name="robots"]' ) ) . toHaveLength ( 0 ) ;
701
703
} ) ;
702
704
705
+ it ( 'renders a canonical link for the list page with alternates' , async ( ) => {
706
+ renderWithAddonAndReviews ( ) ;
707
+
708
+ const getExpectedURL = ( locale , app ) => {
709
+ return `${ config . get (
710
+ 'baseURL' ,
711
+ ) } /${ locale } /${ app } /addon/${ defaultSlug } /reviews/`;
712
+ } ;
713
+
714
+ await waitFor ( ( ) =>
715
+ expect ( getElement ( 'link[rel="canonical"]' ) ) . toHaveAttribute (
716
+ 'href' ,
717
+ getExpectedURL ( 'en-US' , 'firefox' ) ,
718
+ ) ,
719
+ ) ;
720
+
721
+ await waitFor ( ( ) =>
722
+ expect ( getElement ( 'link[rel="alternate"]' ) ) . toBeInTheDocument ( ) ,
723
+ ) ;
724
+
725
+ expect ( getElements ( 'link[rel="alternate"]' ) ) . toHaveLength (
726
+ hrefLangs . length ,
727
+ ) ;
728
+
729
+ const hrefLangsMap = config . get ( 'hrefLangsMap' ) ;
730
+ hrefLangs . forEach ( ( hrefLang ) => {
731
+ const locale = hrefLangsMap [ hrefLang ] || hrefLang ;
732
+ expect (
733
+ getElement ( `link[rel="alternate"][hreflang="${ hrefLang } "]` ) ,
734
+ ) . toHaveAttribute ( 'href' , getExpectedURL ( locale , 'firefox' ) ) ;
735
+ } ) ;
736
+ } ) ;
737
+
738
+ it ( 'renders a canonical with no query string' , async ( ) => {
739
+ renderWithAddonAndReviews ( { score : 5 } ) ;
740
+
741
+ const getExpectedURL = ( locale , app ) => {
742
+ return `${ config . get (
743
+ 'baseURL' ,
744
+ ) } /${ locale } /${ app } /addon/${ defaultSlug } /reviews/`;
745
+ } ;
746
+
747
+ await waitFor ( ( ) =>
748
+ expect ( getElement ( 'link[rel="canonical"]' ) ) . toHaveAttribute (
749
+ 'href' ,
750
+ getExpectedURL ( 'en-US' , 'firefox' ) ,
751
+ ) ,
752
+ ) ;
753
+ } ) ;
754
+
703
755
it ( 'renders a robots meta tag when there is a featured review' , async ( ) => {
704
756
const reviews = [
705
757
{ ...fakeReview , id : 1 , score : 1 } ,
0 commit comments