File: breadcrumbs_schema_markup_spec.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (121 lines) | stat: -rw-r--r-- 4,243 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Breadcrumbs schema markup', :aggregate_failures, feature_category: :shared do
  let_it_be(:user) { create(:user) }
  let_it_be(:project) { create(:project, :public, namespace: user.namespace) }
  let_it_be(:issue) { create(:issue, project: project) }
  let_it_be(:group) { create(:group, :public) }
  let_it_be(:subgroup) { create(:group, :public, parent: group) }
  let_it_be(:group_project) { create(:project, :public, namespace: subgroup) }
  let_it_be(:wiki_home_page) { create(:wiki_page, project: project, title: 'home') }
  let_it_be(:wiki_sub_page) { create(:wiki_page, project: project, title: 'home/subpage') }

  it 'generates the breadcrumb schema for user projects' do
    visit project_url(project)

    item_list = get_schema_content

    expect(item_list.size).to eq 2
    expect(item_list[0]['name']).to eq project.namespace.name
    expect(item_list[0]['item']).to eq user_url(project.first_owner)

    expect(item_list[1]['name']).to eq project.name
    expect(item_list[1]['item']).to eq project_url(project)
  end

  it 'generates the breadcrumb schema for group projects' do
    visit project_url(group_project)

    item_list = get_schema_content

    expect(item_list.size).to eq 3
    expect(item_list[0]['name']).to eq group.name
    expect(item_list[0]['item']).to eq group_url(group)

    expect(item_list[1]['name']).to eq subgroup.name
    expect(item_list[1]['item']).to eq group_url(subgroup)

    expect(item_list[2]['name']).to eq group_project.name
    expect(item_list[2]['item']).to eq project_url(group_project)
  end

  it 'generates the breadcrumb schema for group' do
    visit group_url(subgroup)

    item_list = get_schema_content

    expect(item_list.size).to eq 2
    expect(item_list[0]['name']).to eq group.name
    expect(item_list[0]['item']).to eq group_url(group)

    expect(item_list[1]['name']).to eq subgroup.name
    expect(item_list[1]['item']).to eq group_url(subgroup)
  end

  it 'generates the breadcrumb schema for issues' do
    visit project_issues_url(project)

    item_list = get_schema_content

    expect(item_list.size).to eq 3
    expect(item_list[0]['name']).to eq project.namespace.name
    expect(item_list[0]['item']).to eq user_url(project.first_owner)

    expect(item_list[1]['name']).to eq project.name
    expect(item_list[1]['item']).to eq project_url(project)

    expect(item_list[2]['name']).to eq 'Issues'
    expect(item_list[2]['item']).to eq project_issues_url(project)
  end

  it 'generates the breadcrumb schema for specific issue' do
    visit project_issue_url(project, issue)

    item_list = get_schema_content

    expect(item_list.size).to eq 4
    expect(item_list[0]['name']).to eq project.namespace.name
    expect(item_list[0]['item']).to eq user_url(project.first_owner)

    expect(item_list[1]['name']).to eq project.name
    expect(item_list[1]['item']).to eq project_url(project)

    expect(item_list[2]['name']).to eq 'Issues'
    expect(item_list[2]['item']).to eq project_issues_url(project)

    expect(item_list[3]['name']).to eq issue.to_reference
    expect(item_list[3]['item']).to eq project_issue_url(project, issue)
  end

  it 'generates the breadcrumb schema for wiki pages' do
    visit project_wiki_path(project, wiki_sub_page)

    item_list = get_schema_content

    expect(item_list.size).to eq 5
    expect(item_list[0]['name']).to eq project.namespace.name
    expect(item_list[0]['item']).to eq user_url(project.first_owner)

    expect(item_list[1]['name']).to eq project.name
    expect(item_list[1]['item']).to eq project_url(project)

    expect(item_list[2]['name']).to eq 'Wiki'
    expect(item_list[2]['item']).to eq project_wiki_url(project, wiki_home_page)

    expect(item_list[3]['name']).to eq 'Home'
    expect(item_list[3]['item']).to eq "#{project_wiki_url(project, wiki_home_page)}/"

    expect(item_list[4]['name']).to eq 'subpage'
    expect(item_list[4]['item']).to eq project_wiki_url(project, wiki_sub_page)
  end

  def get_schema_content
    content = find('script[type="application/ld+json"]', visible: false).text(:all)

    expect(content).not_to be_nil

    Gitlab::Json.parse(content)['itemListElement']
  end
end