Skip to content

Commit

Permalink
Update tests to use it.each, thus testing multiple cards, not just if…
Browse files Browse the repository at this point in the history
… there is a single card
  • Loading branch information
marcellamaki committed Feb 22, 2022
1 parent ee407d8 commit 83dfbaf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ResourceCard
v-for="(content, idx) in contents"
:key="`resource-${idx}`"
data-test="resource-card"
:data-test="'resource-card-' + idx"
:contentNode="content"
:to="genContentLink(content)"
@openCopiesModal="$emit('openCopiesModal', content.copies)"
Expand All @@ -22,7 +22,7 @@
v-for="(content, idx) in contents"
:key="`resource-${idx}`"
class="card-grid-item"
data-test="content-card"
:data-test="'content-card-' + idx"
:isMobile="windowIsSmall"
:content="content"
:link="genContentLink(content)"
Expand All @@ -37,7 +37,7 @@
:key="content.id"
:content="content"
class="card-grid-item"
data-test="card-list-view"
:data-test="'card-list-view-' + idx"
:link="genContentLink(content)"
:footerIcons="footerIcons"
:createdDate="content.bookmark ? content.bookmark.created : null"
Expand Down Expand Up @@ -85,6 +85,9 @@
return ['card', 'list'].includes(value);
},
},
// Used to define the "type" (number of columns) for <CardGrid />
// Currently only either `1` or `2`
// See props in CardGrid.vue for more details on # of cards per level
gridType: {
type: Number,
required: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@ describe('Library and Channel Browser Main Content', () => {
beforeEach(() => {
wrapper = shallowMount(LibraryAndChannelBrowserMainContent, {
computed: { windowIsSmall: () => false, backRoute: 'test' },
propsData: { contents: [{ node: 1 }], currentCardViewStyle: 'card' },
propsData: {
contents: [{ node: 1 }, { node: 2 }, { node: 3 }],
currentCardViewStyle: 'card',
},
});
});

it('smoke test', () => {
expect(wrapper.exists()).toBe(true);
});
describe('When the user has a medium or large screen', () => {
describe('When `currentCardViewStyle` is a card', () => {
it('displays a `CardGrid`, and within the grid, a `HybridLearningContentCard` for each content node', () => {
expect(wrapper.find('[data-test="non-mobile-card-grid"]').element).toBeTruthy();
expect(wrapper.find('[data-test="content-card"]').element).toBeTruthy();
it.each([{ node: 1 }, { node: 2 }, { node: 3 }], 'displays a card for each node n', n => {
expect(wrapper.find(`[data-test="content-card-"${n}]`).element).toBeTruthy();
});
});
it('does not display a `CardGrid` with a `ResourceCard` for each content node in a single, full-width column', () => {
expect(wrapper.find('[data-test="mobile-card-grid"]').element).toBeFalsy();
Expand All @@ -34,7 +40,9 @@ describe('Library and Channel Browser Main Content', () => {
});
});
it('displays a `HybridLearningContentCardListView` for each content node, in a single, full-width column', () => {
expect(wrapper.find('[data-test="card-list-view"]').element).toBeTruthy();
it.each([{ node: 1 }, { node: 2 }, { node: 3 }], 'displays a card for each node n', n => {
expect(wrapper.find(`[data-test="card-list-view-"${n}]`).element).toBeTruthy();
});
});
it('does not display a `CardGrid` with a `ResourceCard` for each content node in a single, full-width column', () => {
expect(wrapper.find('[data-test="mobile-card-grid"]').element).toBeFalsy();
Expand All @@ -55,7 +63,13 @@ describe('Library and Channel Browser Main Content', () => {
});
it('displays a `CardGrid` with a `ResourceCard` for each content node in a single, full-width column', () => {
expect(wrapper.find('[data-test="mobile-card-grid"]').element).toBeTruthy();
expect(wrapper.find('[data-test="resource-card"]').element).toBeTruthy();
it.each(
[{ node: 1 }, { node: 2 }, { node: 3 }],
'displays a `ResourceCard` for each node n',
n => {
expect(wrapper.find(`[data-test="resource-card-"${n}]`).element).toBeTruthy();
}
);
});
it('does not display a `CardGrid` with `HybridLearningContentCard`s in columns', () => {
expect(wrapper.find('[data-test="non-mobile-card-grid"]').element).toBeFalsy();
Expand Down

0 comments on commit 83dfbaf

Please sign in to comment.