Skip to content

Commit

Permalink
Refactor Home tests and remove pages from coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
willianjusten committed Nov 7, 2020
1 parent c01fa1c commit 2dbc528
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 38 deletions.
7 changes: 6 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ module.exports = {
testEnvironment: 'jsdom',
testPathIgnorePatterns: ['/node_modules/', '/.next/'],
collectCoverage: true,
collectCoverageFrom: ['src/**/*.ts(x)?', '!src/**/stories.tsx'],
collectCoverageFrom: [
'src/**/*.ts(x)?',
'!src/**/stories.tsx',
'!src/pages/**/*.tsx',
'!src/styles/**/*.ts'
],
setupFilesAfterEnv: ['<rootDir>/.jest/setup.ts'],
modulePaths: ['<rootDir>/src/', '<rootDir>/.jest'],
moduleNameMapper: {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Banner/__snapshots__/test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ exports[`<Banner /> should render correctly 1`] = `
}
@media (max-width:1170px) {
.c0 .sc-bdnylx {
.c0 .sc-bdfBwQ {
right: 0;
}
.c0 .sc-bdnylx::before {
.c0 .sc-bdfBwQ::before {
display: none;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/Form/test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ describe('<Form />', () => {
)

expect(container.parentElement).toMatchInlineSnapshot(`
.c0 .sc-jSFkmK {
.c0 .sc-jSgupP {
margin: 0.8rem 0;
}
.c0 .sc-gKAblj {
.c0 .sc-gKsewC {
margin: 3.2rem auto 1.6rem;
}
Expand Down
78 changes: 45 additions & 33 deletions src/templates/Home/test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,59 @@ import Home from '.'

const props = {
banners: bannerMock,
newGames: [gamesMock[0]],
newGames: gamesMock,
mostPopularHighlight: highlightMock,
mostPopularGames: [gamesMock[0]],
upcommingGames: [gamesMock[0]],
mostPopularGames: gamesMock,
upcommingGames: gamesMock,
upcommingHighlight: highlightMock,
upcommingMoreGames: [gamesMock[0]],
freeGames: [gamesMock[0]],
upcommingMoreGames: gamesMock,
freeGames: gamesMock,
freeHighlight: highlightMock
}

jest.mock('components/Menu', () => {
return {
__esModule: true,
default: function Mock() {
return <div data-testid="Mock Menu"></div>
}
}
})

jest.mock('components/Footer', () => {
return {
__esModule: true,
default: function Mock() {
return <div data-testid="Mock Footer"></div>
}
}
})

jest.mock('components/Showcase', () => {
return {
__esModule: true,
default: function Mock() {
return <div data-testid="Mock Showcase"></div>
}
}
})

jest.mock('components/BannerSlider', () => {
return {
__esModule: true,
default: function Mock() {
return <div data-testid="Mock Banner Slider"></div>
}
}
})

describe('<Home />', () => {
it('should render menu and footer', () => {
renderWithTheme(<Home {...props} />)

// menu
expect(screen.getByLabelText(/open menu/i)).toBeInTheDocument()

// footer
expect(
screen.getByRole('heading', { name: /follow us/i })
).toBeInTheDocument()

// logos (menu/footer)
expect(screen.getAllByRole('img', { name: /won games/i })).toHaveLength(2)

expect(screen.getByRole('heading', { name: /news/i })).toBeInTheDocument()
expect(
screen.getByRole('heading', { name: /most popular/i })
).toBeInTheDocument()
expect(
screen.getByRole('heading', { name: /upcoming/i })
).toBeInTheDocument()
expect(
screen.getByRole('heading', { name: /free games/i })
).toBeInTheDocument()

// banner
expect(screen.getAllByText(/defy death 1/i)).toHaveLength(1)
// card game ( 5 sections com 1 card cada = 5x1 = 5)
expect(screen.getAllByText(/population zero/i)).toHaveLength(5)
// highlight
expect(screen.getAllByText(/read dead is back!/i)).toHaveLength(3)
expect(screen.getByTestId('Mock Menu')).toBeInTheDocument()
expect(screen.getByTestId('Mock Banner Slider')).toBeInTheDocument()
expect(screen.getAllByTestId('Mock Showcase')).toHaveLength(5)
expect(screen.getByTestId('Mock Footer')).toBeInTheDocument()
})
})

0 comments on commit 2dbc528

Please sign in to comment.