diff options
Diffstat (limited to 'spec/frontend/clusters/agents/components/activity_history_item_spec.js')
-rw-r--r-- | spec/frontend/clusters/agents/components/activity_history_item_spec.js | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/spec/frontend/clusters/agents/components/activity_history_item_spec.js b/spec/frontend/clusters/agents/components/activity_history_item_spec.js new file mode 100644 index 00000000000..100a280d0cc --- /dev/null +++ b/spec/frontend/clusters/agents/components/activity_history_item_spec.js @@ -0,0 +1,56 @@ +import { GlSprintf } from '@gitlab/ui'; +import { shallowMount } from '@vue/test-utils'; +import { sprintf } from '~/locale'; +import HistoryItem from '~/vue_shared/components/registry/history_item.vue'; +import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue'; +import ActivityHistoryItem from '~/clusters/agents/components/activity_history_item.vue'; +import { EVENT_DETAILS, DEFAULT_ICON } from '~/clusters/agents/constants'; +import { mockAgentHistoryActivityItems } from '../../mock_data'; + +const agentName = 'cluster-agent'; + +describe('ActivityHistoryItem', () => { + let wrapper; + + const createWrapper = ({ event = {} }) => { + wrapper = shallowMount(ActivityHistoryItem, { + propsData: { event }, + stubs: { + HistoryItem, + GlSprintf, + }, + }); + }; + + const findHistoryItem = () => wrapper.findComponent(HistoryItem); + const findTimeAgo = () => wrapper.find(TimeAgoTooltip); + + afterEach(() => { + wrapper.destroy(); + }); + + describe.each` + kind | icon | title | lineNumber + ${'token_created'} | ${EVENT_DETAILS.token_created.eventTypeIcon} | ${sprintf(EVENT_DETAILS.token_created.title, { tokenName: agentName })} | ${0} + ${'token_revoked'} | ${EVENT_DETAILS.token_revoked.eventTypeIcon} | ${sprintf(EVENT_DETAILS.token_revoked.title, { tokenName: agentName })} | ${1} + ${'agent_connected'} | ${EVENT_DETAILS.agent_connected.eventTypeIcon} | ${sprintf(EVENT_DETAILS.agent_connected.title, { titleIcon: '' })} | ${2} + ${'agent_disconnected'} | ${EVENT_DETAILS.agent_disconnected.eventTypeIcon} | ${sprintf(EVENT_DETAILS.agent_disconnected.title, { titleIcon: '' })} | ${3} + ${'agent_connected'} | ${EVENT_DETAILS.agent_connected.eventTypeIcon} | ${sprintf(EVENT_DETAILS.agent_connected.title, { titleIcon: '' })} | ${4} + ${'unknown_agent'} | ${DEFAULT_ICON} | ${'unknown_agent Event occurred'} | ${5} + `('when the event type is $kind event', ({ icon, title, lineNumber }) => { + beforeEach(() => { + const event = mockAgentHistoryActivityItems[lineNumber]; + createWrapper({ event }); + }); + it('renders the correct icon', () => { + expect(findHistoryItem().props('icon')).toBe(icon); + }); + it('renders the correct title', () => { + expect(findHistoryItem().text()).toContain(title); + }); + it('renders the correct time-ago tooltip', () => { + const activityEvents = mockAgentHistoryActivityItems; + expect(findTimeAgo().props('time')).toBe(activityEvents[lineNumber].recordedAt); + }); + }); +}); |