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

Testing makeover #99

Merged
merged 53 commits into from
Jul 6, 2020
Merged
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
2b1c8a6
Updated scripts.
May 22, 2020
9896df7
Throwing error objects instead of strings. Helps with the stack trace.
May 23, 2020
7202a46
Progress on single instance properties.
May 24, 2020
7e983ce
Updated scripts.
May 22, 2020
21d2e7e
Throwing error objects instead of strings. Helps with the stack trace.
May 23, 2020
d19932f
Progress on single instance properties.
May 24, 2020
c4ec8a4
Merge branch 'testing-makeover' of https://github.com/qodesmith/datep…
May 24, 2020
651ec12
Adding `inlinePosition` to all pickers with a common `positionedEl`.
May 25, 2020
72d4af4
Tests for picker properties (single & range) complete!
May 25, 2020
42b48aa
expect => assert for better error messages. Handling when a property …
May 25, 2020
6bec683
Beginning to test the html structure.
May 25, 2020
9f88714
Found out how to add custom message to expect.
May 25, 2020
b98b2b7
Continuing on testing different square days.
May 26, 2020
bdba702
Removing unneeded inner span for qs-overlay-month.
May 31, 2020
ec90e67
Single instance DOM structure tests complete.
May 31, 2020
bd232dc
Renamed helper fxn.
May 31, 2020
da8f639
Added test for issue #86.
May 31, 2020
c8eaaee
DOM structure tests complete for single and daterange instances.
Jun 1, 2020
8161219
Moving tests around a bit.
Jun 1, 2020
e690e90
Basic visuals and behavior tests complete.
Jun 7, 2020
71fb0c1
Starting on date selection tests.
Jun 8, 2020
96de3cb
Typo. Someone made a PR for this which I merged already, but I figure…
Jun 8, 2020
0086ebf
Finished date changes for single picker.
Jun 13, 2020
b278b56
Woops.
Jun 14, 2020
f61d266
Updated to cypress 4.8.0
Jun 16, 2020
b6097f8
Fixed bug with conditional. Removed unnecessary argument.
Jun 27, 2020
9dd9ee5
Completed "Date changes" tests for single and range pairs.
Jun 27, 2020
9dc4d7a
Added some instance method tests.
Jun 28, 2020
724db36
Added show method test to single instance tests.
Jun 28, 2020
2f474d0
Added hide method test to single instance tests.
Jun 28, 2020
a042698
Added remove method test to single instance tests.
Jun 28, 2020
701a02d
Updated README.md
Jun 29, 2020
30b8efb
Added setDate and navigate method tests to single instance tests.
Jun 29, 2020
787c73c
Setting up to test instance methods for daterange pairs.
Jun 29, 2020
3389de7
getRange method tests done.
Jun 29, 2020
e804433
Deduping setDate tests. Woops!
Jun 29, 2020
369effc
Added setMin for daterange tests.
Jul 2, 2020
3614fb2
No, NOW setMax tests complete for dateranges.
Jul 2, 2020
11c2582
setMax tests complete for daterange.
Jul 4, 2020
31fb19c
show tests complete for daterange.
Jul 4, 2020
de62670
hide tests complete for daterange.
Jul 4, 2020
093f239
Changed DOM structure and selectors accordingly.
Jul 5, 2020
ccb7745
Added remove tests for daterange.
Jul 5, 2020
77b7803
Fixed `setDate` bug where the active date wouldnt de-select.
Jul 6, 2020
53cce4c
Progress on setDate tests.
Jul 6, 2020
22a5bb4
Finished with setDate tests for daterange.
Jul 6, 2020
430356c
navigate method tests for daterange complete.
Jul 6, 2020
f56cb6c
Added missing `remove` tests for daterange.
Jul 6, 2020
3189371
Ok NOW tests are complete.
Jul 6, 2020
891c2b3
Trying to fix timing issues with cy.clock and cy.tick. Pleez werk...
Jul 6, 2020
e78e95a
Forgot some cy.clocks to use with the cy.tick. What a life.
Jul 6, 2020
b07b0de
Added files for future tests.
Jul 6, 2020
4732d3d
Added one more file for future tests.
Jul 6, 2020
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
Prev Previous commit
Next Next commit
setMax tests complete for daterange.
  • Loading branch information
