Skip to content

Commit

Permalink
feat(testcafe): Create empty album scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
CozyKourai committed Mar 1, 2019
1 parent 39c59f7 commit d5a8dc9
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 11 deletions.
1 change: 1 addition & 0 deletions testcafe/runner-photos.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ async function runRunner() {

'testcafe/tests/photos/photos_crud.js',
'testcafe/tests/photos/create_full_album_scenario.js',
'testcafe/tests/photos/create_empty_album_scenario.js',

//Scenario that just delete photos, so we don't need to do it in every test.
'testcafe/tests/photos/photos_end_delete_all_data.js'
Expand Down
27 changes: 16 additions & 11 deletions testcafe/tests/pages/photos-album-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,16 @@ export default class Page {
//@param {string} when : text for console.log
async getPhotosToAddCount(when) {
await checkAllImagesExists()
await isExistingAndVisibile(this.photoSectionAddToAlbum, 'Photo section')

// await isExistingAndVisibile(this.photoAddToAlbumWrapper, 'Picture wrapper')
await isExistingAndVisibile(
this.photoSectionAddToAlbum,
'Photo section (add to album)'
)
await isExistingAndVisibile(this.allPhotosAddToAlbum, 'Photo item(s)')
const allPhotosCount = await this.allPhotosAddToAlbum.count

console.log(`Number of pictures on page (${when} test): ${allPhotosCount}`)
console.log(
`Number of pictures ready to be added (${when} test): ${allPhotosCount}`
)
return allPhotosCount
}

Expand Down Expand Up @@ -140,8 +143,14 @@ export default class Page {
.expect(this.albumTitle.innerText)
.eql(albumName)

const allPhotosAlbumCount = await photoPage.getPhotosCount('On Album page')
await t.expect(allPhotosAlbumCount).eql(photoNumber) //all expected photos are displayed
if (photoNumber == 0) {
await isExistingAndVisibile(photoPage.folderEmpty, 'Folder Empty')
} else {
const allPhotosAlbumCount = await photoPage.getPhotosCount(
'On Album page'
)
await t.expect(allPhotosAlbumCount).eql(photoNumber) //all expected photos are displayed
}
}

// @param {String} AlbumName : Name of the album
Expand Down Expand Up @@ -213,7 +222,7 @@ export default class Page {
}

async backToAlbumsList() {
await isExistingAndVisibile(this.btnBackToAlbum)
await isExistingAndVisibile(this.btnBackToAlbum, 'Back to albums List btn')
await t.click(this.btnBackToAlbum)
await this.waitForLoading()
}
Expand All @@ -222,10 +231,6 @@ export default class Page {
// @param { number } photoNumber : Number of photos expected in the album (
async isAlbumExistsAndVisible(albumName, photoNumber) {
await isExistingAndVisibile(this.album(albumName), albumName)
// await isExistingAndVisibile(
// this.albumDescription(albumName),
// `${albumName} description (${this.albumDescription(albumName).innerText})`
// )
await t
.expect(this.album(albumName).innerText)
.contains(`${photoNumber} photo`)
Expand Down
71 changes: 71 additions & 0 deletions testcafe/tests/photos/create_empty_album_scenario.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { photosUser } from '../helpers/roles'
import { TESTCAFE_PHOTOS_URL } from '../helpers/utils'
import { ALBUM_DATE_TIME } from '../helpers/data'
import PhotoPage from '../pages/photos-model'
import AlbumPage from '../pages/photos-album-model'

const photoPage = new PhotoPage()
const photoAlbumPage = new AlbumPage()

fixture`Create new empty album and add photos`
.page`${TESTCAFE_PHOTOS_URL}/`.beforeEach(async t => {
await t.useRole(photosUser)
await photoPage.waitForLoading()
await photoPage.initPhotosCount()
})

test('Go into Album view, and check that there is no album', async () => {
await photoPage.goToAlbums()
await photoAlbumPage.checkEmptyAlbum()
})

test('Go into Album view, and create new empty album', async () => {
await photoPage.goToAlbums()
await photoAlbumPage.addNewAlbum(ALBUM_DATE_TIME, 0)
await photoAlbumPage.checkAlbumPage(ALBUM_DATE_TIME, 0)
//we need to check the album page, just after the redirection from album creation, hence this step being in this test
})

test('Go to ALBUM_DATE_TIME, and rename it (exit by pressing "enter")', async () => {
await photoPage.goToAlbums()
await photoAlbumPage.goToAlbum(ALBUM_DATE_TIME)
await photoAlbumPage.checkAlbumPage(ALBUM_DATE_TIME, 0)
await photoAlbumPage.renameAlbum(ALBUM_DATE_TIME, `New_${ALBUM_DATE_TIME}`, {
exitWithEnter: true
})
await photoAlbumPage.checkAlbumPage(`New_${ALBUM_DATE_TIME}`, 0)
})

test('Go to New_ALBUM_DATE_TIME, and rename it (exit by clicking away)', async () => {
await photoPage.goToAlbums()
await photoAlbumPage.goToAlbum(`New_${ALBUM_DATE_TIME}`)
await photoAlbumPage.checkAlbumPage(`New_${ALBUM_DATE_TIME}`, 0)
await photoAlbumPage.renameAlbum(
`New_${ALBUM_DATE_TIME}`,
`New2_${ALBUM_DATE_TIME}`,
{ exitWithEnter: false }
)
await photoAlbumPage.checkAlbumPage(`New2_${ALBUM_DATE_TIME}`, 0)
})

test('Go to New2_ALBUM_DATE_TIME, and add 2 more photos', async () => {
await photoPage.goToAlbums()
await photoAlbumPage.goToAlbum(`New2_${ALBUM_DATE_TIME}`)
await photoAlbumPage.addPhotosToAlbum(`New2_${ALBUM_DATE_TIME}`, 0, 2)
await photoAlbumPage.backToAlbumsList()
await photoAlbumPage.isAlbumExistsAndVisible(`New2_${ALBUM_DATE_TIME}`, 2)
})

test('Go to New2_ALBUM_DATE_TIME, and remove the 1st photos', async () => {
await photoPage.goToAlbums()
await photoAlbumPage.goToAlbum(`New2_${ALBUM_DATE_TIME}`)
await photoAlbumPage.removePhoto(1)
})

test('Go to New2_ALBUM_DATE_TIME, and delete it', async () => {
await photoPage.goToAlbums()
await photoAlbumPage.goToAlbum(`New2_${ALBUM_DATE_TIME}`)
await photoAlbumPage.deleteAlbum()
await photoAlbumPage.waitForLoading()
await photoAlbumPage.checkEmptyAlbum() //There is no more album
})

0 comments on commit d5a8dc9

Please sign in to comment.