Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit 72f0e04

Browse files
committed
test(communities): add tests for communities layout and refactor
1 parent e91e271 commit 72f0e04

File tree

6 files changed

+44
-17
lines changed

6 files changed

+44
-17
lines changed

components/Navigator/MainEntries.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@ const splitMargin = '8px'
1212
const MainEntries = ({ curRoute: { mainPath } }) => (
1313
<Wrapper>
1414
<Link href="/home/posts" prefetch passHref>
15-
<SiteLink>首页</SiteLink>
15+
<SiteLink testid="header-home-link">首页</SiteLink>
1616
</Link>
1717
<DotDivider space={splitMargin} />
1818
<Link href="/communities" prefetch passHref>
19-
<SiteLink active={mainPath === 'communities'}>社区</SiteLink>
19+
<SiteLink
20+
active={mainPath === 'communities'}
21+
testid="header-communities-link"
22+
>
23+
社区
24+
</SiteLink>
2025
</Link>
2126
<DotDivider space={splitMargin} />
2227
<Popover

components/Navigator/styles/main_entries.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ export const Wrapper = styled.div`
1313
export const DotDivider = styled(DotDividerBase)`
1414
background-color: ${theme('banner.desc')};
1515
`
16-
export const SiteLink = styled.a`
16+
export const SiteLink = styled.a.attrs(props => ({
17+
'data-testid': props.testid,
18+
}))`
1719
color: ${theme('banner.desc')};
1820
background: ${({ active }) =>
1921
active ? theme('banner.numberHoverBg') : 'transparent'};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
describe('communities page layout', () => {
3+
// beforeEach(() => {
4+
before(() => {
5+
cy.visit('/communities')
6+
})
7+
8+
it('basic layout', () => {
9+
cy.id('header').should('be.visible')
10+
11+
cy.id('header-search').should('be.visible')
12+
cy.id('header-search-icon').should('be.visible')
13+
14+
cy.id('sidebar').should('be.visible')
15+
16+
cy.id('communities-banner').should('be.visible')
17+
cy.id('footer').should('be.visible')
18+
})
19+
20+
it('communities link should be highlight', () => {
21+
cy.id('header-communities-link')
22+
.should('not.have.css', 'background', 'transparent')
23+
.and('have.css', 'padding', '5px 3px 3px')
24+
})
25+
})
Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
describe('basic layout', () => {
1+
describe('home page layout', () => {
22
// beforeEach(() => {
33
before(() => {
44
cy.visit('/home/posts')
55
})
66

77
it('basic layout shoud be visible', () => {
88
cy.id('header').should('be.visible')
9+
cy.id('header-search').should('be.visible')
10+
cy.id('header-search-icon').should('be.visible')
11+
912
cy.id('sidebar').should('be.visible')
1013

1114
cy.id('community-banner').should('be.visible')
@@ -14,18 +17,10 @@ describe('basic layout', () => {
1417
cy.id('footer').should('be.visible')
1518
})
1619

17-
it('header content', () => {
18-
cy.id('header-search').should('be.visible')
19-
cy.id('header-search-icon').should('be.visible')
20-
})
21-
22-
it('communities page', () => {
23-
cy.visit('/communities')
24-
cy.id('header-search').should('be.visible')
25-
cy.id('header-search-icon').should('be.visible')
26-
27-
cy.id('communities-banner').should('be.visible')
28-
29-
cy.id('footer').should('be.visible')
20+
it('home link should not be highlight', () => {
21+
cy.id('header-home-link')
22+
// .should('have.css', 'background')
23+
// .should('not.have.css', 'border-bottom')
24+
.and('not.have.css', 'padding', '5px 3px 3px 3px')
3025
})
3126
})

0 commit comments

Comments
 (0)