Skip to content

Commit

Permalink
test(e2e): homepage screenshot tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DenysKarmazynDFINITY committed Aug 16, 2024
1 parent fade821 commit 2fdd323
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 20 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ jobs:
docker-build-e2e:
runs-on: ubuntu-20.04
steps:
- name: Delete unnecessary tools folder to free space
run: rm -rf /opt/hostedtoolcache

- name: Checkout
uses: actions/checkout@v4

Expand Down
4 changes: 1 addition & 3 deletions Dockerfile.e2e
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ RUN DEBIAN_FRONTEND=noninteractive apt update && apt install -y \
netcat \
ca-certificates \
build-essential \
llvm-dev \
clang \
jq \
&& rm -rf /var/lib/apt/lists/*

# Install NodeJS
Expand All @@ -34,6 +31,7 @@ RUN /bin/bash -c "source /home/apprunner/.cargo/env && rustc --version && cargo

# Add wasm32-unknown-unknown target
RUN /bin/bash -c "source /home/apprunner/.cargo/env && rustup target add wasm32-unknown-unknown"

# Install dfx
ENV DFX_PORT=4943
ENV DFX_VERSION=0.20.0
Expand Down
3 changes: 0 additions & 3 deletions docker/deploy
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ dfx start --background --quiet

./docker/wait-port "$DFX_PORT"

dfx canister create internet_identity --specified-id rdmx6-jaaaa-aaaaa-aaadq-cai
dfx canister create pouh_issuer --specified-id qbw6f-caaaa-aaaah-qdcwa-cai

npm run deploy

dfx stop
22 changes: 14 additions & 8 deletions e2e/homepage.spec.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
import {
EXCHANGE_BALANCE_OUTPUT,
LOGIN_BUTTON,
THREE_BACKGROUND_CANVAS,
TOKENS_SKELETONS_INITIALIZED
} from '$lib/constants/test-ids.constant';
import { testWithII } from '@dfinity/internet-identity-playwright';
import { expect, test, type Page } from '@playwright/test';

const testUrl = '/';
const timeout = 120000;

const hideHeroAnimation = async (page: Page): Promise<void> => {
await page
.getByTestId('three-background-canvas')
.getByTestId(THREE_BACKGROUND_CANVAS)
.evaluate((element) => (element.style.display = 'none'));
};

test.describe('logged out user', () => {
test.beforeEach(async ({ page }) => {
await page.goto(testUrl);

await page.getByTestId('login-button').waitFor();
});

test('should display logged out hero and blurred tokens', async ({ page }) => {
test('should display homepage in logged out state', async ({ page }) => {
await page.getByTestId(LOGIN_BUTTON).waitFor();

await hideHeroAnimation(page);

await expect(page).toHaveScreenshot({
Expand All @@ -30,15 +35,16 @@ testWithII.describe('logged in user', () => {
testWithII.beforeEach(async ({ page, iiPage }) => {
const url = 'http://127.0.0.1:4943';
const canisterId = 'rdmx6-jaaaa-aaaaa-aaadq-cai';
await iiPage.waitReady({ url, canisterId, timeout });
await iiPage.waitReady({ url, canisterId });

await page.goto(testUrl);

await iiPage.signInWithNewIdentity();
});

testWithII('should display logged in hero and tokens', async ({ page }) => {
await page.getByTestId('tokens-skeletons-initialized').waitFor({ timeout });
testWithII('should display homepage in logged in state', async ({ page }) => {
await page.getByTestId(TOKENS_SKELETONS_INITIALIZED).waitFor();
await page.getByTestId(EXCHANGE_BALANCE_OUTPUT).waitFor();

await hideHeroAnimation(page);

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
1 change: 1 addition & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default defineConfig({
port: DEV ? 5173 : 4173
},
testDir: 'e2e',
timeout: 120000,
testMatch: ['**/*.e2e.ts', '**/*.spec.ts'],
use: {
testIdAttribute: 'data-tid',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { formatUSD } from '$lib/utils/format.utils';
import { exchangeInitialized } from '$lib/derived/exchange.derived';
import { combinedDerivedEnabledNetworkTokensUi } from '$lib/derived/network-tokens.derived';
import { EXCHANGE_BALANCE_OUTPUT } from '$lib/constants/test-ids.constant';
let totalUsd: number;
$: totalUsd = $combinedDerivedEnabledNetworkTokensUi.reduce(
Expand All @@ -13,7 +14,7 @@
<span class="text-off-white block">
<output
class={`break-all text-5xl font-bold ${totalUsd === 0 ? 'opacity-50' : 'opacity-100'} inline-block mt-8`}
data-tid="exchange-balance-output"
data-tid={EXCHANGE_BALANCE_OUTPUT}
>
{#if $exchangeInitialized}
{formatUSD(totalUsd)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
import { erc20UserTokensNotInitialized } from '$eth/derived/erc20.derived';
import { fade } from 'svelte/transition';
import SkeletonCards from '$lib/components/ui/SkeletonCards.svelte';
import { TOKENS_SKELETONS_INITIALIZED } from '$lib/constants/test-ids.constant';
</script>

{#if $erc20UserTokensNotInitialized}
<SkeletonCards rows={5} />
{:else}
<div in:fade data-tid="tokens-skeletons-initialized">
<div in:fade data-tid={TOKENS_SKELETONS_INITIALIZED}>
<slot />
</div>
{/if}
3 changes: 2 additions & 1 deletion src/frontend/src/lib/components/ui/ThreeBackground.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
WebGLRenderer
} from 'three';
import { isNullish } from '@dfinity/utils';
import { THREE_BACKGROUND_CANVAS } from '$lib/constants/test-ids.constant';
let container: HTMLDivElement | undefined | null;
Expand Down Expand Up @@ -114,7 +115,7 @@ void main(){
renderer = new WebGLRenderer();
renderer.domElement.style.width = '100%';
renderer.domElement.style.height = '100%';
renderer.domElement.setAttribute('data-tid', 'three-background-canvas');
renderer.domElement.setAttribute('data-tid', THREE_BACKGROUND_CANVAS);
container.appendChild(renderer.domElement);
material = new ShaderMaterial({
Expand Down
4 changes: 4 additions & 0 deletions src/frontend/src/lib/constants/test-ids.constant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const LOGIN_BUTTON = 'login-button';
export const TOKENS_SKELETONS_INITIALIZED = 'tokens-skeletons-initialized';
export const EXCHANGE_BALANCE_OUTPUT = 'exchange-balance-output';
export const THREE_BACKGROUND_CANVAS = 'three-background-canvas';

0 comments on commit 2fdd323

Please sign in to comment.