Skip to content

Commit

Permalink
Auto calc img size and center
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
  • Loading branch information
skjnldsv committed Jul 20, 2020
1 parent 7b47f2f commit 4b32185
Show file tree
Hide file tree
Showing 8 changed files with 3 additions and 159 deletions.
8 changes: 0 additions & 8 deletions cypress/integration/image-small.png.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,6 @@ describe('Open image-small.png in viewer', function() {
cy.get('#viewer-content a.next').should('not.be.visible')
})

it('Have the proper height and width values', function() {
// not using should('have.css'), we want the inline styling
cy.get('#viewer-content .modal-container img.active')
.should('have.attr', 'style')
.should('match', /width: 252px/i)
.should('match', /height: 120px/i)
})

it('Does not have any visual regression', function() {
cy.matchImageSnapshot()
})
Expand Down
8 changes: 0 additions & 8 deletions cypress/integration/image.gif.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,6 @@ describe('Open image.gif in viewer', function() {
cy.get('#viewer-content a.next').should('not.be.visible')
})

it('Have the proper height and width values', function() {
// not using should('have.css'), we want the inline styling
cy.get('#viewer-content .modal-container img.active')
.should('have.attr', 'style')
.should('match', /width: 273px/i)
.should('match', /height: 273px/i)
})

