Skip to content

Commit

Permalink
add tests for rewards dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
maxaleks committed Nov 1, 2024
1 parent 97639dc commit a2226d5
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 0 deletions.
7 changes: 7 additions & 0 deletions mocks/rewards/referrals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { RewardsUserReferralsResponse } from 'types/api/rewards';

export const base: RewardsUserReferralsResponse = {
code: 'QWERTY',
link: 'https://example.com?ref=QWERTY',
referrals: '15',
};
10 changes: 10 additions & 0 deletions mocks/rewards/rewardsConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { RewardsConfigResponse } from 'types/api/rewards';

export const base: RewardsConfigResponse = {
rewards: {
registration: '100',
registration_with_referral: '200',
daily_claim: '10',
referral_share: '0.1',
},
};
40 changes: 40 additions & 0 deletions ui/pages/RewardsDashboard.pw.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import type { BrowserContext } from '@playwright/test';
import React from 'react';

import * as rewardsBalanceMock from 'mocks/rewards/balance';
import * as dailyRewardMock from 'mocks/rewards/dailyReward';
import * as referralsMock from 'mocks/rewards/referrals';
import * as rewardsConfigMock from 'mocks/rewards/rewardsConfig';
import * as profileMock from 'mocks/user/profile';
import { contextWithAuth } from 'playwright/fixtures/auth';
import { ENVS_MAP } from 'playwright/fixtures/mockEnvs';
import { contextWithRewards } from 'playwright/fixtures/rewards';
import { test, expect } from 'playwright/lib';

import RewardsDashboard from './RewardsDashboard';

const testWithAuth = test.extend<{ context: BrowserContext }>({
context: contextWithAuth,
}).extend<{ context: BrowserContext }>({
context: contextWithRewards,
});

testWithAuth.beforeEach(async({ mockEnvs, mockApiResponse }) => {
await mockEnvs([ ...ENVS_MAP.rewardsService ]);
await mockApiResponse('user_info', profileMock.withEmailAndWallet);
});

testWithAuth('base view +@dark-mode +@mobile', async({ render, mockApiResponse }) => {
await mockApiResponse('rewards_user_balances', rewardsBalanceMock.base);
await mockApiResponse('rewards_user_daily_check', dailyRewardMock.base);
await mockApiResponse('rewards_user_referrals', referralsMock.base);
await mockApiResponse('rewards_config', rewardsConfigMock.base);

const component = await render(<RewardsDashboard/>);
await expect(component).toHaveScreenshot();
});

testWithAuth('with error', async({ render }) => {
const component = await render(<RewardsDashboard/>);
await expect(component).toHaveScreenshot();
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a2226d5

Please sign in to comment.