-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathunique_identifier_generator_spec.rb
More file actions
68 lines (55 loc) · 2.26 KB
/
Copy pathunique_identifier_generator_spec.rb
File metadata and controls
68 lines (55 loc) · 2.26 KB
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
RSpec.describe GovukTechDocs::UniqueIdentifierGenerator do
subject { described_class.new }
describe "#create" do
it "lower-cases the text" do
expect(subject.create("Heading", 1)).to eq "heading"
end
it "strips leading and trailing spaces" do
expect(subject.create(" heading ", 1)).to eq "heading"
end
it "replaces non alphanumeric characters with dashes" do
expect(subject.create("Headings (Etc) Are Great", 1)).to eq "headings-etc-are-great"
end
it "does not add dashes at the start or end of the identifier" do
expect(subject.create("(Not (More) Headings!)", 1)).to eq "not-more-headings"
end
it "strips HTML tags" do
expect(subject.create("Using <code>bash</code>", 1)).to eq "using-bash"
end
context "with a parent that is unique" do
it "generates unique headings by prefixing with the parent" do
subject.create("Parent 1", 1)
first_heading = subject.create("The Same Heading", 2)
subject.create("Parent 2", 1)
second_heading = subject.create("The Same Heading", 2)
aggregate_failures do
expect(first_heading).to eq "the-same-heading"
expect(second_heading).to eq "parent-2-the-same-heading"
end
end
end
context "with a parent that is identical" do
it "generates unique headings by suffixing with a number" do
subject.create("The Same Parent", 1)
first_heading = subject.create("The Same Heading", 2)
second_heading = subject.create("The Same Heading", 2)
third_heading = subject.create("The Same Heading", 2)
aggregate_failures do
expect(first_heading).to eq "the-same-heading"
expect(second_heading).to eq "the-same-parent-the-same-heading"
expect(third_heading).to eq "the-same-parent-the-same-heading-2"
end
end
end
context "with no parent" do
it "generates unique headings by suffixing with a number" do
first_heading = subject.create("The Same Heading", 1)
second_heading = subject.create("The Same Heading", 1)
aggregate_failures do
expect(first_heading).to eq "the-same-heading"
expect(second_heading).to eq "the-same-heading-2"
end
end
end
end
end