Aaron Cordova committed Jul 4, 2020
commit 11c25823a2f1122ff6b4fd46fd109f62c6584714
361 changes: 359 additions & 2 deletions cypress/integration/defaultPropertiesAndBehavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ const {
} = selectors
const { singleDatepickerProperties, getDaterangeProperties } = pickerProperties

/*
TODO's:
* Test for setting a datepicker on the same input more than once.
* Test for other error-throwing scenario's
*/


function checkPickerProperties(picker, isDaterange, id) {
return function({ property, defaultValue, domElement, selector, deepEqual, isFunction, notOwnProperty }) {
Expand Down Expand Up @@ -1547,7 +1553,7 @@ describe('Default properties and behavior', function() {
})
})

describe.only('setMin', function() {
describe('setMin', function() {
it('should be a function', function() {
const pickerStart = this.datepicker(daterangeInputStart, { id: 1 })
const pickerEnd = this.datepicker(daterangeInputEnd, { id: 1 })
Expand Down Expand Up @@ -1895,15 +1901,366 @@ describe('Default properties and behavior', function() {
})
})

describe.only('setMax', function() {
describe('setMax', function() {
it('should be a function', function() {
const pickerStart = this.datepicker(daterangeInputStart, { id: 1 })
const pickerEnd = this.datepicker(daterangeInputEnd, { id: 1 })

expect(pickerStart.setMax).to.be.a('function')
expect(pickerEnd.setMax).to.be.a('function')
})

it('(start) should populate `maxDate` on the instance objects', function() {
const pickerStart = this.datepicker(daterangeInputStart, { id: 1 })
this.datepicker(daterangeInputEnd, { id: 1 })
const date = new Date()

expect(pickerStart.maxDate).to.be.undefined
pickerStart.setMax(date)
expect(+pickerStart.maxDate).to.equal(+new Date(date.getFullYear(), date.getMonth(), date.getDate()))
})

it('(end) should populate `maxDate` on the instance objects', function() {
this.datepicker(daterangeInputStart, { id: 1 })
const pickerEnd = this.datepicker(daterangeInputEnd, { id: 1 })
const date = new Date()

expect(pickerEnd.maxDate).to.be.undefined
pickerEnd.setMax(date)
expect(+pickerEnd.maxDate).to.equal(+new Date(date.getFullYear(), date.getMonth(), date.getDate()))
})

it('(start) should disable dates after to the provided value (including later months)', function() {
const pickerStart = this.datepicker(daterangeInputStart, { id: 1 })
this.datepicker(daterangeInputEnd, { id: 1 })
const maxDay = 15
const today = new Date()
const date = new Date(today.getFullYear(), today.getMonth(), maxDay)

cy.get(`${selectors.range.start.squaresContainer} [data-direction="0"]`).then($days => {
Array.from($days).forEach(day => {
const styles = getComputedStyle(day)

expect(styles.opacity).to.equal('1')
expect(day, `(start cal) Days shouldn't have qs-disabled class prior to calling setMax.`).not.to.have.class('qs-disabled')
})
})

cy.get(`${selectors.range.end.squaresContainer} [data-direction="0"]`).then($days => {
Array.from($days).forEach(day => {
const styles = getComputedStyle(day)

expect(styles.opacity).to.equal('1')
expect(day, `(end cal) Days shouldn't have qs-disabled class prior to calling setMax.`).not.to.have.class('qs-disabled')
})

pickerStart.setMax(date)
})

cy.get(`${selectors.range.start.squaresContainer} [data-direction="0"]`).then($days => {
Array.from($days).forEach((day, i) => {
const styles = getComputedStyle(day)

expect(styles.opacity).to.equal(i < maxDay ? '1' : '0.2')

if (i < maxDay) {
expect(day, 'Unaffected days from setMax').not.to.have.class('qs-disabled')
} else {
expect(day, 'Disabled days from setMax').to.have.class('qs-disabled')
}
})
})

cy.get(`${selectors.range.end.squaresContainer} [data-direction="0"]`).then($days => {
Array.from($days).forEach((day, i) => {
const styles = getComputedStyle(day)

expect(styles.opacity).to.equal(i < maxDay ? '1' : '0.2')

if (i < maxDay) {
expect(day, 'Unaffected days from setMax').not.to.have.class('qs-disabled')
} else {
expect(day, 'Disabled days from setMax').to.have.class('qs-disabled')
}
})
})

cy.get(daterangeInputStart).click()
cy.get(`${selectors.range.start.controls} .qs-arrow.qs-right`).click()
cy.get(`${selectors.range.start.squaresContainer} [data-direction="0"]`).then($days => {
Array.from($days).forEach(day => {
const styles = getComputedStyle(day)

expect(styles.opacity).to.equal('0.2')
expect(day).to.have.class('qs-disabled')
})
})

cy.get(`${selectors.range.start.controls} .qs-arrow.qs-left`).click()
cy.get(`${selectors.range.start.controls} .qs-arrow.qs-left`).click()
cy.get(`${selectors.range.start.squaresContainer} [data-direction="0"]`).then($days => {
Array.from($days).forEach(day => {
const styles = getComputedStyle(day)

expect(styles.opacity).to.equal('1')
expect(day).not.to.have.class('qs-disabled')
})
})

cy.get(daterangeInputEnd).click()
cy.get(`${selectors.range.end.controls} .qs-arrow.qs-right`).click()
cy.get(`${selectors.range.end.squaresContainer} [data-direction="0"]`).then($days => {
Array.from($days).forEach(day => {
const styles = getComputedStyle(day)

expect(styles.opacity).to.equal('0.2')
expect(day).to.have.class('qs-disabled')
})
})

cy.get(`${selectors.range.end.controls} .qs-arrow.qs-left`).click()
cy.get(`${selectors.range.end.controls} .qs-arrow.qs-left`).click()
cy.get(`${selectors.range.end.squaresContainer} [data-direction="0"]`).then($days => {
Array.from($days).forEach(day => {
const styles = getComputedStyle(day)

expect(styles.opacity).to.equal('1')
expect(day).not.to.have.class('qs-disabled')
})
})
})

it('(end) should disable dates after to the provided value (including later months)', function() {
this.datepicker(daterangeInputStart, { id: 1 })
const pickerEnd = this.datepicker(daterangeInputEnd, { id: 1 })
const maxDay = 15
const today = new Date()
const date = new Date(today.getFullYear(), today.getMonth(), maxDay)

cy.get(`${selectors.range.start.squaresContainer} [data-direction="0"]`).then($days => {
Array.from($days).forEach(day => {
const styles = getComputedStyle(day)

expect(styles.opacity).to.equal('1')
expect(day, `(start cal) Days shouldn't have qs-disabled class prior to calling setMax.`).not.to.have.class('qs-disabled')
})
})

cy.get(`${selectors.range.end.squaresContainer} [data-direction="0"]`).then($days => {
Array.from($days).forEach(day => {
const styles = getComputedStyle(day)

expect(styles.opacity).to.equal('1')
expect(day, `(end cal) Days shouldn't have qs-disabled class prior to calling setMax.`).not.to.have.class('qs-disabled')
})

pickerEnd.setMax(date)
})

cy.get(`${selectors.range.start.squaresContainer} [data-direction="0"]`).then($days => {
Array.from($days).forEach((day, i) => {
const styles = getComputedStyle(day)

expect(styles.opacity).to.equal(i < maxDay ? '1' : '0.2')

if (i < maxDay) {
expect(day, 'Unaffected days from setMax').not.to.have.class('qs-disabled')
} else {
expect(day, 'Disabled days from setMax').to.have.class('qs-disabled')
}
})
})

cy.get(`${selectors.range.end.squaresContainer} [data-direction="0"]`).then($days => {
Array.from($days).forEach((day, i) => {
const styles = getComputedStyle(day)

expect(styles.opacity).to.equal(i < maxDay ? '1' : '0.2')

if (i < maxDay) {
expect(day, 'Unaffected days from setMax').not.to.have.class('qs-disabled')
} else {
expect(day, 'Disabled days from setMax').to.have.class('qs-disabled')
}
})
})

cy.get(daterangeInputStart).click()
cy.get(`${selectors.range.start.controls} .qs-arrow.qs-right`).click()
cy.get(`${selectors.range.start.squaresContainer} [data-direction="0"]`).then($days => {
Array.from($days).forEach(day => {
const styles = getComputedStyle(day)

expect(styles.opacity).to.equal('0.2')
expect(day).to.have.class('qs-disabled')
})
})

cy.get(`${selectors.range.start.controls} .qs-arrow.qs-left`).click()
cy.get(`${selectors.range.start.controls} .qs-arrow.qs-left`).click()
cy.get(`${selectors.range.start.squaresContainer} [data-direction="0"]`).then($days => {
Array.from($days).forEach(day => {
const styles = getComputedStyle(day)

expect(styles.opacity).to.equal('1')
expect(day).not.to.have.class('qs-disabled')
})
})

cy.get(daterangeInputEnd).click()
cy.get(`${selectors.range.end.controls} .qs-arrow.qs-right`).click()
cy.get(`${selectors.range.end.squaresContainer} [data-direction="0"]`).then($days => {
Array.from($days).forEach(day => {
const styles = getComputedStyle(day)

expect(styles.opacity).to.equal('0.2')
expect(day).to.have.class('qs-disabled')
})
})

cy.get(`${selectors.range.end.controls} .qs-arrow.qs-left`).click()
cy.get(`${selectors.range.end.controls} .qs-arrow.qs-left`).click()
cy.get(`${selectors.range.end.squaresContainer} [data-direction="0"]`).then($days => {
Array.from($days).forEach(day => {
const styles = getComputedStyle(day)

expect(styles.opacity).to.equal('1')
expect(day).not.to.have.class('qs-disabled')
})
})
})

it('(start) should prevent disabled dates from being selected', function() {
const pickerStart = this.datepicker(daterangeInputStart, { id: 1 })
this.datepicker(daterangeInputEnd, { id: 1 })
const maxDay = 15
const today = new Date()
const date = new Date(today.getFullYear(), today.getMonth(), maxDay)
pickerStart.setMax(date)

// Assert a few values prior to clicking.
cy.get(daterangeInputStart).should('have.value', '')
expect(pickerStart.dateSelected).to.be.undefined

// Click a disabled date and assert a few more values.
cy.get(daterangeInputStart).click()
cy.get(`${selectors.range.start.squaresContainer} [data-direction="0"]`).eq(maxDay + 1).click()
cy.wait(1).then(() => {
cy.get(daterangeInputStart).should('have.value', '')
expect(pickerStart.dateSelected).to.be.undefined
})

// Navigate to the next month and assert you can't click dates.
cy.get(`${selectors.range.start.controls} .qs-arrow.qs-right`).click().then(() => {
cy.get(`${selectors.range.start.squaresContainer} [data-direction="0"]`).eq(0).click()
cy.wait(1).then(() => {
cy.get(daterangeInputStart).should('have.value', '')
expect(pickerStart.dateSelected).to.be.undefined
})
})

// For sanity reasons, assert that clicking a non-disabled date works.
cy.get(`${selectors.range.start.controls} .qs-arrow.qs-left`).click()
cy.get(`${selectors.range.start.squaresContainer} [data-direction="0"]`).eq(maxDay - 1).click()
cy.wait(1).then(() => {
cy.get(daterangeInputStart).should('not.have.value', '')
expect(pickerStart.dateSelected).not.to.be.undefined
})
})

it('(end) should prevent disabled dates from being selected', function() {
this.datepicker(daterangeInputStart, { id: 1 })
const pickerEnd = this.datepicker(daterangeInputEnd, { id: 1 })
const maxDay = 15
const today = new Date()
const date = new Date(today.getFullYear(), today.getMonth(), maxDay)
pickerEnd.setMax(date)

// Assert a few values prior to clicking.
cy.get(daterangeInputEnd).should('have.value', '')
expect(pickerEnd.dateSelected).to.be.undefined

// Click a disabled date and assert a few more values.
cy.get(daterangeInputEnd).click()
cy.get(`${selectors.range.end.squaresContainer} [data-direction="0"]`).eq(maxDay + 1).click()
cy.wait(1).then(() => {
cy.get(daterangeInputEnd).should('have.value', '')
expect(pickerEnd.dateSelected).to.be.undefined
})

// Navigate to the next month and assert you can't click dates.
cy.get(`${selectors.range.end.controls} .qs-arrow.qs-right`).click().then(() => {
cy.get(`${selectors.range.end.squaresContainer} [data-direction="0"]`).eq(0).click()
cy.wait(1).then(() => {
cy.get(daterangeInputEnd).should('have.value', '')
expect(pickerEnd.dateSelected).to.be.undefined
})
})

// For sanity reasons, assert that clicking a non-disabled date works.
cy.get(`${selectors.range.end.controls} .qs-arrow.qs-left`).click()
cy.get(`${selectors.range.end.squaresContainer} [data-direction="0"]`).eq(maxDay - 1).click()
cy.wait(1).then(() => {
cy.get(daterangeInputEnd).should('not.have.value', '')
expect(pickerEnd.dateSelected).not.to.be.undefined
})
})

it('(start) should remove the maximum selectable date when called with no argument', function() {
const pickerStart = this.datepicker(daterangeInputStart, { id: 1 })
const pickerEnd = this.datepicker(daterangeInputEnd, { id: 1 })
const maxDay = 15
const today = new Date()
const date = new Date(today.getFullYear(), today.getMonth(), maxDay)
const daysInMonth = new Date(today.getFullYear(), today.getMonth() + 1, 0).getDate()

expect(pickerStart.maxDate).to.be.undefined
expect(pickerEnd.maxDate).to.be.undefined
pickerStart.setMax(date)

cy.get(`${selectors.range.start.squaresContainer} [data-direction="0"].qs-disabled`)
.should('have.length', daysInMonth - maxDay)
.then(() => {
expect(pickerStart.maxDate).not.to.be.undefined
expect(pickerEnd.maxDate).not.to.be.undefined
pickerStart.setMax()
})
cy.get(`${selectors.range.start.squaresContainer} [data-direction="0"].qs-disabled`)
.should('have.length', 0)
.then(() => {
expect(pickerStart.maxDate).to.be.undefined
expect(pickerEnd.maxDate).to.be.undefined
})
})

it('(end) should remove the maximum selectable date when called with no argument', function() {
const pickerStart = this.datepicker(daterangeInputStart, { id: 1 })
const pickerEnd = this.datepicker(daterangeInputEnd, { id: 1 })
const maxDay = 15
const today = new Date()
const date = new Date(today.getFullYear(), today.getMonth(), maxDay)
const daysInMonth = new Date(today.getFullYear(), today.getMonth() + 1, 0).getDate()

expect(pickerStart.maxDate).to.be.undefined
expect(pickerEnd.maxDate).to.be.undefined
pickerEnd.setMax(date)

cy.get(`${selectors.range.end.squaresContainer} [data-direction="0"].qs-disabled`)
.should('have.length', daysInMonth - maxDay)
.then(() => {
expect(pickerStart.maxDate).not.to.be.undefined
expect(pickerEnd.maxDate).not.to.be.undefined
pickerEnd.setMax()
})
cy.get(`${selectors.range.end.squaresContainer} [data-direction="0"].qs-disabled`)
.should('have.length', 0)
.then(() => {
expect(pickerStart.maxDate).to.be.undefined
expect(pickerEnd.maxDate).to.be.undefined
})
})
})

describe('show', function() {})
describe('hide', function() {})
describe('remove', function() {})
Expand Down