<?xml version="1.0"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.atlassian.jira</groupId>
        <artifactId>jira-functional-tests</artifactId>
        <version>10.3.2</version>
    </parent>

    <artifactId>jira-sanity-check-tests</artifactId>
    <name>Jira Sanity Checks</name>

    <properties>
        <node.version>v18.20.4</node.version>
        <jira.baseUrl>http://localhost:2990/jira</jira.baseUrl>
        <jira.admin.password>admin</jira.admin.password>
        <jira.version>${project.version}</jira.version>
        <!--
            test files used for tests against Jira Core,
            would be overridden by a profile if jira.servicedesk.version or jira.software.version property is defined,
            can be overridden by -DplaywrightTestFiles=
        -->
        <playwrightTestFiles>commonTests jiraCore</playwrightTestFiles>
        <playwrightEnvCi>false</playwrightEnvCi>
    </properties>

    <profiles>
        <profile>
            <id>run-playwright-integration-tests</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.atlassian.maven.plugins</groupId>
                        <artifactId>jira-maven-plugin</artifactId>
                        <configuration>
                            <productVersion>${jira.version}</productVersion>
                            <productDataVersion>${jira.version}</productDataVersion>
                            <allowGoogleTracking>false</allowGoogleTracking>
                            <awaitFullInitialization>true</awaitFullInitialization>
                            <compressResources>true</compressResources>
                            <enableDevToolbox>false</enableDevToolbox>
                            <enablePde>false</enablePde>
                            <enablePluginViewer>false</enablePluginViewer>
                            <enableQuickReload>false</enableQuickReload>
                            <extractDependencies>false</extractDependencies>
                            <skipAllPrompts>true</skipAllPrompts>
                            <skipManifestValidation>true</skipManifestValidation>
                            <skipRestDocGeneration>true</skipRestDocGeneration>
                            <writePropertiesToFile>true</writePropertiesToFile>
                            <wait>false</wait>
                            <systemPropertyVariables>
                                <jira.websudo.is.disabled>false</jira.websudo.is.disabled>
                                <jira.xml.data.location>${project.build.directory}/dataset</jira.xml.data.location>
                                <atlassian.dev.mode>false</atlassian.dev.mode>
                            </systemPropertyVariables>
                            <pluginArtifacts>
                                <pluginArtifact>
                                    <groupId>com.atlassian.jira.tests</groupId>
                                    <artifactId>jira-testkit-plugin</artifactId>
                                    <version>${testkit.version}</version>
                                </pluginArtifact>
                            </pluginArtifacts>
                            <jvmArgs>-Xmx4g -Xms4g</jvmArgs>
                        </configuration>
                        <executions>
                            <execution>
                                <id>5-run-jira</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <groupId>com.github.eirslett</groupId>
                        <artifactId>frontend-maven-plugin</artifactId>
                        <version>${frontend.maven.plugin.version}</version>
                        <configuration>
                            <npmVersion>${npm.version}</npmVersion>
                            <installDirectory>${nodePath}</installDirectory>
                            <workingDirectory>${nodePath}/..</workingDirectory>
                        </configuration>
                        <executions>
                            <execution>
                                <id>1-install-node-and-yarn</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>install-node-and-yarn</goal>
                                </goals>
                                <configuration>
                                    <nodeVersion>${node.version}</nodeVersion>
                                </configuration>
                            </execution>
                            <execution>
                                <id>2-yarn-install</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>yarn</goal>
                                </goals>
                                <configuration>
                                    <arguments>install</arguments>
                                </configuration>
                            </execution>
                            <execution>
                                <id>3-playwright-install</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>yarn</goal>
                                </goals>
                                <configuration>
                                    <arguments>playwright install</arguments>
                                </configuration>
                            </execution>
                            <execution>
                                <id>4-playwright-install</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>yarn</goal>
                                </goals>
                                <configuration>
                                    <arguments>playwright install-deps</arguments>
                                </configuration>
                            </execution>
                            <execution>
                                <id>9-run-playwright-tests</id>
                                <phase>integration-test</phase>
                                <goals>
                                    <goal>yarn</goal>
                                </goals>
                                <configuration>
                                    <arguments>playwright test ${playwrightTestFiles}</arguments>
                                    <environmentVariables>
                                        <BASE_URL>${jira.baseUrl}</BASE_URL>
                                        <ADMIN_USERNAME>admin</ADMIN_USERNAME>
                                        <ADMIN_PASSWORD>${jira.admin.password}</ADMIN_PASSWORD>
                                        <CI>${playwrightEnvCi}</CI>
                                    </environmentVariables>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>7-import-dataset</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <target>
                                        <exec executable="./import-dataset.sh">
                                            <arg value="${jira.baseUrl}"/>
                                        </exec>
                                        <echo>Waiting for import to be completed</echo>
                                        <waitfor maxwait="3" maxwaitunit="minute" checkevery="500">
                                            <http url="${jira.baseUrl}"/>
                                        </waitfor>
                                        <echo>Jira is up</echo>
                                    </target>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>jira-software-playwright-integration-tests-config</id>
            <activation>
                <property>
                    <name>jira.software.version</name>
                </property>
            </activation>
            <properties>
                <playwrightTestFiles>commonTests jiraSoftware</playwrightTestFiles>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.atlassian.maven.plugins</groupId>
                        <artifactId>jira-maven-plugin</artifactId>
                        <configuration>
                            <applications>
                                <application>
                                    <applicationKey>jira-software</applicationKey>
                                    <version>${jira.software.version}</version>
                                </application>
                            </applications>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>jira-servicedesk-playwright-integration-tests-config</id>
            <activation>
                <property>
                    <name>jira.servicedesk.version</name>
                </property>
            </activation>
            <properties>
                <playwrightTestFiles>commonTests jiraServiceDesk</playwrightTestFiles>
            </properties>

            <build>
                <plugins>
                    <plugin>
                        <groupId>com.atlassian.maven.plugins</groupId>
                        <artifactId>jira-maven-plugin</artifactId>
                        <configuration>
                            <applications>
                                <application>
                                    <applicationKey>jira-servicedesk</applicationKey>
                                    <version>${jira.servicedesk.version}</version>
                                </application>
                            </applications>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>