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

Create Cypress Tests for League Admin Event Crud #529

Merged
merged 5 commits into from
Mar 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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