-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
report(details-renderer): support sub-rows within a table #10084
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2b9babb
initial
connorjclark d73c056
rm row.multi
connorjclark 3848221
tests
connorjclark 774de08
delete code not needed yet
connorjclark 8a5f433
fix types
connorjclark dc75cbf
do not need _ yet
connorjclark 95ab723
dry _getCanonicalizedHeadingsFromTable
connorjclark 50eb275
subRows
connorjclark 0ee5d5a
move type check
connorjclark 878301c
ts
connorjclark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -548,7 +548,7 @@ describe('DetailsRenderer', () => { | |
// itemType is overriden by code object | ||
headings: [{key: 'content', itemType: 'url', text: 'Heading'}], | ||
items: [ | ||
{content: {type: 'code', value: 'code object'}}, | ||
{content: {type: 'code', value: 'https://codeobject.com'}}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The fallback code in the details render will render a URL w/ an invalid url as a |
||
{content: 'https://example.com'}, | ||
], | ||
}; | ||
|
@@ -560,7 +560,7 @@ describe('DetailsRenderer', () => { | |
const codeEl = itemElements[0].firstChild; | ||
assert.equal(codeEl.localName, 'pre'); | ||
assert.ok(codeEl.classList.contains('lh-code')); | ||
assert.equal(codeEl.textContent, 'code object'); | ||
assert.equal(codeEl.textContent, 'https://codeobject.com'); | ||
|
||
// Second item uses the heading's specified type for the column. | ||
const urlEl = itemElements[1].firstChild; | ||
|
@@ -569,5 +569,78 @@ describe('DetailsRenderer', () => { | |
assert.equal(urlEl.title, 'https://example.com'); | ||
assert.equal(urlEl.textContent, 'https://example.com'); | ||
}); | ||
|
||
describe('subRows', () => { | ||
it('renders', () => { | ||
const details = { | ||
type: 'table', | ||
headings: [{key: 'url', itemType: 'url', subRows: {key: 'sources', itemType: 'code'}}], | ||
items: [ | ||
{url: 'https://www.example.com', sources: ['a', 'b', 'c']}, | ||
], | ||
}; | ||
|
||
const el = renderer.render(details); | ||
const columnElement = el.querySelector('td.lh-table-column--url'); | ||
|
||
// First element is the url. | ||
const codeEl = columnElement.firstChild; | ||
assert.equal(codeEl.localName, 'div'); | ||
assert.ok(codeEl.classList.contains('lh-text__url')); | ||
assert.equal(codeEl.textContent, 'https://www.example.com'); | ||
|
||
// Second element lists the multiple values. | ||
const subRowsEl = columnElement.children[1]; | ||
assert.equal(subRowsEl.localName, 'div'); | ||
assert.ok(subRowsEl.classList.contains('lh-sub-rows')); | ||
|
||
const multiValueEls = subRowsEl.querySelectorAll('.lh-sub-row'); | ||
assert.equal(multiValueEls[0].textContent, 'a'); | ||
assert.ok(multiValueEls[0].classList.contains('lh-code')); | ||
assert.equal(multiValueEls[1].textContent, 'b'); | ||
assert.ok(multiValueEls[1].classList.contains('lh-code')); | ||
assert.equal(multiValueEls[2].textContent, 'c'); | ||
assert.ok(multiValueEls[2].classList.contains('lh-code')); | ||
}); | ||
|
||
it('renders, uses heading properties as fallback', () => { | ||
const details = { | ||
type: 'table', | ||
headings: [{key: 'url', itemType: 'url', subRows: {key: 'sources'}}], | ||
items: [ | ||
{ | ||
url: 'https://www.example.com', | ||
sources: [ | ||
'https://www.a.com', | ||
{type: 'code', value: 'https://www.b.com'}, | ||
'https://www.c.com', | ||
], | ||
}, | ||
], | ||
}; | ||
|
||
const el = renderer.render(details); | ||
const columnElement = el.querySelector('td.lh-table-column--url'); | ||
|
||
// First element is the url. | ||
const codeEl = columnElement.firstChild; | ||
assert.equal(codeEl.localName, 'div'); | ||
assert.ok(codeEl.classList.contains('lh-text__url')); | ||
assert.equal(codeEl.textContent, 'https://www.example.com'); | ||
|
||
// Second element lists the multiple values. | ||
const subRowsEl = columnElement.children[1]; | ||
assert.equal(subRowsEl.localName, 'div'); | ||
assert.ok(subRowsEl.classList.contains('lh-sub-rows')); | ||
|
||
const multiValueEls = subRowsEl.querySelectorAll('.lh-sub-row'); | ||
assert.equal(multiValueEls[0].textContent, 'https://www.a.com'); | ||
assert.ok(multiValueEls[0].classList.contains('lh-text__url')); | ||
assert.equal(multiValueEls[1].textContent, 'https://www.b.com'); | ||
assert.ok(multiValueEls[1].classList.contains('lh-code')); | ||
assert.equal(multiValueEls[2].textContent, 'https://www.c.com'); | ||
assert.ok(multiValueEls[2].classList.contains('lh-text__url')); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is unrelated to multi, right? just needed for the eventual js audits?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I noticed it when I was making the js audits. I could pull this out as a one line change. It seems like a mistake to me.