7masters css | consistência visual em projetos web, por rafael rinaldi

52
Visual consistency on web projects @rafaelrinaldi

Upload: imasters

Post on 16-Jul-2015

335 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

Visual consistency on web projects

@rafaelrinaldi

Page 2: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

@rafaelrinaldi

Page 3: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

http://netshoes.com.br

Page 4: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

http://sp.femug.com

Page 5: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

http://zofe.com.br

Page 6: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

We all ❤ CSS (don’t we?)

Page 7: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

It’s really easy to change, but incredibly hard to test

Page 8: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

Different implementations, multiple devices, screen sizes…

Page 9: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

How to achieve consistency and sanity?

Page 10: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

›❯ Syntax check; ›❯ Code styleguide; ›❯ Code architecture; ›❯ Visual regression test.

Page 11: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

Syntax check

Page 12: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

Check for the code syntax in order to find errors

Page 13: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

CSSLint

Page 14: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

.imasters { /* Invalid color value */ color: #red; /* Invalid property and attribute */ lorem: 'ipsum'; }

Page 15: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

λ csslint style.css

csslint: There are 2 problems in style.css.

style.css 1: error at line 3, col 10 Expected a hex color but found '#red' at line 3, col 10. color: #red;

style.css 2: warning at line 6, col 3 Unknown property 'lorem'. lorem: 'ipsum';

Page 16: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

Code styleguide

Page 17: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

Ensure code consistency by following a set

of predefined rules

Page 18: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi
Page 19: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

SCSSLint

Page 20: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

# config.yaml linters: # IDs, classes and placeholders should be all lowercase. CapitalizationInSelector: enabled: true

# Prefer hexadecimal color codes over color keywords. ColorKeyword: enabled: true

# Reports when you define the same property twice. DuplicateProperty: enabled: true

Page 21: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

λ scss-lint -c config.yaml style.css

style.css:1 Selector `iMasters` should be written in lowercase style.css:2 Color literals like `fuchsia` should be variables style.css:2 Color `fuchsia` should be written in hexadecimal form style.css:3 Property `color` already defined on line 2 style.css:3 Color `fuchsia` should be written in hexadecimal form style.css:3 Color literals like `fuchsia` should be variables

Page 22: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

Code architecture

Page 23: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

A well structured code base make things flexible

and easier to change

Page 24: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

BEM, SMACSS, OOCSS, Your Own Cool Technique… (pick your poison)

Page 25: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

. ├── assets │   └── stylesheets │   ├── application.scss │   ├── base │   │   ├── _grid.scss │   │   ├── _typography.scss │   │   └── _variables.scss │   ├── components │   │   ├── _dropdown.scss │   ├── helpers │   │   └── _mixins.scss │   └── layout │   ├── core │   │   ├── _footer.scss │   │   ├── _header.scss │   └── sections │   └── _dashboard.scss ├── bower.json └── vendor ├── assets ├── normalize-css └── susy

Page 26: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

Use your common sense and build your projects

with a solid foundation from the ground up

Page 27: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

Visual regression test

Page 28: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

The classic way of testing UI is achieved by eyeballing

Page 29: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

Style changes can break stuff you don’t even know about

Page 30: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

That’s what’s called a regression (we all have been there)

Page 31: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

If you rely on humans to test stuff you’re screwed

Page 32: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

Image diff

Page 33: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

Uses image analysis and comparison

to make sure things didn’t break

Page 34: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi
Page 35: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

BackstopJS (uses Resemble.js, CasperJS and PhantomJS)

Page 36: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

{ "viewports": [ { "name": "phone", "width": 320, "height": 480 }, { "name": "tablet", "width": 568, "height": 1024 } ] }

Page 37: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

{ "scenarios": [ { "label": "My Website", "url": "../../index.html", "selectors": [ "nav", ".jumbotron", "body .col-md-4:nth-of-type(1)", "body .col-md-4:nth-of-type(2)", "body .col-md-4:nth-of-type(3)", "footer" ] } ] }

Page 38: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi
Page 39: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

If you have a visual styleguide,

image diff regression test can be your best friend

Page 40: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi
Page 41: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

Testing UI is more than just making assertions

against HTML markup

Page 42: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

Computed style

Page 43: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

Consists in testing UI by matching computed style values

Page 44: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

Hardy (uses Selenium)

Page 45: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

Feature: iMasters UI Test As a user I want visual consistency on the http://imasters.com.br

Scenario: Header layout Given I visit 'http://imasters.com.br' Then 'header > logo > a' should have 'color' of 'rgb(255, 165, 0)'

Page 46: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

λ hardy selenium start λ hardy .

Hardy v0.0.11 CSS Utils Steps Loaded CSS Steps Loaded Generic Steps Loaded Loading browser firefox …Shutting down browser

1 scenario (1 passed) 3 steps (3 passed) firefox success

Page 47: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

TL;DR

Page 48: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

Invest in code consistency and modularity

Page 49: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

Automate UI testing

Page 50: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

Integrate everything into your build pipeline

Page 51: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

CSS: Just Try and Do a Good JobChris Coyier

“ ”

Page 52: 7Masters CSS | Consistência visual em projetos web, por Rafael Rinaldi

Thanks

@rafaelrinaldi