Skip to content
Open
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
4 changes: 3 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ root = true

[*]
indent_style = space
indent_size = 2
indent_size = 2
end_of_line = lf
insert_final_newline = true
44 changes: 44 additions & 0 deletions cypress/integration/initiative.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,48 @@ describe('RPG Turns', () => {
cy.contains('add').click();
cy.get('table').should('have.length', 0);
});

it('should add multiples characters when how many field is filled', () => {
const numberOfCharacters = 10;

cy.visit('/');

cy.get('input[name="howMany"]').type(numberOfCharacters);
cy.get('input[name="name"]').type('Goblin');
cy.get('input[name="initiative"]').type(8);
cy.contains('add').click();

cy.get('table').find('tr').should('have.length', numberOfCharacters + 1);
});

it('should remove an entry when click on remove button', () => {
cy.visit('/');

cy.get('input[name="name"]').type('Black Dragon');
cy.get('input[name="initiative"]').type(10);
cy.contains('add').click();

cy.get('table').find('tr').should('have.length', 2);

cy.get('[data-test-id="delete-button"]').click();
cy.get('table').should('have.length', 0);
});

it('should move to the next character on-turn class when click in next', () => {
const numberOfCharacters = 5;
cy.visit('/');

cy.get('input[name="howMany"]').type(numberOfCharacters);
cy.get('input[name="name"]').type('Goblin');
cy.get('input[name="initiative"]').type(2);
cy.contains('add').click();

cy.get('tbody tr:nth-child(1) td:nth-child(1) img')
.should('has.attr', 'data-test-id', 'turn-icon');

cy.get('[data-test-id="next-button"]').click();

cy.get('tbody tr:nth-child(2) td:nth-child(1) img')
.should('has.attr', 'data-test-id', 'turn-icon');
});
});
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,14 @@ class App extends Component {
<strong>2 - </strong>
<span>Prepare for battle!</span>
</p>
<Button uppercase type="button" onClick={this.handleNextTurn}>Next turn</Button>
<Button
uppercase
type="button"
data-test-id="next-button"
onClick={this.handleNextTurn}
>
Next turn
</Button>
</AppCardHeader>
<AppCardBody>
<InitiativeList
Expand Down
11 changes: 9 additions & 2 deletions src/components/InitiativeList.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,20 @@ export default function InitiativeList({ characters, turn, removeCharacter }) {
<TableRow key={character.id}>
<TableCell isActive={turn === index}>
{turn === index && (
<TurnIcon src={icon} />
<TurnIcon src={icon} data-test-id="turn-icon" />
)}
<span>{character.name}</span>
</TableCell>
<TableCell>{character.initiative}</TableCell>
<TableCell align="right">
<Button type="button" onClick={() => removeCharacter(character.id)} uppercase>Remove</Button>
<Button
type="button"
data-test-id="delete-button"
onClick={() => removeCharacter(character.id)}
uppercase
>
Remove
</Button>
</TableCell>
</TableRow>
))}
Expand Down