Skip to content
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

Component-Specific CSS Selector Tests #1574

Merged
merged 48 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
03537e3
added first pass at making a working css selector test for components
mxriverlynn Nov 3, 2022
2cb6eca
working on a bit more code organization and error message for failed …
mxriverlynn Nov 3, 2022
fee5bf6
loop through all the components with previews, and test the selectors…
mxriverlynn Nov 3, 2022
500f9a6
correcting the test method name generation
mxriverlynn Nov 3, 2022
4586618
Merge remote-tracking branch 'origin/main' into mxriverlynn/component…
mxriverlynn Nov 3, 2022
558a8c8
better failure message and code to generate it
mxriverlynn Nov 3, 2022
f0f2e28
improving assertion so it doesn't muddy failure messages with the def…
mxriverlynn Nov 3, 2022
59773f3
further improvements to the failure message
mxriverlynn Nov 3, 2022
23576d5
ignored 'to' selector
mxriverlynn Nov 3, 2022
63dea07
rubocop cleanup
mxriverlynn Nov 3, 2022
fde18ee
code cleanup for remaining selectors
mxriverlynn Nov 3, 2022
b517060
update ignored_selectors to allow global vs component specific ignore…
mxriverlynn Nov 3, 2022
68675cd
added a few comments about the dynamic test generation
mxriverlynn Nov 3, 2022
5e4c78a
adding a few previews to banner, to help coverage of the selectors an…
mxriverlynn Nov 3, 2022
20f01b0
another round of previews for banner
mxriverlynn Nov 3, 2022
1e6572d
correcting rendering of banner previews
mxriverlynn Nov 4, 2022
0c189a6
typo
mxriverlynn Nov 4, 2022
b4f5e79
Update test/components/css/css_selector_test.rb
mxriverlynn Nov 8, 2022
b11c361
Merge remote-tracking branch 'origin/main' into mxriverlynn/component…
mxriverlynn Nov 8, 2022
aa3d7c5
rubocop cleanup
mxriverlynn Nov 8, 2022
12c23e3
improving test comments
mxriverlynn Nov 8, 2022
1613097
correcting banner to alpha in preview
mxriverlynn Nov 8, 2022
34ae502
added dismissable preview for banner
mxriverlynn Nov 8, 2022
c00343f
Merge remote-tracking branch 'origin/main' into mxriverlynn/component…
mxriverlynn Nov 9, 2022
a089996
ignore the banner close selector since it's not used at the moment
mxriverlynn Nov 9, 2022
43e8c0c
correcting comment style
mxriverlynn Nov 9, 2022
66373d2
rebuilt segmented control preview to include more of the available op…
mxriverlynn Nov 9, 2022
bc741d0
segmented control selector ignore and question
mxriverlynn Nov 9, 2022
1bfae15
correcting method named, and adding full width icon only preview
mxriverlynn Nov 9, 2022
4ca094f
full width sizes for segmented previews
mxriverlynn Nov 9, 2022
6e7bcd0
correcting full width examples for segmented control
mxriverlynn Nov 9, 2022
6c2b5c7
added changeset
mxriverlynn Nov 9, 2022
4610aa1
adding progress bar size previews
mxriverlynn Nov 9, 2022
809b13f
Merge remote-tracking branch 'origin/main' into mxriverlynn/component…
mxriverlynn Nov 10, 2022
83495b7
added Counter previews to demonstrate various rounding options
mxriverlynn Nov 10, 2022
aeeae66
ignore Counter .ociton selector
mxriverlynn Nov 10, 2022
e533709
added some preview groups to banner preview
mxriverlynn Nov 10, 2022
085ddf9
moved component specific css test to new folder
mxriverlynn Nov 10, 2022
e366725
added component css specific test run
mxriverlynn Nov 10, 2022
36d2b19
Update .github/workflows/test_css.yml
mxriverlynn Nov 10, 2022
50f9c4f
Merge remote-tracking branch 'origin/main' into mxriverlynn/component…
mxriverlynn Nov 10, 2022
d59febe
move css tests into test.yml
mxriverlynn Nov 10, 2022
fa3a4de
Generating component snapshots
mxriverlynn Nov 10, 2022
c2d1677
Merge remote-tracking branch 'origin/mxriverlynn/component-css-select…
mxriverlynn Nov 10, 2022
2abdde5
correcting preview rendering for segmented control tests
mxriverlynn Nov 10, 2022
49ed298
removing comment that included an ampersand, because it was causing a…
mxriverlynn Nov 10, 2022
91187ee
reset folder what's on main
mxriverlynn Nov 10, 2022
fa62e91
Generating component snapshots
mxriverlynn Nov 10, 2022
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
5 changes: 5 additions & 0 deletions .changeset/rare-birds-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/view-components': patch
---