it('Take screenshot', function() {
// gif is impossible to match with existing screenshot
// just taking a screenshot to manually compare if needed
Expand Down
10 changes: 0 additions & 10 deletions cypress/integration/image.png.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,6 @@ describe('Open image.png in viewer', function() {
cy.get('#viewer-content a.next').should('not.be.visible')
})

it('Have the proper height and width values', function() {
// not using should('have.css'), we want the inline styling
cy.get('#viewer-content .modal-container img.active')
.should('have.attr', 'style')
// 70% max width (see cypress config)
.should('match', new RegExp(`width: ${Math.round(Cypress.config('viewportWidth') * 0.7)}px`, 'i'))
// capped by the width, keeping ratio
.should('match', new RegExp(`height: ${Math.round(Cypress.config('viewportWidth') * 0.7 / 3000 * 2000)}px`, 'i'))
})

it('Does not have any visual regression', function() {
cy.matchImageSnapshot()
})
Expand Down
50 changes: 0 additions & 50 deletions cypress/integration/images-custom-list-loadmore.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,6 @@ describe('Open custom list of images in viewer with pagination', function() {
cy.get('#viewer-content a.next').should('be.visible')
})

it('Have the proper height and width values', function() {
// not using should('have.css'), we want the inline styling
cy.get('#viewer-content .modal-container img.active')
.should('have.attr', 'style')
// 70% max width (see cypress config)
.should('match', new RegExp(`width: ${Math.round(Cypress.config('viewportWidth') * 0.7)}px`, 'i'))
// capped by the width, keeping ratio
.should('match', new RegExp(`height: ${Math.round(Cypress.config('viewportWidth') * 0.7 / 3000 * 2000)}px`, 'i'))
})

it('Does not have any visual regression 1', function() {
cy.matchImageSnapshot()
})
Expand All @@ -170,16 +160,6 @@ describe('Open custom list of images in viewer with pagination', function() {
.and('not.have.class', 'icon-loading')
})

it('Have the proper height and width values', function() {
// not using should('have.css'), we want the inline styling
cy.get('#viewer-content .modal-container img.active')
.should('have.attr', 'style')
// 70% max width (see cypress config)
.should('match', new RegExp(`width: ${Math.round(Cypress.config('viewportWidth') * 0.7)}px`, 'i'))
// capped by the width, keeping ratio
.should('match', new RegExp(`height: ${Math.round(Cypress.config('viewportWidth') * 0.7 / 3000 * 1688)}px`, 'i'))
})

it('Does not have any visual regression 2', function() {
cy.matchImageSnapshot()
})
Expand All @@ -198,16 +178,6 @@ describe('Open custom list of images in viewer with pagination', function() {
.and('not.have.class', 'icon-loading')
})

it('Have the proper height and width values', function() {
// not using should('have.css'), we want the inline styling
cy.get('#viewer-content .modal-container img.active')
.should('have.attr', 'style')
// 70% max width (see cypress config)
.should('match', new RegExp(`width: ${Math.round(Cypress.config('viewportWidth') * 0.7)}px`, 'i'))
// capped by the width, keeping ratio
.should('match', new RegExp(`height: ${Math.round(Cypress.config('viewportWidth') * 0.7 / 3000 * 2002)}px`, 'i'))
})

it('Does not have any visual regression 3', function() {
cy.matchImageSnapshot()
})
Expand All @@ -226,16 +196,6 @@ describe('Open custom list of images in viewer with pagination', function() {
.and('not.have.class', 'icon-loading')
})

it('Have the proper height and width values', function() {
// not using should('have.css'), we want the inline styling
cy.get('#viewer-content .modal-container img.active')
.should('have.attr', 'style')
// 70% max width (see cypress config)
.should('match', new RegExp(`width: ${Math.round(Cypress.config('viewportWidth') * 0.7)}px`, 'i'))
// capped by the width, keeping ratio
.should('match', new RegExp(`height: ${Math.round(Cypress.config('viewportWidth') * 0.7 / 3000 * 2000)}px`, 'i'))
})

it('Does not have any visual regression 4', function() {
cy.matchImageSnapshot()
})
Expand All @@ -254,16 +214,6 @@ describe('Open custom list of images in viewer with pagination', function() {
.and('not.have.class', 'icon-loading')
})

it('Have the proper height and width values', function() {
// not using should('have.css'), we want the inline styling
cy.get('#viewer-content .modal-container img.active')
.should('have.attr', 'style')
// 70% max width (see cypress config)
.should('match', new RegExp(`width: ${Math.round(Cypress.config('viewportWidth') * 0.7)}px`, 'i'))
// capped by the width, keeping ratio
.should('match', new RegExp(`height: ${Math.round(Cypress.config('viewportWidth') * 0.7 / 3000 * 2000)}px`, 'i'))
})

it('Does not have any visual regression 5', function() {
cy.matchImageSnapshot()
})
Expand Down
30 changes: 0 additions & 30 deletions cypress/integration/images-custom-list.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,6 @@ describe('Open custom images list in viewer', function() {
cy.get('#viewer-content a.next').should('be.visible')
})

it('Have the proper height and width values', function() {
// not using should('have.css'), we want the inline styling
cy.get('#viewer-content .modal-container img.active')
.should('have.attr', 'style')
// 70% max width (see cypress config)
.should('match', new RegExp(`width: ${Math.round(Cypress.config('viewportWidth') * 0.7)}px`, 'i'))
// capped by the width, keeping ratio
.should('match', new RegExp(`height: ${Math.round(Cypress.config('viewportWidth') * 0.7 / 3000 * 2000)}px`, 'i'))
})

it('Does not have any visual regression 1', function() {
cy.matchImageSnapshot()
})
Expand All @@ -143,16 +133,6 @@ describe('Open custom images list in viewer', function() {
cy.get('#viewer-content .modal-header button.icon-close').should('be.visible')
})

it('Have the proper height and width values', function() {
// not using should('have.css'), we want the inline styling
cy.get('#viewer-content .modal-container img.active')
.should('have.attr', 'style')
// 70% max width (see cypress config)
.should('match', new RegExp(`width: ${Math.round(Cypress.config('viewportWidth') * 0.7)}px`, 'i'))
// capped by the width, keeping ratio
.should('match', new RegExp(`height: ${Math.round(Cypress.config('viewportWidth') * 0.7 / 3000 * 2002)}px`, 'i'))
})

it('Does not have any visual regression 2', function() {
cy.matchImageSnapshot()
})
Expand All @@ -177,16 +157,6 @@ describe('Open custom images list in viewer', function() {
cy.get('#viewer-content .modal-header button.icon-close').should('be.visible')
})

it('Have the proper height and width values', function() {
// not using should('have.css'), we want the inline styling
cy.get('#viewer-content .modal-container img.active')
.should('have.attr', 'style')
// 70% max width (see cypress config)
.should('match', new RegExp(`width: ${Math.round(Cypress.config('viewportWidth') * 0.7)}px`, 'i'))
// capped by the width, keeping ratio
.should('match', new RegExp(`height: ${Math.round(Cypress.config('viewportWidth') * 0.7 / 3000 * 2000)}px`, 'i'))
})

it('Does not have any visual regression 3', function() {
cy.matchImageSnapshot()
})
Expand Down
50 changes: 0 additions & 50 deletions cypress/integration/images.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,6 @@ describe('Open images in viewer', function() {
cy.get('#viewer-content a.next').should('be.visible')
})

it('Have the proper height and width values', function() {
// not using should('have.css'), we want the inline styling
cy.get('#viewer-content .modal-container img.active')
.should('have.attr', 'style')
// 70% max width (see cypress config)
.should('match', new RegExp(`width: ${Math.round(Cypress.config('viewportWidth') * 0.7)}px`, 'i'))
// capped by the width, keeping ratio
.should('match', new RegExp(`height: ${Math.round(Cypress.config('viewportWidth') * 0.7 / 3000 * 2000)}px`, 'i'))
})

it('Does not have any visual regression 1', function() {
cy.matchImageSnapshot()
})
Expand All @@ -108,16 +98,6 @@ describe('Open images in viewer', function() {
.and('not.have.class', 'icon-loading')
})

it('Have the proper height and width values', function() {
// not using should('have.css'), we want the inline styling
cy.get('#viewer-content .modal-container img.active')
.should('have.attr', 'style')
// 70% max width (see cypress config)
.should('match', new RegExp(`width: ${Math.round(Cypress.config('viewportWidth') * 0.7)}px`, 'i'))
// capped by the width, keeping ratio
.should('match', new RegExp(`height: ${Math.round(Cypress.config('viewportWidth') * 0.7 / 3000 * 1688)}px`, 'i'))
})

it('Does not have any visual regression 2', function() {
cy.matchImageSnapshot()
})
Expand All @@ -136,16 +116,6 @@ describe('Open images in viewer', function() {
.and('not.have.class', 'icon-loading')
})

it('Have the proper height and width values', function() {
// not using should('have.css'), we want the inline styling
cy.get('#viewer-content .modal-container img.active')
.should('have.attr', 'style')
// 70% max width (see cypress config)
.should('match', new RegExp(`width: ${Math.round(Cypress.config('viewportWidth') * 0.7)}px`, 'i'))
// capped by the width, keeping ratio
.should('match', new RegExp(`height: ${Math.round(Cypress.config('viewportWidth') * 0.7 / 3000 * 2002)}px`, 'i'))
})

it('Does not have any visual regression 3', function() {
cy.matchImageSnapshot()
})
Expand All @@ -165,16 +135,6 @@ describe('Open images in viewer', function() {
.and('not.have.class', 'icon-loading')
})

it('Have the proper height and width values', function() {
// not using should('have.css'), we want the inline styling
cy.get('#viewer-content .modal-container img.active')
.should('have.attr', 'style')
// 70% max width (see cypress config)
.should('match', new RegExp(`width: ${Math.round(Cypress.config('viewportWidth') * 0.7)}px`, 'i'))
// capped by the width, keeping ratio
.should('match', new RegExp(`height: ${Math.round(Cypress.config('viewportWidth') * 0.7 / 3000 * 2000)}px`, 'i'))
})

it('Does not have any visual regression 4', function() {
cy.matchImageSnapshot()
})
Expand All @@ -193,16 +153,6 @@ describe('Open images in viewer', function() {
.and('not.have.class', 'icon-loading')
})

it('Have the proper height and width values', function() {
// not using should('have.css'), we want the inline styling
cy.get('#viewer-content .modal-container img.active')
.should('have.attr', 'style')
// 70% max width (see cypress config)
.should('match', new RegExp(`width: ${Math.round(Cypress.config('viewportWidth') * 0.7)}px`, 'i'))
// capped by the width, keeping ratio
.should('match', new RegExp(`height: ${Math.round(Cypress.config('viewportWidth') * 0.7 / 3000 * 2000)}px`, 'i'))
})

it('Does not have any visual regression 5', function() {
cy.matchImageSnapshot()
})
Expand Down
2 changes: 0 additions & 2 deletions src/components/Images.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
}"
:src="data"
:style="{
height: minHeight,
width: minWidth,
marginTop: shiftY + 'px',
marginLeft: shiftX + 'px'
}"
Expand Down
4 changes: 3 additions & 1 deletion src/views/Viewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -683,12 +683,14 @@ export default {
transition: width ease 100ms;
.modal-container {
display: flex !important;
width: auto !important;
border-radius: 0 !important;
// let the mime components manage their own background-color
background-color: transparent;
justify-content: center;
align-items: center;
// Override max-height & max-width
width: 85% !important;
height: 90% !important;
}
}

Expand Down

0 comments on commit 4b32185

Please sign in to comment.