Skip to content

Commit

Permalink
Merge pull request #97 from AnnaDodson/develop
Browse files Browse the repository at this point in the history
Admin page for steps totals
  • Loading branch information
AnnaDodson authored Dec 2, 2019
2 parents 96b3f73 + f42248f commit d768634
Show file tree
Hide file tree
Showing 17 changed files with 696 additions and 21 deletions.
19 changes: 19 additions & 0 deletions StepChallenge.Tests/StepsServiceStub.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Threading.Tasks;
using StepChallenge.Services;

namespace StepChallenge.Tests
{
public class StepsServiceStub : StepsService
{
private readonly int _averageTeamSize;
public StepsServiceStub(StepContext stepContext, int averageTeamSize = 3) : base(stepContext)
{
_averageTeamSize = averageTeamSize;
}

public override async Task<int> GetAverageTeamSize()
{
return _averageTeamSize;
}
}
}
116 changes: 116 additions & 0 deletions StepChallenge.Tests/TeamOverviewTests.Data.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Model;
using NUnit.Framework;

namespace StepChallenge.Tests
{
public class TestOverviewData
{
private static DateTime StartDate = new DateTime(2019,09,16, 0,0,0);

[SetUp]
public void Setup()
{
}

public static IQueryable<Team> GetTeams(){
var teams = CreateThreeTeams();
return teams;
}

public static IQueryable<Team> GetTeamWithThreePeople()
{
var teams = CreateTeamWithOneLessPerson();
return teams;
}

private static IQueryable<Team> CreateTeamWithOneLessPerson()
{
return (new List<Team>
{
new Team
{
TeamId = 1,
TeamName = "Team_1",
NumberOfParticipants = 3,
Participants = CreateParticipants(10)
}
}).AsQueryable();
}

private static IQueryable<Team> CreateThreeTeams()
{
return (new List<Team>
{
new Team
{
TeamId = 1,
TeamName = "Team_1",
NumberOfParticipants = 3,
Participants = CreateParticipants(10)
},
new Team
{
TeamId = 2,
TeamName = "Team_2",
NumberOfParticipants = 3,
Participants = CreateParticipants(20)
},
new Team
{
TeamId = 3,
TeamName = "Team_3",
NumberOfParticipants = 3,
Participants = CreateParticipants(30)
}
}).AsQueryable();
}

private static ICollection<Participant> CreateParticipants(int id)
{
var participants = new List<Participant>
{
new Participant
{
ParticipantName = "ParticipantNameOne",
ParticipantId = id + 1,
Steps = CreateSteps(20)
},
new Participant
{
ParticipantName = "ParticipantNameTwo",
ParticipantId = id + 2,
Steps = CreateSteps(20)
},
new Participant
{
ParticipantName = "ParticipantNameThree",
ParticipantId = id + 3,
Steps = CreateSteps(20)
},
};
return participants;
}

private static ICollection<Steps> CreateSteps(int stepCount)
{
var steps = new List<Steps>();

for (int i = 0; i < 3; i++)
{
steps.Add(
new Steps
{
StepCount = stepCount,
DateOfSteps = StartDate.AddDays(i),
}
);
}

return steps;
}
}
}
98 changes: 98 additions & 0 deletions StepChallenge.Tests/TeamOverviewTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Model;
using Moq;
using NUnit.Framework;
using StepChallenge.Services;

