forked from allegro/hermes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unit testing groups listing (allegro#1657)
- Loading branch information
Showing
9 changed files
with
256 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...onsole-vue/src/views/group-topics/group-topics-breadcrumbs/GroupTopicsBreadcrumbs.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { render } from '@/utils/test-utils'; | ||
import GroupTopicsBreadcrumbs from '@/views/group-topics/group-topics-breadcrumbs/GroupTopicsBreadcrumbs.vue'; | ||
|
||
describe('GroupTopicsBreadcrumbs', () => { | ||
it('should render `home` breadcrumb with an anchor to a home page', () => { | ||
// given | ||
const { getByText } = render(GroupTopicsBreadcrumbs); | ||
|
||
// when | ||
const element = getByText( | ||
'groupTopics.groupTopicsBreadcrumbs.home', | ||
) as HTMLAnchorElement; | ||
|
||
// then | ||
expect(element).toHaveAttribute('href', '/'); | ||
}); | ||
|
||
it('should render `group` breadcrumb with anchor to groups listing', () => { | ||
// given | ||
const { getByText } = render(GroupTopicsBreadcrumbs); | ||
|
||
// when | ||
const element = getByText( | ||
'groupTopics.groupTopicsBreadcrumbs.groups', | ||
) as HTMLAnchorElement; | ||
|
||
// then | ||
expect(element).toHaveAttribute('href', '/groups/'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { fireEvent, waitFor } from '@testing-library/vue'; | ||
import { render } from '@/utils/test-utils'; | ||
import GroupsView from '@/views/groups/GroupsView.vue'; | ||
|
||
describe('GroupsView', () => { | ||
it('should render', () => { | ||
// when | ||
const { queryByText } = render(GroupsView); | ||
|
||
// then | ||
expect(queryByText('groups.heading')).toBeInTheDocument(); | ||
expect(queryByText('groups.groupForm.createTitle')).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('should open modal on `new group` button click', async () => { | ||
// given | ||
const { queryByText } = render(GroupsView); | ||
|
||
// when | ||
await fireEvent.click(queryByText('groups.actions.create')!); | ||
|
||
// then | ||
await waitFor(() => { | ||
expect(queryByText('groups.groupForm.createTitle')).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
92 changes: 92 additions & 0 deletions
92
hermes-console-vue/src/views/groups/group-form/GroupForm.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { fireEvent, waitFor } from '@testing-library/vue'; | ||
import { render } from '@/utils/test-utils'; | ||
import GroupForm from '@/views/groups/group-form/GroupForm.vue'; | ||
|
||
describe('GroupForm', () => { | ||
it('should render form (create variant)', () => { | ||
// given | ||
const props = { | ||
dialogOpen: true, | ||
operation: 'create', | ||
}; | ||
|
||
// when | ||
const { queryByText } = render(GroupForm, { props }); | ||
|
||
// then | ||
expect(queryByText('groups.groupForm.createTitle')).toBeInTheDocument(); | ||
expect(queryByText('groups.groupForm.edu')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render form (edit variant)', () => { | ||
// given | ||
const props = { | ||
dialogOpen: true, | ||
operation: 'edit', | ||
}; | ||
|
||
// when | ||
const { queryByText } = render(GroupForm, { props }); | ||
|
||
// then | ||
expect(queryByText('groups.groupForm.editTitle')).toBeInTheDocument(); | ||
expect(queryByText('groups.groupForm.edu')).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('should not show name validation error for untouched form', () => { | ||
// given | ||
const props = { | ||
dialogOpen: true, | ||
operation: 'create', | ||
}; | ||
|
||
// when | ||
const { queryByText } = render(GroupForm, { props }); | ||
|
||
// then | ||
expect( | ||
queryByText('groups.groupForm.validation.groupName'), | ||
).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('should show name validation error after invalid form submit', async () => { | ||
// given | ||
const props = { | ||
dialogOpen: true, | ||
operation: 'create', | ||
}; | ||
|
||
// when | ||
const { getByText } = render(GroupForm, { props }); | ||
await fireEvent.click(getByText('groups.groupForm.save')); | ||
|
||
// then | ||
await waitFor(() => { | ||
expect( | ||
getByText('groups.groupForm.validation.groupName'), | ||
).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('should not show name validation error for valid group name', async () => { | ||
// given | ||
const props = { | ||
dialogOpen: true, | ||
operation: 'create', | ||
}; | ||
|
||
// when | ||
const { getByLabelText, queryByText } = render(GroupForm, { props }); | ||
|
||
await fireEvent.update( | ||
getByLabelText('groups.groupForm.groupName'), | ||
'pl.allegro.sample', | ||
); | ||
await fireEvent.click(queryByText('groups.groupForm.save')!); | ||
|
||
// then | ||
expect( | ||
queryByText('groups.groupForm.validation.groupName'), | ||
).not.toBeInTheDocument(); | ||
}); | ||
}); |
81 changes: 81 additions & 0 deletions
81
hermes-console-vue/src/views/groups/group-listing/GroupListing.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { dummyGroups } from '@/dummy/groups'; | ||
import { render } from '@/utils/test-utils'; | ||
import { within } from '@testing-library/vue'; | ||
import GroupListing from '@/views/groups/group-listing/GroupListing.vue'; | ||
|
||
describe('GroupListing', () => { | ||
it('should render group listing with no filter applied', () => { | ||
// given | ||
const props = { | ||
groups: dummyGroups, | ||
}; | ||
|
||
// when | ||
const { getByText } = render(GroupListing, { props }); | ||
|
||
// then | ||
dummyGroups.forEach(({ name, topics }, index) => { | ||
const groupRow = getByText(name).closest('tr')!; | ||
expect(within(groupRow).getByText(`${index + 1}`)).toBeInTheDocument(); | ||
expect(within(groupRow).getByText(name)).toBeInTheDocument(); | ||
expect( | ||
within(groupRow).getByText( | ||
`groups.groupListing.topicsChip ${topics.length}`, | ||
), | ||
).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('should render group listing with a filter applied', () => { | ||
// given | ||
const props = { | ||
groups: dummyGroups, | ||
filter: 'pl.allegro.offer', | ||
}; | ||
|
||
// when | ||
const groups = render(GroupListing, { props }) | ||
.getAllByText(/pl\.allegro\.offer/) | ||
.map((group) => group.closest('tr')); | ||
|
||
// then | ||
expect(groups).toHaveLength(2); | ||
expect(within(groups[0]!).getByText(/topicsChip 1/)).toBeInTheDocument(); | ||
expect(within(groups[1]!).getByText(/topicsChip 2/)).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render group listing with a filter applied (no results)', () => { | ||
// given | ||
const props = { | ||
groups: dummyGroups, | ||
filter: 'pl.allegro.i18n.DummyEventV1', | ||
}; | ||
|
||
// when | ||
const rows = render(GroupListing, { props }).getAllByRole('row'); | ||
|
||
// then | ||
expect(rows).toHaveLength(2); | ||
expect(within(rows[0]!).getByText(/index/)).toBeInTheDocument(); | ||
expect(within(rows[0]!).getByText(/name/)).toBeInTheDocument(); | ||
expect(within(rows[1]!).getByText(/noGroups/)).toBeInTheDocument(); | ||
expect(within(rows[1]!).getByText(/appliedFilter/)).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render an empty group listing without filter applied', () => { | ||
// given | ||
const props = { | ||
groups: [], | ||
}; | ||
|
||
// when | ||
const rows = render(GroupListing, { props }).getAllByRole('row'); | ||
|
||
// then | ||
expect(rows).toHaveLength(2); | ||
expect(within(rows[1]!).getByText(/noGroups/)).toBeInTheDocument(); | ||
expect( | ||
within(rows[1]!).queryByText(/appliedFilter/), | ||
).not.toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters