Skip to content

Commit 9bf2f0f

Browse files
committed
test(cypress): docs addons on catalog sub-pages
Signed-off-by: Camila Belo <camilaibs@gmail.com>
1 parent 89e7885 commit 9bf2f0f

2 files changed

Lines changed: 151 additions & 1 deletion

File tree

cypress/src/integration/plugins/catalog.spec.ts

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,118 @@ describe('Catalog', () => {
8282
.contains('Sub-page 1')
8383
.should('be.visible');
8484
});
85+
86+
it('Should render addons on docs tab homepage', () => {
87+
cy.loginAsGuest();
88+
89+
cy.visit('/catalog');
90+
91+
cy.contains('techdocs-e2e-fixture').click();
92+
93+
cy.location().should(loc => {
94+
expect(loc.pathname).to.eq(
95+
'/catalog/default/component/techdocs-e2e-fixture',
96+
);
97+
});
98+
99+
cy.getCatalogDocsTab().click();
100+
101+
cy.wait(300);
102+
103+
cy.getTechDocsShadowRoot()
104+
.find('h1')
105+
.contains('Home page')
106+
.should('be.visible');
107+
108+
// highlight a snippet of text
109+
cy.getTechDocsShadowRoot()
110+
.find('article > p')
111+
.then($el => {
112+
const el = $el[0];
113+
const document = el.ownerDocument;
114+
const range = document.createRange();
115+
range.selectNodeContents(el);
116+
document?.getSelection()?.removeAllRanges();
117+
document?.getSelection()?.addRange(range);
118+
});
119+
120+
cy.document().trigger('selectionchange');
121+
122+
// wait for new issue default debounce time
123+
cy.wait(600);
124+
125+
// assert that the new issue button has a right url
126+
cy.getTechDocsShadowRoot()
127+
.contains('Open new Github issue')
128+
.should(
129+
'have.attr',
130+
'href',
131+
'https://github.com/backstage/backstage/issues/new?title=Documentation%20feedback%3A%20This%20is%20a%20basic%20documentation%20used%20for%20end-to-end%20tests.&body=%23%23%20Documentation%20Feedback%20%F0%9F%93%9D%0A%0A%20%23%23%23%23%20The%20highlighted%20text%3A%20%0A%0A%20%3E%20This%20is%20a%20basic%20documentation%20used%20for%20end-to-end%20tests.%0A%0A%20%23%23%23%23%20The%20comment%20on%20the%20text%3A%20%0A%20_%3Ereplace%20this%20line%20with%20your%20comment%3C_%0A%0A%20___%0ABackstage%20URL%3A%20%3Chttp%3A%2F%2Flocalhost%3A7007%2Fcatalog%2Fdefault%2Fcomponent%2Ftechdocs-e2e-fixture%2Fdocs%3E%20%0AMarkdown%20URL%3A%20%3Chttps%3A%2F%2Fgithub.com%2Fbackstage%2Fbackstage%2Fblob%2Fmaster%2Fcypress%2Ffixtures%2Fdocs%2Findex.md%3E',
132+
);
133+
});
134+
135+
it('Should render addons on docs tab sup-page', () => {
136+
cy.loginAsGuest();
137+
138+
cy.visit('/catalog');
139+
140+
cy.contains('techdocs-e2e-fixture').click();
141+
142+
cy.location().should(loc => {
143+
expect(loc.pathname).to.eq(
144+
'/catalog/default/component/techdocs-e2e-fixture',
145+
);
146+
});
147+
148+
cy.getCatalogDocsTab().click();
149+
150+
cy.wait(300);
151+
152+
cy.getTechDocsShadowRoot()
153+
.find('h1')
154+
.contains('Home page')
155+
.should('be.visible');
156+
157+
cy.getTechDocsShadowRoot().within(() => {
158+
cy.getTechDocsNavigation().find('a').contains('Sub-page 1').click();
159+
});
160+
161+
cy.location().should(loc => {
162+
expect(loc.pathname).to.eq(
163+
'/catalog/default/component/techdocs-e2e-fixture/docs/sub-page-one/',
164+
);
165+
});
166+
167+
cy.getTechDocsShadowRoot()
168+
.find('h1')
169+
.contains('Sub-page 1')
170+
.should('be.visible');
171+
172+
// highlight a snippet of text
173+
cy.getTechDocsShadowRoot()
174+
.find('#section-11')
175+
.then($el => {
176+
const el = $el[0];
177+
const document = el.ownerDocument;
178+
const range = document.createRange();
179+
range.selectNodeContents(el);
180+
document?.getSelection()?.removeAllRanges();
181+
document?.getSelection()?.addRange(range);
182+
});
183+
184+
cy.document().trigger('selectionchange');
185+
186+
// wait for new issue default debounce time
187+
cy.wait(600);
188+
189+
// assert that the new issue button has a right url
190+
cy.getTechDocsShadowRoot()
191+
.contains('Open new Github issue')
192+
.should(
193+
'have.attr',
194+
'href',
195+
'https://github.com/backstage/backstage/issues/new?title=Documentation%20feedback%3A%20Section%201.1%C2%B6&body=%23%23%20Documentation%20Feedback%20%F0%9F%93%9D%0A%0A%20%23%23%23%23%20The%20highlighted%20text%3A%20%0A%0A%20%3E%20Section%201.1%C2%B6%0A%0A%20%23%23%23%23%20The%20comment%20on%20the%20text%3A%20%0A%20_%3Ereplace%20this%20line%20with%20your%20comment%3C_%0A%0A%20___%0ABackstage%20URL%3A%20%3Chttp%3A%2F%2Flocalhost%3A7007%2Fcatalog%2Fdefault%2Fcomponent%2Ftechdocs-e2e-fixture%2Fdocs%2Fsub-page-one%2F%3E%20%0AMarkdown%20URL%3A%20%3Chttps%3A%2F%2Fgithub.com%2Fbackstage%2Fbackstage%2Fblob%2Fmaster%2Fcypress%2Ffixtures%2Fdocs%2Fsub-page-one.md%3E',
196+
);
197+
});
85198
});
86199
});

