1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
| describe('blog app',function () {
beforeEach(function () { cy.request('POST','http://localhost:3003/api/testing/reset') const user = { name: 'DASB', username: 'sb', password: '123456' } cy.request('POST','http://localhost:3003/api/users', user) cy.visit('http://localhost:3000') })
it('can open site ๅฏไปฅๆๅผ็ฝ้กต',function () { cy.visit('http://localhost:3000') cy.contains('blogs') })
it('and its have login form ๆพ็คบ็ปๅฝ่กจๅ',function () { cy.contains('username') cy.contains('password') })
describe('login ็ปๅฝๆต่ฏ',function () {
it('can not log in with incorrect credentials ้่ฏฏไฟกๆฏไธๅฏไปฅ็ปๅฝ',function () { cy.get('#username-login').type('dasb') cy.get('#password-login').type('dasb') cy.get('#login-button').click()
cy.contains('error') })
it('can log in with correct info ๆญฃ็กฎไฟกๆฏๅฏไปฅ็ปๅฝ',function () { cy.get('#username-login').type('sb') cy.get('#password-login').type('123456') cy.get('#login-button').click()
cy.contains('success') })
})
describe('When logged in', function() { beforeEach(function () { cy.login({ username: 'sb', password: '123456' }) })
it('A blog can be created', function() { cy.contains('create a new blog').click() cy.get('#title').type('ๆ ้ข') cy.get('#author').type('ไฝ่
') cy.get('#url').type('้พๆฅ') cy.get('#likes').type('666') cy.contains('submit').click() cy.contains('ๆ ้ข ไฝ่
') })
it('open show details and click like!', function () {
cy.createBlog({ title:'Test', author:'T est',url:'hppp:%%test@tset.com',likes:999 })
cy.contains('Test').find('button:first').as('theShowDetailButton') cy.get('@theShowDetailButton').click() cy.get('@theShowDetailButton').should('contain', 'hide detail')
cy.get('#add-likes-button').as('theLikeButton') cy.contains(999) cy.get('@theLikeButton').click() cy.contains(1000)
})
it('blog can be deleted',function () {
cy.createBlog({ title:'this', author:'will',url:'remove',likes:0 })
cy.get('#show-detail-button').as('theShowDetailButton') cy.get('@theShowDetailButton').click() cy.contains('this') cy.contains('will') cy.contains('remove')
cy.get('#delete-button').click() cy.contains('delete blog') cy.should('not.contain','this') cy.should('not.contain','will') cy.should('not.contain','remove')
})
describe('the order is correct order by likes',function () {
beforeEach(function () {
cy.createBlog({ title:'first', author:'hehe',url:'haha',likes:0 }) cy.createBlog({ title:'second', author:'hehe',url:'xxxx',likes:666 }) cy.createBlog({ title:'third', author:'hehe',url:'xxxx',likes:888 }) cy.createBlog({ title:'fourth', author:'hehe',url:'xxxx',likes:888 }) cy.createBlog({ title:'fifth', author:'hehe',url:'xxxx',likes:111 }) cy.createBlog({ title:'sixth', author:'will',url:'remove',likes:1001 }) })
it('have six blogs in correct order',function () {
cy.get('#blog-list div').find('button:first').click({ multiple: true })
cy.get('#blog-list div') .first().should('contain','sixth').should('contain',1001) .next().should('contain','third').should('contain',888) .next().should('contain','fourth').should('contain',888) .next().should('contain','second').should('contain',666) .next().should('contain','fifth').should('contain',111) .next().should('contain','first').should('contain',0)
})
it('click fourth blog like! button, then the order change',function () { cy.get('#blog-list div').find('button:first').click({ multiple: true })
cy.get('#blog-list div') .first() .next() .next().should('contain','fourth').should('contain',888).find('#add-likes-button').click()
cy.get('#blog-list div') .first() .next() .next().should('contain','fourth').should('contain',889) })
}) }) })
|