namespace StepChallenge.Tests
{
public class TeamOverviewTests : BaseTests
{
/// <summary>
/// Test a teams step total is counted correctly
/// </summary>
[Test]
public async Task Test_TeamOverview_TotalSteps_AreCountedCorrectly()
{
var team = TestOverviewData.GetTeams().ToList();

var stepsService = new StepsServiceStub(GetMockStepContext(team));
var result = await stepsService.GetTeamsOverview();

var resultTotal = result.Teams.ToList().First(r => r.TeamId == 1).TeamTotalSteps;
var expectedTotal = 180;

Assert.IsTrue(resultTotal == expectedTotal, $"Expected total steps to be: {expectedTotal} but got {resultTotal}");
}

/// <summary>
/// Test a teams step total is counted correctly and ignore steps counted outside of the challenge dates
/// </summary>
[Test]
[TestCase("01/01/2012")]
[TestCase("01/01/2020")]
public async Task Test_TeamOverview_TotalSteps_DoNotCountStepsOutsideOfDates(DateTime date)
{
var team = TestOverviewData.GetTeams().ToList();
team.First(r => r.TeamId == 1).Participants.First(p => p.ParticipantId == 11).Steps.Add(new Steps
{
StepCount = 30,
DateOfSteps = date,
});

var stepsService = new StepsServiceStub(GetMockStepContext(team));
var result = await stepsService.GetTeamsOverview();

var resultTotal = result.Teams.ToList().First(r => r.TeamId == 1).TeamTotalSteps;
var expectedTotal = 180;

Assert.IsTrue(resultTotal == expectedTotal, $"Expected total steps to be: {expectedTotal} but got {resultTotal}");
}

/// <summary>
/// Test a teams step total adds an average person correctly for teams with less people
/// </summary>
[Test]
public async Task Test_TeamOverview_TotalSteps_TeamsWithLessPeopleGetAverageSteps()
{
var team = TestOverviewData.GetTeamWithThreePeople().ToList();

var averageTeamSize = 4;
var stepsService = new StepsServiceStub(GetMockStepContext(team), averageTeamSize);
var result = await stepsService.GetTeamsOverview();

var resultTotal = result.Teams.ToList().First(r => r.TeamId == 1).TeamTotalStepsWithAverage;
var expectedTotal = 240;

Assert.IsTrue(resultTotal == expectedTotal, $"Expected total steps to be: {expectedTotal} but got {resultTotal}");
}

private StepContext GetMockStepContext(List<Team> teams)
{
var mockContext = new Mock<StepContext>();

mockContext.Setup(x => x.Team).Returns(GetDbSetTeams(teams).Object);

return mockContext.Object;
}


private Mock<DbSet<Team>> GetDbSetTeams(List<Team> teamList)
{
var teams = teamList.AsQueryable();

var mockParticipantSet = new Mock<DbSet<Team>>();
mockParticipantSet.As<IQueryable<Team>>().Setup(m => m.Expression).Returns(teams.Expression);
mockParticipantSet.As<IQueryable<Team>>().Setup(m => m.Provider).Returns(teams.Provider);
mockParticipantSet.As<IQueryable<Team>>().Setup(m => m.Expression).Returns(teams.Expression);
mockParticipantSet.As<IQueryable<Team>>().Setup(m => m.ElementType).Returns(teams.ElementType);
mockParticipantSet.As<IQueryable<Team>>().Setup(m => m.GetEnumerator()).Returns(teams.GetEnumerator());

return mockParticipantSet;
}
}
}
16 changes: 10 additions & 6 deletions StepChallenge/ClientApp/src/Admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { EditParticipant } from './components/admin/editParticipant';
import { EditTeams } from './components/admin/editTeams';
import { EditChallengeSettings } from './components/admin/editChallengeSettings';
import { AdminScoreBoard } from './components/admin/adminScoreBoard';
import { TotalOverview } from './components/admin/totalOverview';

export class Admin extends Component {
static displayName = Admin.name;
Expand Down Expand Up @@ -41,12 +42,15 @@ export class Admin extends Component {
<p><em>Loading...</em></p>
}
{!this.state.loading &&
<AdminLayout >
<Route path='/admin/participants' component={EditParticipant} />
<Route path='/admin/teams' component={EditTeams} />
<Route path='/admin/settings' component={EditChallengeSettings} />
<Route path='/admin/leaderboard' component={AdminScoreBoard} />
</AdminLayout>
<div>
<AdminLayout >
<Route exact path='/admin/' component={TotalOverview} />
<Route path='/admin/participants' component={EditParticipant} />
<Route path='/admin/teams' component={EditTeams} />
<Route path='/admin/settings' component={EditChallengeSettings} />
<Route path='/admin/leaderboard' component={AdminScoreBoard} />
</AdminLayout>
</div>
}
</div>
);
Expand Down
50 changes: 50 additions & 0 deletions StepChallenge/ClientApp/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,53 @@
border: "1px solid red";
text-decoration: underline;
}

.table-container{
width: 100%;
position: relative;
height: 800px;
overflow: auto;
}

.overview-table{
overflow-x: scroll;
overflow-y: overflow;
margin-left: 24em;
}

.overview-table table {
border-collapse: separate;
border-spacing: 0;
}

.overview-table .headcol {
position: absolute;
width: 12em;
left: 0;
top: auto;
border-top-width: 1px;
/*only relevant for first row*/
margin-top: -1px;
/*compensate for top border*/
}

.overview-table .headcol2 {
margin-left: 12em;
}

.overview-table .headcol:before {
margin-left: 12em;
}

.overview-table .winner {
color: rgb(102, 219, 121) !important;
font-weight: 700;
}

.overview-table .border-right{
border-right: 1px solid black;
}

.overview-table .border-left{
border-left: 1px solid black;
}
15 changes: 10 additions & 5 deletions StepChallenge/ClientApp/src/components/CreateStepTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ import TeamStep from './TeamStep';


function getDaysToDisplay(startDate){
var displayFromNextDay = moment().add(2, 'days');
var diff = displayFromNextDay.diff(startDate, "days");
var roundUpToTheNextWeek = Math.ceil(diff/7)*7
var howManyDaysToShow = moment(startDate).add(roundUpToTheNextWeek, 'days');
return howManyDaysToShow.diff(startDate, 'days');
if(moment().isAfter(moment("2019-12-01T01:00:00+01:00"))){
var endDate = moment("2019-12-07T01:00:00+01:00")
var diff = endDate.diff(startDate, 'days');
return diff
}
var displayFromNextDay = moment().add(2, 'days');
var diff = displayFromNextDay.diff(startDate, "days");
var roundUpToTheNextWeek = Math.ceil(diff/7)*7
var howManyDaysToShow = moment(startDate).add(roundUpToTheNextWeek, 'days');
return howManyDaysToShow.diff(startDate, 'days');
}

function getTable(steps, numberOfParticipants, type){
Expand Down
Loading

0 comments on commit d768634

Please sign in to comment.