adding a test suite to show all component-specific selectors are used in previews, and updating various component previews for lookbook
22 changes: 22 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,25 @@ jobs:
- name: Failure
if: ${{ steps.auto-commit.outputs.changes_detected == 'true' || steps.playwright-run.outcome == 'failure' }}
run: exit 1
selectors:
name: CSS coverage
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.0'
bundler-cache: true
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 16
cache: 'npm'
- name: NPM Build
run: npm ci
- name: Build Output Selectors
run: script/build-assets
- name: Test CSS
run: bundle exec rake test:component_css
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/components/primer/alpha/banner.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
}
}

/* is this used anywhere? could not find any use, but unsure */
& .Banner-close {
grid-area: close;
margin-left: var(--primer-controlStack-medium-gap-condensed, 8px);
Expand Down
1 change: 1 addition & 0 deletions app/components/primer/alpha/segmented_control.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
justify-content: center;
}

/* is .Button-withTooltip used anywhere? can't find use of it */
& .Button--iconOnly,
& .Button-withTooltip {
width: 100%;
Expand Down
4 changes: 0 additions & 4 deletions app/components/primer/beta/button.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@
cursor: not-allowed;
box-shadow: none;
}

/* &:focus {
@mixin focusOutline;
} */
Comment on lines -56 to -58
Copy link
Contributor Author

Choose a reason for hiding this comment

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

with this commented out, PCSS copies it as a literal comment with no parsing into the final css output. this was causing test/components/component_css_test.rb to fail in the test suite, because that test looks for the presence of any & regardless of context

}

.Button-withTooltip {
Expand Down
1 change: 1 addition & 0 deletions app/components/primer/beta/counter.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
display: none;
}

/* Is this selector used? could not find any use of it */
& .octicon {
vertical-align: text-top;
opacity: 0.8;
Expand Down
8 changes: 8 additions & 0 deletions lib/tasks/test.rake
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ namespace :test do
]
end

Rake::TestTask.new(:component_css) do |t|
t.warning = false
t.libs << "test"
t.test_files = FileList[
"test/css/**/*_test.rb"
]
end

