Skip to content

Commit

Permalink
Switch out assertions for single screen assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick-Lucas committed Nov 7, 2021
1 parent f84fc9b commit e91916a
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 20 deletions.
39 changes: 37 additions & 2 deletions packages/giterm-e2e/GuiValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const COMMITS_OUTER = '[data-testid="Commits"]'
const COMMIT_ROW = `[data-testid="commit"]`
const COMMIT_ROW_BY_SHA = (sha: string) =>
`[data-testid="commit"][data-sha="${sha}"]`
const COMMIT_REF = (localName: string) => `[data-testid="ref-${localName}"]`
const COMMIT_REF = `[data-testid="ref"]`
const COMMIT_REF_BY_TEXT = (text: string) => `[data-refid="ref-${text}"]`
const LOCAL_BRANCH_ICON = `[data-testid="localBranch"]`
const TRACKED_BRANCH_ICON = `[data-testid="remoteInSync"]`
const REMOTE_BRANCH_ICON = `[data-testid="remoteBranch"]`
Expand Down Expand Up @@ -41,6 +42,20 @@ interface RefRemoteBranch {

type Ref = RefBranch | RefTag | RefRemoteBranch

interface CheckScreen {
status: string
currentBranch: {
name: string
remote?: RemoteBranchInfo
}
commits: number
commitChecks: {
index: number
message: string
refs?: Ref[]
}[]
}

export class GuiValidator {
private wd: SpectronClient

Expand Down Expand Up @@ -84,6 +99,16 @@ export class GuiValidator {
await this.wd.waitUntilTextExists(SHOW_REMOTE_SELECTOR, 'Show Remote')
}

screen = async (expected: CheckScreen) => {
await this.status(expected.status)
await this.currentBranch(expected.currentBranch.name)

await this.commits(expected.commits)
for (const commit of expected.commitChecks) {
await this.commit(commit.index, commit.message, commit.refs)
}
}

status = async (status: string) => {
await this.wd.waitUntilTextExists(REPO_STATUS, status)
}
Expand All @@ -108,9 +133,19 @@ export class GuiValidator {
expect(!!commit).toBe(true)

await this.wd.waitUntilTextExists(commit.selector, commitMessage)

const refElements = await this.wd.$$(COMMIT_REF)

// Check that we have the same number on both sides, we should always validate every ref on a commit
const expectedRefsLength = refs?.length ?? 0
expect(refElements.length).toBe(expectedRefsLength)

if (refs && refs.length > 0) {
for (const ref of refs) {
const refElement = await this.exists(COMMIT_REF(ref.name), commit)
const refElement = await this.exists(
COMMIT_REF_BY_TEXT(ref.name),
commit,
)

if (ref.type === 'branch') {
await this.exists(LOCAL_BRANCH_ICON, refElement)
Expand Down
86 changes: 69 additions & 17 deletions packages/giterm-e2e/giterm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,19 @@ describe('giterm', () => {
const git = new TestGitShim()
await cmd('cd ' + git.dir)

await validate.status('No Repository')
await validate.currentBranch('No Branch')

await validate.commits(0)
await validate.screen({
status: 'No Repository',
currentBranch: {
name: 'No Branch',
remote: {
hasRemote: true,
ahead: 0,
behind: 0,
},
},
commits: 0,
commitChecks: [],
})
})

it('initialises a git directory with no commits', async () => {
Expand All @@ -67,10 +76,19 @@ describe('giterm', () => {
await cmd('git init')
await cmd('git checkout -b dev/main')

await validate.status('OK')
await validate.currentBranch('dev/main')

await validate.commits(0)
await validate.screen({
status: 'OK',
currentBranch: {
name: 'dev/main',
remote: {
hasRemote: true,
ahead: 0,
behind: 0,
},
},
commits: 0,
commitChecks: [],
})
})

it('initialises a git directory and creates one commit', async () => {
Expand All @@ -91,6 +109,26 @@ describe('giterm', () => {
await validate.commit(0, 'Initial Test Commit', [
{ type: 'branch', name: 'dev/main' },
])

await validate.screen({
status: 'OK',
currentBranch: {
name: 'dev/main',
},
commits: 1,
commitChecks: [
{
index: 0,
message: 'Initial Test Commit',
refs: [
{
type: 'branch',
name: 'dev/main',
},
],
},
],
})
})

it('loads a git directory with a remote', async () => {
Expand All @@ -108,16 +146,30 @@ describe('giterm', () => {
await cmd(`git remote add origin "${remoteDir}"`)
await cmd('git push --set-upstream origin dev/main')

await validate.status('OK')
await validate.currentBranch('dev/main')

await validate.commits(1)
await validate.commit(0, 'Initial Test Commit', [
{
type: 'branch',
await validate.screen({
status: 'OK',
currentBranch: {
name: 'dev/main',
remote: { hasRemote: true, ahead: 0, behind: 0 },
remote: {
hasRemote: true,
ahead: 0,
behind: 0,
},
},
])
commits: 1,
commitChecks: [
{
index: 0,
message: 'Initial Test Commit',
refs: [
{
type: 'branch',
name: 'dev/main',
remote: { hasRemote: true, ahead: 0, behind: 0 },
},
],
},
],
})
})
})
2 changes: 1 addition & 1 deletion packages/giterm/app/renderer/components/commits/GitRef.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function GitRef({
}

return (
<Pill.Container data-testid={`ref-${label}`}>
<Pill.Container data-testid={`ref`} data-refid={`ref-${label}`}>
<Pill.Segment current={current}>{iconFromType(type)}</Pill.Segment>

{type === 'branch' && remoteInSync && (
Expand Down

0 comments on commit e91916a

Please sign in to comment.