cypress/src/integration/plugins/techdocs.spec.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ describe('TechDocs', () => {
9999
});
100100

101101
describe('Rendering TechDocs Addons', () => {
102-
it('should render a content addon', () => {
102+
it('should render a content addon in homepage', () => {
103103
cy.visit('/docs/default/Component/techdocs-e2e-fixture');
104104

105105
cy.contains('e2e Fixture Documentation');
@@ -130,6 +130,43 @@ describe('TechDocs', () => {
130130
'https://github.com/backstage/backstage/issues/new?title=Documentation%20feedback%3A%20This%20is%20a%20basic%20documentation%20used%20for%20end-to-end%20tests.&body=%23%23%20Documentation%20Feedback%20%F0%9F%93%9D%0A%0A%20%23%23%23%23%20The%20highlighted%20text%3A%20%0A%0A%20%3E%20This%20is%20a%20basic%20documentation%20used%20for%20end-to-end%20tests.%0A%0A%20%23%23%23%23%20The%20comment%20on%20the%20text%3A%20%0A%20_%3Ereplace%20this%20line%20with%20your%20comment%3C_%0A%0A%20___%0ABackstage%20URL%3A%20%3Chttp%3A%2F%2Flocalhost%3A7007%2Fdocs%2Fdefault%2FComponent%2Ftechdocs-e2e-fixture%3E%20%0AMarkdown%20URL%3A%20%3Chttps%3A%2F%2Fgithub.com%2Fbackstage%2Fbackstage%2Fblob%2Fmaster%2Fcypress%2Ffixtures%2Fdocs%2Findex.md%3E',
131131
);
132132
});
133+
134+
it('should render a content addon in sub-pages', () => {
135+
cy.visit('/docs/default/Component/techdocs-e2e-fixture');
136+
137+
cy.contains('e2e Fixture Documentation');
138+
139+
// open sub-page
140+
cy.getTechDocsShadowRoot().within(() => {
141+
cy.getTechDocsNavigation().find('a').contains('Sub-page 1').click();
142+
});
143+
144+
// highlight a snippet of text
145+
cy.getTechDocsShadowRoot()
146+
.find('#section-11')
147+
.then($el => {
148+
const el = $el[0];
149+
const document = el.ownerDocument;
150+
const range = document.createRange();
151+
range.selectNodeContents(el);
152+
document?.getSelection()?.removeAllRanges();
153+
document?.getSelection()?.addRange(range);
154+
});
155+
156+
cy.document().trigger('selectionchange');
157+
158+
// wait for new issue default debounce time
159+
cy.wait(600);
160+
161+
// assert that the new issue button has a right url
162+
cy.getTechDocsShadowRoot()
163+
.contains('Open new Github issue')
164+
.should(
165+
'have.attr',
166+
'href',
167+
'https://github.com/backstage/backstage/issues/new?title=Documentation%20feedback%3A%20Section%201.1%C2%B6&body=%23%23%20Documentation%20Feedback%20%F0%9F%93%9D%0A%0A%20%23%23%23%23%20The%20highlighted%20text%3A%20%0A%0A%20%3E%20Section%201.1%C2%B6%0A%0A%20%23%23%23%23%20The%20comment%20on%20the%20text%3A%20%0A%20_%3Ereplace%20this%20line%20with%20your%20comment%3C_%0A%0A%20___%0ABackstage%20URL%3A%20%3Chttp%3A%2F%2Flocalhost%3A7007%2Fdocs%2Fdefault%2FComponent%2Ftechdocs-e2e-fixture%2Fsub-page-one%2F%3E%20%0AMarkdown%20URL%3A%20%3Chttps%3A%2F%2Fgithub.com%2Fbackstage%2Fbackstage%2Fblob%2Fmaster%2Fcypress%2Ffixtures%2Fdocs%2Fsub-page-one.md%3E',
168+
);
169+
});
133170
});
134171

135172
describe('Navigating within TechDocs', () => {

0 commit comments

Comments
 (0)