Rake::TestTask.new(:lib) do |t|
t.warning = false
t.libs << "test"
Expand Down
45 changes: 44 additions & 1 deletion previews/primer/alpha/banner_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,52 @@ def playground(full: false, full_when_narrow: false, dismissible: false, icon: :

# @label Default
def default
render(Primer::Alpha::Banner.new) { "This is a banner!" }
render(Primer::Alpha::Banner.new) { "This is a banner." }
end

# @!group Schemes
#
# @label Default scheme
def scheme_default
render(Primer::Alpha::Banner.new) { "This is a default banner." }
end

# @label Danger
def scheme_danger
render(Primer::Alpha::Banner.new(scheme: :danger)) { "This is a danger banner!" }
end

# @label Success
def scheme_success
render(Primer::Alpha::Banner.new(scheme: :success)) { "This is a success banner!" }
end

# @label Warning
def scheme_warning
render(Primer::Alpha::Banner.new(scheme: :warning)) { "This is a warning banner!" }
end
#
# @!endgroup

# @label Dismissable
def dismissable
render(Primer::Alpha::Banner.new(dismissable: true, reappear: true)) { "This is a dismissable banner." }
end

# @!group Full Width
#
# @label Full width
def full_width
render(Primer::Alpha::Banner.new(full: true)) { "This is a full width banner." }
end

# @label Full width in Narrow Viewport
def full_width_in_narrow_viewport
render(Primer::Alpha::Banner.new(full: true, full_when_narrow: true)) { "This is a full width banner in a narrow viewport." }
end
#
# @!endgroup

# @label With action button
#
# @param full toggle
Expand Down
126 changes: 106 additions & 20 deletions previews/primer/alpha/segmented_control_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,53 +23,139 @@ def playground(full_width: false, hide_labels: false, size: :medium, icon: :none
end
end

# @param full_width [Boolean] toggle
# @param size select [small, medium, large]
def default(full_width: false, size: :medium)
render(Primer::Alpha::SegmentedControl.new("aria-label": "File view", full_width: full_width, size: size)) do |c|
# @label Default
def default
render(Primer::Alpha::SegmentedControl.new("aria-label": "File view")) do |c|
c.with_item(label: "Preview", selected: true)
c.with_item(label: "Raw")
c.with_item(label: "Blame")
end
end

# @param hide_labels [Boolean] toggle
# @param size select [small, medium, large]
def full_width(hide_labels: false, size: :medium)
render(Primer::Alpha::SegmentedControl.new("aria-label": "File view", full_width: true, hide_labels: hide_labels, size: size)) do |c|
c.with_item(label: "Preview", icon: (hide_labels ? :zap : nil), selected: true)
c.with_item(label: "Raw", icon: (hide_labels ? :zap : nil))
c.with_item(label: "Blame", icon: (hide_labels ? :zap : nil))
# @!group Full width
# @label Size small
def full_width_small(hide_labels: false, size: :small)
render(Primer::Alpha::SegmentedControl.new("aria-label": "File view", full_width: true, size: :small)) do |c|
c.with_item(label: "Preview", selected: true)
c.with_item(label: "Raw")
c.with_item(label: "Blame")
end
end

# @param full_width [Boolean] toggle
# @param size select [small, medium, large]
def icons_and_text(full_width: false, size: :medium)
render(Primer::Alpha::SegmentedControl.new("aria-label": "File view", full_width: full_width, size: size)) do |c|
# @label Size medium
def full_width_medium(hide_labels: false, size: :medium)
render(Primer::Alpha::SegmentedControl.new("aria-label": "File view", full_width: true, size: :medium)) do |c|
c.with_item(label: "Preview", selected: true)
c.with_item(label: "Raw")
c.with_item(label: "Blame")
end
end

# @label Size large
def full_width_large(hide_labels: false, size: :large)
render(Primer::Alpha::SegmentedControl.new("aria-label": "File view", full_width: true, size: :large)) do |c|
c.with_item(label: "Preview", selected: true)
c.with_item(label: "Raw")
c.with_item(label: "Blame")
end
end
# @!endgroup

# @!group Icons and text
# @label Size small
def icons_and_text_small
render(Primer::Alpha::SegmentedControl.new("aria-label": "File view", size: :small)) do |c|
c.with_item(label: "Preview", icon: :eye, selected: true)
c.with_item(label: "Raw", icon: :"file-code")
c.with_item(label: "Blame", icon: :people)
end
end

# @param full_width [Boolean] toggle
# @param size select [small, medium, large]
def icons_only(full_width: false, size: :medium)
render(Primer::Alpha::SegmentedControl.new("aria-label": "File view", full_width: full_width, hide_labels: true, size: size)) do |c|
# @label Size medium
def icons_and_text_medium
render(Primer::Alpha::SegmentedControl.new("aria-label": "File view", size: :medium)) do |c|
c.with_item(label: "Preview", icon: :eye, selected: true)
c.with_item(label: "Raw", icon: :"file-code")
c.with_item(label: "Blame", icon: :people)
end
end

# @label Size large
def icons_and_text_large
render(Primer::Alpha::SegmentedControl.new("aria-label": "File view", size: :large)) do |c|
c.with_item(label: "Preview", icon: :eye, selected: true)
c.with_item(label: "Raw", icon: :"file-code")
c.with_item(label: "Blame", icon: :people)
end
end
# @!endgroup

# @!group Icons only
# @label Size small
def icon_only_small
render(Primer::Alpha::SegmentedControl.new("aria-label": "File view", hide_labels: true, size: :small)) do |c|
c.with_item(label: "Preview", icon: :eye, selected: true)
c.with_item(label: "Raw", icon: :"file-code")
c.with_item(label: "Blame", icon: :people)
end
end

# @label Size medium
def icon_only_medium
render(Primer::Alpha::SegmentedControl.new("aria-label": "File view", hide_labels: true, size: :medium)) do |c|
c.with_item(label: "Preview", icon: :eye, selected: true)
c.with_item(label: "Raw", icon: :"file-code")
c.with_item(label: "Blame", icon: :people)
end
end

# @label Size large
def icon_only_large
render(Primer::Alpha::SegmentedControl.new("aria-label": "File view", hide_labels: true, size: :large)) do |c|
c.with_item(label: "Preview", icon: :eye, selected: true)
c.with_item(label: "Raw", icon: :"file-code")
c.with_item(label: "Blame", icon: :people)
end
end

# @label Full width, size small
def icon_only_full_width_small
render(Primer::Alpha::SegmentedControl.new("aria-label": "File view", hide_labels: true, full_width: true, size: :small)) do |c|
c.with_item(label: "Preview", icon: :eye, selected: true)
c.with_item(label: "Raw", icon: :"file-code")
c.with_item(label: "Blame", icon: :people)
end
end

# @label Full width, size medium
def icon_only_full_width_medium
render(Primer::Alpha::SegmentedControl.new("aria-label": "File view", hide_labels: true, full_width: true, size: :medium)) do |c|
c.with_item(label: "Preview", icon: :eye, selected: true)
c.with_item(label: "Raw", icon: :"file-code")
c.with_item(label: "Blame", icon: :people)
end
end

# @label Full width, size large
def icon_only_full_width_large
render(Primer::Alpha::SegmentedControl.new("aria-label": "File view", hide_labels: true, full_width: true, size: :large)) do |c|
c.with_item(label: "Preview", icon: :eye, selected: true)
c.with_item(label: "Raw", icon: :"file-code")
c.with_item(label: "Blame", icon: :people)
end
end
# @!endgroup

def with_links_as_tags
# NOTE: this preview uses a group to force it's display below the other groups
# @!group With link as tag
def with_link_as_tag
render(Primer::Alpha::SegmentedControl.new) do |c|
c.with_item(tag: :a, href: "#", label: "Preview", icon: :eye, selected: true)
c.with_item(tag: :a, href: "#", label: "Raw", icon: :"file-code")
c.with_item(tag: :a, href: "#", label: "Blame", icon: :people)
end
end
# @!endgroup
end
end
end
63 changes: 55 additions & 8 deletions previews/primer/beta/counter_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,67 @@ def playground(count: 1_000, limit: nil, round: false, hide_if_zero: false, sche
end

# @label Default Options
#
# @param count number
# @param limit number
# @param hide_if_zero toggle
# @param round toggle
# @param scheme [Symbol] select [[Default, default], [Primary, primary], [Secondary, secondary]]]
def default(count: 1_000, limit: nil, round: false, hide_if_zero: false, scheme: :default)
render(Primer::Beta::Counter.new(count: count, round: round, limit: limit, hide_if_zero: hide_if_zero, scheme: scheme))
def default
render(Primer::Beta::Counter.new(count: 1_000))
end

# @label With Text
def with_text
render(Primer::Beta::Counter.new(text: "∞"))
end

# @!group Color Schemes
#
# @label Default
def color_scheme_default
render(Primer::Beta::Counter.new(count: 1_000))
end

# @label Primary
def color_scheme_primary
render(Primer::Beta::Counter.new(count: 1_000, scheme: :primary))
end

# @label Secondary
def color_scheme_secondary
render(Primer::Beta::Counter.new(count: 1_000, scheme: :secondary))
end
#
# @!endgroup

# @!group Rounded Number
#
# @label Default (No Rounding)
def rounding_default
render(Primer::Beta::Counter.new(count: 1_234))
end

# @label Rounded Above 1,000
def rounding_above_1000
render(Primer::Beta::Counter.new(count: 1_234, round: true))
end

# @label Rounded Below 1,000
def rounding_below_1000
render(Primer::Beta::Counter.new(count: 999, round: true))
end

# @label Rounded Large Numbers w/ Default Limit
def rounding_large_number
render(Primer::Beta::Counter.new(count: 4_567_890, round: true))
end

# @label Rounded Large Numbers, Less Than Custom Limit
def rounding_large_number_less_than_custom_limit
render(Primer::Beta::Counter.new(count: 4_567_890, limit: 1_000_000_000, round: true))
end

# @label Rounded Large Numbers, Greater Than Custom Limit
def rounding_large_number_greater_than_custom_limit
render(Primer::Beta::Counter.new(count: 4_567_890, limit: 1_000_000, round: true))
end
#
# @!endgroup
end
end
end
Loading