Skip to content

Commit

Permalink
Merge pull request #529 from DnD-Montreal/439-cypress-league-admin-event
Browse files Browse the repository at this point in the history
Create Cypress Tests for League Admin Event Crud
  • Loading branch information
IanjhPhillips authored Mar 27, 2022
2 parents 97ba266 + 9e845db commit 3116330
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 2 deletions.
56 changes: 56 additions & 0 deletions cypress/integration/Event Management/league_admin_event_crud.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
describe('League Admin Event CRUD Test Suite', () => {
const event_title = 'Test Event'
const event_edited_title = 'Test Edited Event'
const event_location = 'Cypress Town'
const event_edited_location = 'Cypress Town Edited'
let last_url = ''

before(() => {
cy.refreshDatabase()
cy.seed('FastSeeder')
last_url = `${Cypress.config('baseUrl')}/admin/dashboard/`
})

beforeEach(() => {
cy.seederLoginLeagueAdmin()
cy.intercept('GET', last_url).as('last_url')
cy.visit(last_url)
cy.wait('@last_url')
})

it('Event Index', () => {
cy.contains('Events').click()
cy.get('table[id="crudTable"]')
last_url = `${Cypress.config('baseUrl')}/admin/event/`
})

it('Event Creation', () => {
cy.get(`a[href="${Cypress.config('baseUrl')}/admin/event/create"]`).click()
cy.get('input[name="title"]').type(event_title)
cy.get('textarea[name="description"]').type(event_title)
cy.get('input[name="location"]').type(event_location)
cy.get('button[type="submit"]').click()
cy.contains(event_title)
})

it('Event Delete', () => {
cy.get('a[data-button-type="delete"]').eq(0).click()
cy.contains('Item Deleted')
})

it('Event Edit', () => {
cy.get('i[class="la la-edit"]').eq(0).parent().click()
cy.get('input[name="title"]').clear().type(event_edited_title)
cy.get('textarea[name="description"]').clear().type(event_edited_title)
cy.get('input[name="location"]').clear().type(event_edited_location)
cy.get('button[type="submit"]').click()
cy.contains(event_edited_title)
})

it('Event Detail', () => {
cy.get('i[class="la la-eye"]').eq(0).parent().click()
cy.contains('Description:')
cy.contains('Location:')
cy.contains('Title:')
})
})
17 changes: 17 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,20 @@ Cypress.Commands.add('seederLogin', () => {
cy.wait('@login')
cy.get('[data-cy="user"]').should('contain', testusername)
})

Cypress.Commands.add('seederLoginLeagueAdmin', () => {
const testuser_email = '[email protected]'
const testuser_password = 'password'
const testusername = 'Test account'
cy.intercept('GET', '/').as('landingpage')
cy.intercept('POST', '/login').as('login')
cy.visit('/')
cy.wait('@landingpage')
cy.get('[data-testid="PersonIcon"]').click()
cy.contains('button', 'LOGIN').click()
cy.get('#email').type(testuser_email)
cy.get('#password').clear().type(testuser_password)
cy.get('button[type="submit"]').click()
cy.wait('@login')
cy.get('[data-cy="user"]').should('contain', testusername)
})
10 changes: 9 additions & 1 deletion database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@ public function run()
$dndmtl = League::factory()->create([
'name' => "DnD MTL"
]);
$users = User::factory(10)->create()->prepend($defaultUser);

$leagueAdminUser = User::factory()
->hasAttached(Role::where('name', Role::LEAGUE_ADMIN)->first(), ['league_id' => $dndmtl->id])
->create([
'email' => '[email protected]',
'name' => "League Admin Test account"
]);

$users = User::factory(10)->create()->prepend($defaultUser)->prepend($leagueAdminUser);
$dm = User::factory(5)->create();
$events = Event::factory(5)->create([
'league_id' => $dndmtl->id
Expand Down
10 changes: 9 additions & 1 deletion database/seeders/FastSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,15 @@ public function run()
$dndmtl = League::factory()->create([
'name' => "DnD MTL"
]);
$users = User::factory(3)->create()->prepend($defaultUser);

$leagueAdminUser = User::factory()
->hasAttached(Role::where('name', Role::LEAGUE_ADMIN)->first(), ['league_id' => $dndmtl->id])
->create([
'email' => '[email protected]',
'name' => "League Admin Test account"
]);

$users = User::factory(3)->create()->prepend($defaultUser)->prepend($leagueAdminUser);
$dm = User::factory(2)->create();
$events = Event::factory(2)->create([
'league_id' => $dndmtl->id
Expand Down

0 comments on commit 3116330

Please sign in to comment.