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

chore: update commit #95

Merged
merged 1 commit into from
Sep 24, 2023
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
37 changes: 29 additions & 8 deletions src/views/commits/CommitContent.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
<template>
<div class="commit-box" @click="openCommit()">
<div v-if="commit.pushedDate" class="commit-information">
<span class="tooltip" :data-tooltip="commit.getPushedLocalDate()">
<i class="fas fa-clock"></i>{{ commit.getPushedRelativeDate() }}
<div class="commit-information">
<span class="tooltip" :data-tooltip="commit.committedDate">
<i class="fas fa-clock"></i>{{ commit.getCommittedRelativeDate() }}
</span>
<span class="tooltip" :data-tooltip="commitHash">
<span>{{ commitHash?.slice(0, 8) }}</span>
</span>
</div>
<div>
<p class="commit-message_headline">{{ commitMessage.firstLine }}</p>
<p class="commit-message">{{ commitMessage.other }}</p>
</div>
<div class="commit-message">{{ commit.message }}</div>
<span class="commit-description">
<span class="tooltip" :data-tooltip="commit.getAuthoredLocalDate()">
{{ commit.getAuthorInformation() }},
Expand All @@ -18,10 +24,10 @@
</template>

<script lang="ts">
import { defineComponent } from 'vue'
import { Commit } from '@/application/domain/model/github'
import { inject } from '@/plugins/di/injector'
import { WebBrowserUserCaseKey } from '@/plugins/di/types'
import { computed, defineComponent } from 'vue'

type PropsType = {
commit: Commit
Expand All @@ -39,8 +45,21 @@ export default defineComponent({
const webBrowserUserCase = inject(WebBrowserUserCaseKey)
const openCommit = () => webBrowserUserCase.openUrl(props.commit.commitUrl)

const commitMessage = computed(() => {
const message = props.commit.message
const firstLine = message.split('\n', 1)[0]
const other = message.replace(firstLine, '')
return {
firstLine,
other: other.startsWith('\n') ? other.replace('\n', '') : other,
}
})
const commitHash = computed(() => props.commit.commitUrl.split('/').pop())

return {
openCommit,
commitMessage,
commitHash,
}
},
})
Expand All @@ -58,9 +77,11 @@ export default defineComponent({
white-space: pre-wrap;
text-align: left;
padding-left: 20px;
font-weight: bold;
font-size: 95%;
margin: 15px 0;
font-size: 90%;
&_headline {
text-align: center;
font-weight: bold;
}
}

.commit-information {
Expand Down
20 changes: 13 additions & 7 deletions tests/unit/views/commits/CommitContent.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { mount } from '@vue/test-utils'
import { vi } from 'vitest'
import { Commit } from '@/application/domain/model/github'
import { WebBrowserUserCase } from '@/application/usecase/webBrowser'
import { WebBrowserUserCaseKey } from '@/plugins/di/types'
import CommitContent from '@/views/commits/CommitContent.vue'
import { mount } from '@vue/test-utils'
import { vi } from 'vitest'

const MockedWebBrowserUserCase = vi.fn()
const openUrlMock = vi.fn()
Expand All @@ -20,7 +20,7 @@ describe('CommitContent.vue', () => {
})

const commitMessage = 'commit message'
const commitUrl = 'https://github.com/ytakahashi/miru/commits/1234'
const commitUrl = 'https://github.com/ytakahashi/miru/commits/1234567898765432'
const commit = new Commit(
commitMessage,
commitUrl,
Expand All @@ -34,7 +34,7 @@ describe('CommitContent.vue', () => {
'2021-03-13T00:00:02Z'
)

it('renders issue (opened)', async () => {
it('renders commit', async () => {
const wrapper = mount(CommitContent, {
global: {
provide: {
Expand All @@ -46,9 +46,15 @@ describe('CommitContent.vue', () => {
},
})

expect(wrapper.text()).toMatch(/ytakahashi authored .+ .+ ago/)
expect(wrapper.text()).toMatch(/ytakahashi committed .+ .+ ago/)
expect(wrapper.text()).toContain(commitMessage)
const spans = wrapper.findAll('span.tooltip')
expect(spans).toHaveLength(4)
expect(spans[0].text()).toMatch(/.+ ago/)
expect(spans[1].text()).toBe('12345678')
expect(spans[2].text()).toMatch(/ytakahashi authored .+ .+ ago/)
expect(spans[3].text()).toMatch(/ytakahashi committed .+ .+ ago/)

expect(wrapper.find('p.commit-message_headline').text()).toBe('commit message')
expect(wrapper.find('p.commit-message').text()).toBe('')
})

it('can open url', async () => {
Expand Down