Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ describe('assemblerStrategy with a non-default rootPath', () => {
expect(assemblerStrategy.getPathFromUrl('/pricing')).toBe(null)
})

it('still excludes the /api sub-app under the prefixed root', () => {
it('allows the /api sub-app under the prefixed root through HTMX', () => {
expect(
assemblerStrategy.isExternalDocsUrl(
'/elastic/docs-builder/docs/3634/api/elasticsearch'
)
).toBe(true)
).toBe(false)
})

it('accepts absolute self-links on non-elastic.co hosts (previews)', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ import type { HtmxUrlStrategy } from './types'
// rootPath is '/docs' on prod but varies on PR previews (e.g.
// '/elastic/docs-builder/docs/3634'), so it can't be hardcoded.
const root = config.rootPath.replace(/\/$/, '')
const apiRoot = `${root}/api`
const isDocsPath = (path: string) =>
path === root || path.startsWith(`${root}/`)

export const assemblerStrategy: HtmxUrlStrategy = {
isExternalDocsUrl: (url) =>
url === apiRoot || url.startsWith(`${apiRoot}/`),
isExternalDocsUrl: () => false,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[MEDIUM] Update assembler HTMX link tests to match this new contract

This change flips API links from external to internal for assembler, but the existing suite still asserts the old behavior in useHtmxLink.test.tsx (for example, isExternalDocsUrl('/docs/api') === true and expecting hx-disable on /docs/api/...). That makes the test suite inconsistent with this implementation and likely to fail once those tests run. Please update those assertions to validate HTMX handling for API links instead of external-link handling.


getPathFromUrl: (url) => {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ describe('useHtmxContainer', () => {
})
})

describe('/docs/api paths should be disabled', () => {
it('should add hx-disable for /docs/api paths', () => {
describe('/docs/api paths should be enabled', () => {
it('should call htmx.process for /docs/api paths', () => {
render(
<TestContainer html='<a href="/docs/api/elasticsearch">API Link</a>' />
)
Expand All @@ -79,11 +79,11 @@ describe('useHtmxContainer', () => {
const anchor = container.querySelector('a')

expect(anchor).toHaveAttribute('href', '/docs/api/elasticsearch')
expect(anchor).toHaveAttribute('hx-disable', 'true')
expect(mockHtmx.process).not.toHaveBeenCalled()
expect(anchor).not.toHaveAttribute('hx-disable')
expect(mockHtmx.process).toHaveBeenCalledWith(container)
})

it('should add hx-disable for full elastic.co/docs/api URLs', () => {
it('should call htmx.process for full elastic.co/docs/api URLs', () => {
render(
<TestContainer html='<a href="https://www.elastic.co/docs/api/kibana">API Link</a>' />
)
Expand All @@ -92,8 +92,8 @@ describe('useHtmxContainer', () => {
const anchor = container.querySelector('a')

expect(anchor).toHaveAttribute('href', '/docs/api/kibana')
expect(anchor).toHaveAttribute('hx-disable', 'true')
expect(mockHtmx.process).not.toHaveBeenCalled()
expect(anchor).not.toHaveAttribute('hx-disable')
expect(mockHtmx.process).toHaveBeenCalledWith(container)
})
})

Expand Down Expand Up @@ -184,9 +184,9 @@ describe('useHtmxContainer', () => {
expect(internalLink).toHaveAttribute('href', '/docs/elasticsearch')
expect(internalLink).not.toHaveAttribute('hx-disable')

// API link - htmx disabled
// API link - htmx enabled
expect(apiLink).toHaveAttribute('href', '/docs/api/kibana')
expect(apiLink).toHaveAttribute('hx-disable', 'true')
expect(apiLink).not.toHaveAttribute('hx-disable')

// External link - htmx disabled
expect(externalLink).toHaveAttribute(
Expand All @@ -199,12 +199,12 @@ describe('useHtmxContainer', () => {
expect(mockHtmx.process).toHaveBeenCalledWith(container)
})

it('should not call htmx.process if all links are external', () => {
it('should not call htmx.process if all links are truly external', () => {
render(
<TestContainer
html={`
<a href="/docs/api/elasticsearch">API</a>
<a href="https://github.com/elastic">GitHub</a>
<a href="https://www.elastic.co/products">Products</a>
`}
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ const TestLink = ({ url }: { url: string }) => {
}

describe('isExternalDocsUrl', () => {
it('should return true for /docs/api', () => {
expect(isExternalDocsUrl('/docs/api')).toBe(true)
it('should return false for /docs/api', () => {
expect(isExternalDocsUrl('/docs/api')).toBe(false)
})

it('should return true for /docs/api/ paths', () => {
expect(isExternalDocsUrl('/docs/api/')).toBe(true)
expect(isExternalDocsUrl('/docs/api/elasticsearch')).toBe(true)
expect(isExternalDocsUrl('/docs/api/kibana/some/path')).toBe(true)
it('should return false for /docs/api/ paths', () => {
expect(isExternalDocsUrl('/docs/api/')).toBe(false)
expect(isExternalDocsUrl('/docs/api/elasticsearch')).toBe(false)
expect(isExternalDocsUrl('/docs/api/kibana/some/path')).toBe(false)
})

it('should return false for regular docs paths', () => {
Expand Down Expand Up @@ -238,13 +238,13 @@ describe('useHtmxLink', () => {
expect(anchor).not.toHaveAttribute('hx-disable')
})

it('should add hx-disable for /docs/api paths', () => {
it('should call htmx.process for /docs/api paths', () => {
render(<TestLink url="/docs/api/elasticsearch" />)

const anchor = screen.getByTestId('test-link')

expect(anchor).toHaveAttribute('hx-disable', 'true')
expect(mockHtmx.process).not.toHaveBeenCalled()
expect(anchor).not.toHaveAttribute('hx-disable')
expect(mockHtmx.process).toHaveBeenCalledWith(anchor)
})

it('should add hx-disable for external URLs', () => {
Expand Down
Loading